Prepared token rows

Use prepared token rows when you have decided which tokens carry loss. Each row has a loss mask that selects the tokens to train on. See Datasets for other dataset formats and registration.

Use prepared token rows

Prepared rows supply token IDs and loss masks directly. Use them for SFT training and validation.

Prepared rows are for the training and validation datasets of a supervised run. An evaluation, a reinforcement run and a smoke check read prompts, which prepared rows do not hold. An evaluation of a model trained on prepared rows names its dataset, since it cannot default to the training dataset. Such a model has no training instructions. An endpoint serves it without instructions. To use it as a model: grader, specify graderInstructions.

Prepare row files

The rows are in one or more Parquet files. Each row has an input_ids and a loss_mask list column of the same length. The loss_mask[i] field is 1 where token i is trained on and 0 elsewhere. The first token is never marked, because no token predicts it, and every row marks at least one token. Optimize ignores other columns.

Prepare the rows with the base model’s own tokenizer, at the commit the run trains, and under the chat template the run renders under.

The descriptor

A prepared version is a ZIP file containing prepared.json alongside the Parquet files it lists:

{"tokenizer":{"repository":"google/gemma-4-E4B-it",
              "revision":"ee0ef6023621cff504d758262d4e04895a5af4a2"},
 "tokenizerSha256":"bca34862f49c6a63155300a313b0d3f901ad1c16d619d19c2677ba963449085d",
 "chatTemplateSha256":"0a2c8073c878ab1da004bee933a998606537bbb62016310352c7285c3f01c5b5",
 "files":[{"path":"train.parquet",
           "sha256":"5f0c9e1d2a7b4c3e8f6a1d0b9c8e7f6a5b4c3d2e1f0a9b8c7d6e5f4a3b2c1d0e",
           "rows":2000,"tokens":3412880,"supervisedTokens":402117,"longestRow":8190}]}

The descriptor contains the following fields:

  • Set tokenizer to name the model repository and the full commit the tokenizer was loaded from.

  • Set tokenizerSha256 to the SHA-256 of the tokenizer’s serialized form, tokenizer.backend_tokenizer.to_str() in Hugging Face Transformers.

  • Set chatTemplateSha256 to the SHA-256 of the chat template the rows were rendered under. A run renders under the template the repository ships at that commit, or under the corrected template where Optimize corrects that commit.

  • Use files to list every Parquet file in training order, with the SHA-256 of its bytes, its row count, its token count, how many tokens its loss masks mark, and the token count of its longest row.

The describe_prepared.py script reads every row and writes the descriptor. It needs transformers and pyarrow, and it refuses a row that a run would refuse. With --zip, it writes the zip to register. Download the descriptor script to prepare a dataset for registration.

python describe_prepared.py --model google/gemma-4-E4B-it --zip train.zip train.parquet
akka optimize registry datasets register gemma/train -f train.zip

The --revision option names a branch, tag or commit of the model. The descriptor records it as a commit.

Optimize trains these Gemma 4 commits under a corrected chat template:

Repository Commit Template

google/gemma-4-E2B-it

3e22461f65e89153144f8adb70e3b8c2cc9845a7

gemma-4-E2B-E4B-it.jinja

google/gemma-4-E4B-it

ee0ef6023621cff504d758262d4e04895a5af4a2

gemma-4-E2B-E4B-it.jinja

google/gemma-4-12B-it

707f0a3b8a3c7ad586ed01e27eafbad8a27dd0f7

gemma-4-12B-it.jinja

For one of these commits, render the rows under the corrected template, for example with tokenizer.apply_chat_template(messages, chat_template=Path("gemma-4-E2B-E4B-it.jinja").read_text(encoding="utf-8")) in Hugging Face Transformers. Then name the template’s file with --chat-template and the commit with --revision, so the descriptor records the template’s digest at that commit:

python describe_prepared.py --model google/gemma-4-E4B-it --revision ee0ef6023621cff504d758262d4e04895a5af4a2 --chat-template gemma-4-E2B-E4B-it.jinja --zip train.zip train.parquet

Check prepared rows

Use the same tokenizer revision and chat template as your selected base model. Keep every row within maxSeqLength and use prepared rows for both training and validation. Leave loss, truncation and smoke settings out.

If the tokenizer, template or row digests do not match, regenerate the descriptor from the files and model revision you intend to train.

To read the text a run trains on in each row, index the rows with akka optimize training datasets index gemma/train --wait, then run akka optimize training datasets rows gemma/train --trained-only. See Read a dataset’s rows.