This skill assumes
finetuning-method-selection
already routed here — the next step is preparing
data, not choosing a method. What follows: format
selection by target method, the template/packing
mechanics behind the most common silent training
failures, rules for mixing in synthetic data
without collapse, and the dataset card that closes
out Phase 2 before a run starts.
Input: raw examples (demonstrations, preference
judgments, or task prompts) plus a routing decision
from
finetuning-method-selection
.
Output format: a formatted, packed, validated
JSONL dataset plus a completed dataset card — the
Phase 2 artifact
checks before launching
training.
-
~1,000+ rows is the recommended floor for SFT,
not a target. Below it, a handful of low-quality
or duplicate examples can dominate the gradient;
above it, quality over quantity — a smaller
verified, deduplicated set beats a larger noisy one.
-
The ChatML shape, for orientation; the other four
formats plus a ShareGPT conversion note live in
references/formats-and-templates.md
:
json
{"messages": [
{"role": "user", "content": "..."},
{"role": "assistant", "content": "..."}
]}
-
Train on assistant responses only. Mask the
loss (
in the labels tensor) over system/user
turns and the template's own role markers — only
assistant-turn content tokens contribute to loss.
-
Template/tokenizer mismatches are a top silent
failure mode. A model trained against one chat
template but served or evaluated with a different
one degrades without erroring. Verify the same
template string used in training is applied at
inference and eval time.
-
Keep the dataset in shape and let
the trainer template and mask it
(
in current TRL) —
pre-rendering to a flat text field destroys the
turn boundaries masking needs. Full code sketch:
references/formats-and-templates.md
. Sanity-check
before training — decode only unmasked positions;
expect only assistant text:
python
keep = batch["labels"][0] != -100
print(tokenizer.decode(batch["input_ids"][0][keep]))
-
Packing changes batch semantics. A packed
sequence can contain several original examples, so
"steps per epoch" and any LR schedule keyed to
example count shift once packing is on — recompute
schedule milestones against packed-sequence count.
-
MANDATORY: decode and manually inspect 5–10
packed sequences before scaling to a full run.
Confirm example boundaries land where expected,
template markers are intact per sub-example, and
the loss mask is still assistant-only within each
packed sequence. Not optional — packing bugs are
silent (the loss curve looks normal) and only
surface in eval quality, hours later:
python
for seq in packed_dataset.select(range(10)):
print(tokenizer.decode(seq["input_ids"]))
Every dataset that reaches training gets a card —
the required Phase 2 artifact
checks
before launching. The card is not free-form
documentation; it MUST carry these fields:
A dataset missing any of these six fields isn't
ready for
— the card is a gate, not a
summary written after the fact.
Related skills:
finetuning-method-selection
routes
here;
,
, and
consume the datasets this
skill produces;
is the
provenance source for graded-trajectory datasets;
grades the resulting checkpoint.