Repository navigation
Conversation
|
Hi @jacklanda! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
52d7bc8 to
bfa7f12
Compare
Add a reusable candidate-distribution decision recipe and a GS1 specialization. Use TorchTitan Qwen3.5 as the GS1 backbone and include a seeded distribution-v4.5 sampler, tests, and usage notes.
bfa7f12 to
57abfff
Compare
|
@claude review. In particular,
|
|
Claude finished @tianyu-l's task in 3m 19s —— View job Request changes: this is the Jev recipe again plus a soft-target loss, with no training results. See my review on this PR, which also answers the three questions. |
There was a problem hiding this comment.
Verdict: Request changes -- the only new idea is a soft-target loss, and it comes with no training evidence. torchtitan_recipes/README.md limits public recipes to configurations that have actually been trained, and this PR states "No GPU training, convergence, or performance results are claimed."
What this PR does. It adds a second decision recipe next to the existing Jev recipe (#5569, qwen3.py). It reads GS1 request/targets records that carry a probability distribution over candidates instead of one gold answer, and keeps 3,000 of them. On each pass, the processor samples one answer letter from that distribution. The loss restricts the softmax to the first n letters and minimizes NLL + brier_weight * Brier. The backbone is Qwen3.5-0.8B, with data parallelism only.
Example.
GS1 target: {job_a: 0.2, job_b: 0.3, job_c: 0.5}
Jev (main): one gold letter, e.g. " C" -> full-vocab CE at "Answer:"
This PR: options reshuffled each pass; " A"/" B"/" C" sampled with p=(.2,.3,.5)
labels[-2] = -3 (candidate count), labels[-1] = sampled letter
loss = -log p_y + w * (sum p^2 + 1 - 2 p_y) over 3 letters, divided by global_count/2
Answers to @tianyu-l
Difference from Jev. These are the only changes to the method:
- Soft targets: it samples labels from a distribution instead of using one hard label.
- Candidate-restricted softmax plus a Brier term, instead of full-vocab CE.
- It reshuffles options on every pass instead of once, at data-prep time.
Everything else re-implements qwen3.py: the processor, the gather-at-answer loss wrapper (DecisionLoss ~ AnswerTokenLoss), and the Trainer.Config block. It also gives up things Jev has:
- TP/CP support
- an eval script (the prompt format is now
State:plus an extra\nreadout token, soevaluate.pycan't score it) - a calibration/eval split
- a public dataset (GS1 "distribution-v4.5" is not linked)
- results
Worth landing as another example? Not in this form. Today it is a parallel copy of the Jev recipe with one loss change and no numbers. The smallest version that carries the new idea is about 30 lines in the existing recipe:
DecisionLetterProcessorsamples the answer letter fromtarget_probswhen they are present (the sampled CE is an unbiased estimate of soft CE, which is the same argument this PR makes).- A prep path for GS1-format data.
The Brier term and the restricted softmax (which is what forces the negative-label marker) should only land if a run shows they improve calibration over that baseline. Folder organization is moot until then.
Must fix
- The PR description has an empty human-written summary and no motivation. It doesn't say what GS1 is or link the dataset, and the data can't be reproduced without it.
- There are no training, convergence, or eval results (see the verdict). The README addition presents this as a working recipe.
base.py:229--DecisionModelis an ABC with one subclass that duplicatesqwen3.py. Extend the existing recipe instead.base.py:116-- the candidate count is stored as a negative label. It is counted as a loss token (hence the/ 2at line 170) and adds a marker search to the loss.prepare_gs1_data.py:78-- rows aren't filtered by length, so one over-length state crashes training partway through the run.test_gs1_decision.py:128-- this test checks no behavior. Delete it.
Should consider
base.py:147-- the loss builds a host-to-device tensor on every call, which is a CUDA-graph hazard (unverified).base.py:168-- the loggeddecision_brier/meanis the one-hot Brier. It is higher than the soft-target Brier by1 - sum(t^2), so it can't be compared to Jev's Brier column.base.py:255-283-- tokenizer files are loaded while the config is being built. If./assets/hf/Qwen3.5-*is missing,gs1_decision()fails before training starts.qwen3.pydoesn't do this.prepare_gs1_data.py:97-- 3,000 samples is a magic number. Say why.
Not verified: GPU runs. I also didn't check whether the GS1 score target IDs really are "0".."n-1".
Signed-off-by: Michael Yang Liu <yonyonlau@gmail.com>
Signed-off-by: Michael Yang Liu <yonyonlau@gmail.com>
Signed-off-by: Michael Yang Liu <yonyonlau@gmail.com>
Signed-off-by: Michael Yang Liu <yonyonlau@gmail.com>
|
@tianyu-l Implemented the structural fix in |
|
@claude review |
There was a problem hiding this comment.
Verdict: Request changes -- there are still no training results, and the "structural fix" left the old class in the file as a string literal. base.py still has a single consumer, and the recipe's claim of a native GS1 head doesn't match the code.
What this PR does. It adds a second decision recipe next to Jev (qwen3.py). Input is GS1 request/targets records that hold a probability distribution over candidates. The recipe flattens them to one row per question and keeps 3,000. On each pass it samples one answer letter from the distribution. Training is Qwen3.5-0.8B with data parallelism only, on a candidate-restricted NLL + brier_weight * Brier loss. The candidate count travels in the labels as a negative marker.
Example.
GS1 target: {a: 0.75, b: 0.25} -> options shuffled, e.g. "A) B-text B) A-text", probs (.25, .75)
input_ids: ...prompt..."Answer:" "\n"
labels: ...IGNORE... -2 " B" (sampled with p=.75)
loss: softmax over [" A"," B"] only; -log p_B + w * (p_A^2 + p_B^2 + 1 - 2 p_B)
divided by global_loss_token_counts / 2 (marker + answer counted as 2 tokens)
Must fix
- Evidence. The PR still has no training, convergence, or eval results.
torchtitan_recipes/README.mdlimits public recipes to configurations that have actually been trained. The Brier term, the restricted softmax, and the label-marker transport each need a run showing they beat the ~30-line alternative from the last review (sample the letter fromtarget_probsinside the existingDecisionLetterProcessor). I still recommend that alternative. torchtitan_recipes/decision/base.py:316-426-- the oldDecisionModelwas kept as a commented-out string literal plus a no-op stub. Delete it.torchtitan_recipes/decision/base.py:234-- @tianyu-l's single-user question is still unresolved. The ABC became a function, but it still has one caller. Foldbase.pyintogs1.py.torchtitan_recipes/decision/gs1.py:23-- the code is a plain Qwen3.5 model with an LM-head letter readout, but the README and description claim a GS1 cross-attention decision head. Either the claim is wrong, or HF loading drops the head (unverified). Show HF numerics parity.torchtitan_recipes/decision/README.md:75and the PR description -- both still describeDecisionModel/GS1DecisionModel, which no longer exist. The "Summary" also doesn't link thedistribution-v4.5dataset, so the data can't be reproduced.
Should consider
torchtitan_recipes/decision/base.py:261-- the tokenizer is still loaded while the config is being built (open from the last review), and it duplicates the processor's own letter-ID lookup.torchtitan_recipes/decision/base.py:112/:174-- the negative count marker and/ 2are unchanged. The author's reply explains them but doesn't remove the side effects:loss_token_countsis 2x the real count, and labels contain out-of-vocab values. That's acceptable only if a run justifies the restricted softmax (item 1).
Questions
- Is
bigai/GS1-0.8Ba stock Qwen3.5-0.8B architecture? If so, what does "GS1 model family" add here beyond the dataset format?
Not verified: GPU runs, and HF checkpoint loading for bigai/GS1-0.8B.
Signed-off-by: Michael Yang Liu <yonyonlau@gmail.com>
|
@claude review again |
Signed-off-by: Michael Yang Liu <yonyonlau@gmail.com>
|
How's it fundamentally different from existing Jev one? They should sit in the same folder in torchtitan_recipes/, sharing building blocks if they have any. |
Place candidate-distribution training alongside Jev and share the answer-token loss wrapper. Document the separate data preparation and evaluation entry points. Signed-off-by: Michael Yang Liu <yonyonlau@gmail.com>
|
@tianyu-l Both recipes score answer letters at one position. Jev uses a gold answer letter and full-vocabulary cross-entropy. The Qwen3.5 recipe samples an answer from the GS1-format soft targets and computes NLL plus weighted Brier over the valid options. In cdad7cd, both recipes now live under Thank you so much! |
Stream reservoir sampling with enumerate, render shuffled options directly, and consolidate overlapping test setup. Signed-off-by: Michael Yang Liu <yonyonlau@gmail.com>
|
@claude review again In particular, check if the folder and file structure makes sense. We should share what could be shared, and make what couldn't be shared in consistent format, via inheritance / composition / etc. |
|
Claude finished @tianyu-l's task in 3m 6s —— View job Request changes: the two recipes still share only |
There was a problem hiding this comment.
Verdict: Request changes -- both recipes now live in decision/, but they still run two parallel pipelines. Only AnswerTokenLoss is shared. The prompt format, data schema, prep script, processor, label format, and Trainer.Config are all duplicated or diverge for no stated reason, and evaluate.py still only works for Jev.
What changed since the last review. The recipe moved from experiments/ back into torchtitan_recipes/decision/ and uses Qwen3.5-0.8B-Base assets, not GS1. AnswerTokenLoss moved into loss.py, which both recipes import. The negative count marker and the / 2 were replaced by a single class-ID label. The README adds a 10-step run with loss going 1.94 -> 1.50.
Example: what is shared today, per stage.
stage Jev (qwen3.py) distribution.py
prep prepare_data.py -> {prompt,gold} prepare_distribution_data.py -> {options,target_probs}
render at prep, "Context:", "yes/no" in processor, "State:", "noul"
readout last token of "Answer:" extra "\n" after "Answer:"
label token(" C") (n-2)*26 + slot
loss_fn CrossEntropyLoss CandidateDistributionLoss
wrapper AnswerTokenLoss AnswerTokenLoss <- only shared piece
config Trainer.Config (50 lines) same 50 lines, 6 values differ
eval evaluate.py none (no calib/eval split)
Resolved
- The negative-count marker, the
/ 2, and the inflatedloss_token_countsare gone: there is one label per question now. - The tokenizer is no longer read while the config is built.
- The checkpoint is no longer loaded through the wrong adapter: the recipe now uses Qwen3.5 assets.
Must fix
- Structure (@tianyu-l's request). Only the loss pipeline (
loss_fn) and the model config need to differ between the recipes, and both can be selected by config type. Everything else should be shared. Target layout:Jev numerics stay bit-identical as long asdecision/ prepare_data.py bev and gs1 readers -> one row schema {state, type, instructions, keys, prompt, target_probs} (one-hot for BEV); shared render/filters/write; train/calib/eval for both <recipe>.py one processor: label = token(" X") sampled from target_probs (one-hot -> identical to today's Jev labels) AnswerTokenLoss, _decision_config(...) qwen3_1_7b_decision(), qwen3_5_0_8b_distribution() evaluate.py scores both; Brier against target_probs (identical for one-hot) tests/.../test_decision.pyrenderand the prep-time shuffle are unchanged. Inline:distribution.py:94-- second prompt rendererdistribution.py:100-- extra"\n"readout tokendistribution.py:107-- class-ID labelsdistribution.py:215-- copiedTrainer.Configprepare_distribution_data.py:39-- second prep script with no calib/eval splitREADME.md:78-- file names that describe different things
- Evidence (still open). The new run is 10 steps on one GPU. It shows only that training runs, not that the new objective helps, and the README says the "comparisons with full-vocabulary CE remain to be measured". Until that comparison exists, the restricted softmax and Brier term are the one thing that blocks sharing the label format (see
distribution.py:107). Land the shared version with Jev's CE on the sampled letter, and addCandidateDistributionLossas a differentloss_fnconfig once a held-out run shows it improves calibration. - PR description. "Put distribution preparation ... under
torchtitan/experiments/decision_distribution/" and "Use ... the Qwen3.5 state-dict adapter" with "no compatible evaluation entry point" describe an older layout. Update the description to match HEAD, and leave the human-written summary to the author.
Should consider
distribution.py:22-29--CandidateDistributionLoss.Confighas two ways to set the same thing (candidate_token_idsortokenizer_path), and it loads its own tokenizer even though the trainer already builds one. Keep just one way.distribution.py:103vsqwen3.py:73-- an over-length row is silently dropped here but raises in Jev. Pick one behavior for both.
Not verified: GPU runs, and whether Qwen3.5 supports TP/CP with this recipe.
Use one letter-slot renderer, processor and trainer config for Jev and GS1-format targets. Compare candidate NLL plus Brier with full-vocabulary CE on separate calibration and test splits. Signed-off-by: Michael Yang Liu <yonyonlau@gmail.com>
|
@claude review again |
There was a problem hiding this comment.
Verdict: Request changes -- the structure now matches what @tianyu-l asked for. What still blocks is the candidate-restricted NLL+Brier objective: it adds a class-ID label encoding and two coupled booleans, and the only evidence for it is a 30-step run on a non-default config with no measurable effect.
What changed since the last review (525a98d). distribution.py, prepare_distribution_data.py, and loss.py are gone. The two recipes now share:
- one processor (
DecisionLetterProcessor) - one prompt renderer (
render_options) - one
_decision_config - one
prepare_data.py, which writes train/calib/eval for both sources - one
evaluate.py, which scores soft targets (one-hot for BEV)
The Jev path looks numerically unchanged: same prompt, same label, same warmup, microbatch, and prefetch values, and the Brier/NLL formulas reduce to the old ones for one-hot targets.
Example (GS1 row at HEAD).
prep: {a: .75, b: .25} -> shuffled once, rendered "Context: ... Question (choice) ... Answer:", target_probs (.25, .75)
CE path (full_vocab_ce=True): label = token(" B") sampled with p=.75 <- same format as Jev
default (candidate_labels=True): label = (2-2)*26 + 1 = 1 <- not a token ID
CandidateDistributionLoss decodes count/slot from it
Resolved
- Folder and file structure: one prep script, one recipe module, one evaluator, one test file.
- Second prompt renderer and extra
"\n"readout token: removed. GS1 now uses Jev'sAnswer:readout. - Copied
Trainer.Config: replaced by_decision_config. - No calib/eval split, and
evaluate.pyscoring only Jev: both fixed. - Over-length rows: now raise for both recipes.
- Two ways to set the loss tokenizer: now one.
Must fix
- PR description is stale again. It says the Jev files are "unchanged" and that the code lives under
torchtitan/experiments/decision_distribution/. Both are false at HEAD. It also has no human-written summary of the motivation, and it doesn't link thedistribution-v4.5data. README.md:106-- Evidence. The runs don't use the shipped config, the effect is within noise, there is no base row, and the reported sampling procedure isn't what the code does (inline).qwen3.py:148-- Coupled booleans.candidate_labelsandfull_vocab_ceselect the implementation by flag instead of by config type, and a mismatch trains on wrong labels with no error. Unless item 2 shows a real gain, drop the candidate objective and use CE for both recipes (about -90 lines) (inline).
Should consider
prepare_data.py:186-- the sampling and shuffle RNGs share one seed and stream (inline).qwen3.py:140-- the processor repeats validation that prep already does (inline).qwen3.py:7-- the module docstring still says "Qwen3-1.7B-Base" only, but the module now hostsqwen3_5_distribution. Theprepare_data.pydocstring and usage line also describe only BEV.prepare_data.py:34--GS1_MAX_STATE_CHARS = 12_000vs BEV's 4000 has no stated reason.flatten_record'srng: ... | None = Noneexists only so the test can omit it.qwen3.py:298--tokenizer_path=assetsduplicateshf_assets_path. If a user overrides one, the loss resolves letter IDs from a different tokenizer. This goes away with item 3.
Not verified: GPU runs, behavior under accelerator graphs, and HF loading of the exported Qwen3.5 checkpoint in evaluate.py's prefix remap.
Signed-off-by: Michael Yang Liu <yonyonlau@gmail.com>
Signed-off-by: Michael Yang Liu <yonyonlau@gmail.com>
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Thanks for the feedback, @tianyu-l. Could you take another look at |
|
@claude review again |
There was a problem hiding this comment.
Verdict: Request changes -- the code layout is now fine, but the new results show the shipped Qwen3.5 recipe makes the base model worse on every metric. The temperature fit is also clipped at the top of its grid, so the CE vs candidate comparison isn't a clean measurement yet.
What changed since the last review (f7490a1, 54c6ffe). The two coupled booleans are gone:
- The processor is now selected by loss config type (
CandidateLetterProcessoriffCandidateDistributionLoss.Config). - Candidate labels are encoded as
-101 - ((n-2)*26 + slot), a range belowIGNORE_INDEXand disjoint from vocab IDs, so a mismatch now fails loudly. - The RNG streams are seeded per split, sampled states are checked for overlap across splits, GS1 uses Jev's 4,000-char limit, and the README reports 600-step, two-seed runs with a base row.
The Jev path still looks numerically unchanged: same prompt, same label token, same warmup, microbatch size, and prefetch, and the Brier/NLL formulas reduce to the old ones for one-hot targets.
Example (README table at HEAD).
exp. acc Brier ECE
Qwen3.5-0.8B-Base 0.4315 0.6455 0.0555
CE, seeds 42/43 0.33/0.34 0.692/0.691
Cand NLL+Brier 42/43 0.35/0.38 0.675/0.665
-> every fine-tuned run is worse than not training; fitted T > grid max (~20.1) for all four
Resolved
- Coupled
candidate_labels/full_vocab_cebooleans: replaced by selection on config type, and a mismatch now raises. - Evidence not from the shipped config: the runs now use the default 600 steps, 32K-token microbatches, and CUDA graphs, with two seeds and a base row.
- Shared RNG stream, undocumented 12,000-char limit, and states not checked as disjoint: all fixed.
- PR description is current and has a human-written summary.
Must fix
torchtitan_recipes/decision/README.md:111-122-- fine-tuning regresses below the base checkpoint, and the temperature fit saturates atevaluate.py:155's upper edge. The likely cause is many epochs over 3,000 questions (unverified). Widen the grid, retune the data size or steps until fine-tuning beats the base, then re-run the comparison (inline).- Data still not linked. The README and description reference "distribution-v4.5" but don't say where to get it, so the table can't be reproduced. Add the link, or the HF dataset id, in
README.md. torchtitan_recipes/decision/qwen3.py:144-145-- theanswer/goldfallbacks (here and inevaluate.py:57-59) only serve files prepared before this PR. Delete them (inline).
Should consider
torchtitan_recipes/decision/qwen3.py:110-114--AnswerTokenLossnow doesisinstanceon one specificloss_fnto run a check that CE'sgatherand TP CE already enforce (inline).torchtitan_recipes/decision/qwen3.py:385-- prefetch depth is now tied tobatch_contexts, andwarmup_steps=0still has no reason (inline).qwen3.py:876-879-- still open:CandidateDistributionLoss.Config.tokenizer_path=assetsduplicateshf_assets_pathand loads a second tokenizer. Overriding one but not the other resolves letter IDs from the wrong tokenizer. The test has to monkeypatchHuggingFaceTokenizerbecause of it.- Still open: the module docstrings (
qwen3.py:7,prepare_data.py:7-21) describe only Qwen3-1.7B/BEV, andflatten_record(rng=None)exists only so the test can omit it.
Questions
- Given that both objectives currently do worse than no training, do the maintainers want the ~150-line candidate objective (processor subclass, label encoding, loss) at all? Or should the recipe land with CE only, adding the candidate objective once it beats both CE and the base at a non-degrading setting?
Not verified: GPU runs, the epoch count per run (depends on average GS1 prompt length), and HF loading of the remapped model.language_model.* export in evaluate.py.
Fit calibration without a fixed temperature grid, use one prepared row schema, and reuse the trainer tokenizer for candidate scoring. Validate the shorter recipe against the base checkpoint and full-vocabulary CE on public BEV data.
|
Thanks for the review, @tianyu-l. In Could you review the update and approve the Lint, CPU Unit Test, and GPU Unit Tests workflows when you have a chance? Thanks. Results and reproduction steps · CI runs |
Summary (human-written)
I wanted the new Qwen3.5 recipe for GS1-format soft targets to fit into the existing Jev workflow, so both recipes now share the same data preparation, training setup, and evaluator. I checked that Jev still produces the same prompts and supervises the same answer letters. I also reviewed the 600-step runs for both training objectives and compared their results on the held-out set.
Why
A GS1-format decision question can carry a soft target such as
[0.2, 0.8]. The shared letter-slot pipeline now trains on these probabilities alongside the one-hot targets used for Jev.What changed
Validation
Both objectives used the same Qwen3.5-0.8B-Base checkpoint, dataset, step count, and A800 GPU type. Seeds 42 and 43 apply to both training and data loading. The public BEV benchmark uses 1,500 test questions and separate calibration states. The README links the dataset and records the revisions and commands.
Both objectives improved accuracy, Brier, and ECE over base on public BEV. Each objective had the lower Brier for one seed.
For the local distribution-v4.5 check, the former 3,000-question slice contained only yes/no questions. We reran with 60,000 questions sampled across the full training JSONL and 1,000 questions each for calibration and final testing. The splits used disjoint states.
Both objectives improved expected accuracy and Brier over base on the soft targets. Full-vocabulary CE had lower Brier in both seeds. ECE varied by seed.
All 22 decision CPU tests passed. The public and local GPU runs completed training, exported their HF-format checkpoints, and reloaded them for evaluation. On the same prepared prompts and logits, the refactor produced bitwise-identical labels, losses, and gradients for both objectives. All pre-commit hooks except Pyrefly passed locally. Pyrefly reported the same six dependency API errors on the previous PR head and this patch.