Commit 74dfb9a
refactor(train): config-file-first CLI generated from a typed pydantic schema
Make scripts/train.py config-file-first without changing what any run does and
without touching the model layer.
- New src/speculators/train/config.py is the single source of truth: ~75 tunables
as typed fields on cohesive pydantic-settings groups (verifier/draft/data/
generation/loss/optimizer/scheduler/trainer/logging + per-algo dflash/dspark/
peagle/mtp). The argparse CLI is GENERATED from these fields, so adding an
argument is one typed field -- train.py has no per-flag add_argument.
- --config run.yaml supplies any argument; precedence is CLI > YAML > coded
defaults; --config is optional (no file == the old pure-CLI behaviour).
- --dump-config prints the fully-resolved grouped YAML (a valid --config file);
the resolved run.yaml is also saved next to each checkpoint for reproducibility.
It runs the draft-init contract first, so a scaffold is never emitted for a
config that would fail to load.
- Provenance = the argparse.SUPPRESS'd namespace (not model_fields_set, which the
nested partial-update machinery pollutes). A YAML leaf counts as provided only
under its owning group block; a misplaced key is reported as unrecognised and
kept out of provenance so it can't mis-fire the draft-init conflict check.
- Every bad input is a clean argparse error (exit code 2, no traceback): schema
ValidationError and a broken --config file (missing/unreadable/malformed/
non-mapping) alike; a missing required field names the flag to set.
Phase 1: the resolved config is flattened back to the vars(args)-shaped dict the
five SpeculatorModel classes consume via **kwargs, so the model layer and Trainer
are untouched; only main()'s TrainerConfig reads the typed groups. Pushing typed
configs into the model layer is deferred to a follow-up PR.
Rebased onto current main. Absorbs the flags added since the branch point and
ports them into the schema so behaviour is unchanged:
- #736 D-PACE: --per-position-loss-weight, --dpace-alpha as typed DFlash fields,
with the "dpace requires ce loss / alpha in (0,1]" check as a cross-group
model_validator.
- #651 scheduler: --scheduler-warmup-ratio, and --scheduler-type as a Literal
(linear/cosine/none), threaded through the typed TrainerConfig build.
- #749 default sliding-window attention: --sliding-window-indices renamed to
--full-attention-indices (inverted semantics), matching upstream.
The decoder-shaping flag set (used by the draft-init conflict check) is derived
from the schema via a field tag, so it is not a second place to edit when a
shaping knob is added.
Equivalence is guarded by tests/unit/train/test_golden_cli_equivalence.py: the
refactored flat working-dict is asserted byte-value-identical to the pre-refactor
parser across a 17-invocation matrix (expected values in one golden_flat_dict.json
-- a _baseline all-defaults dict + per-invocation deltas), and the generated CLI's
option-string set is frozen against the pre-refactor parser (golden_cli_flags.json)
so no flag can be silently renamed or dropped.
Removes src/speculators/utils/argparse_utils.py and its test: train.py was the
only caller of explicitly_provided_dests, which the SUPPRESS'd-namespace
provenance replaces.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Rahul-Tuli <rtuli@redhat.com>1 parent 6030a44 commit 74dfb9a
9 files changed
Lines changed: 2104 additions & 651 deletions
File tree
- scripts
- src/speculators
- train
- utils
- tests/unit
- train
- utils
Large diffs are not rendered by default.
Large diffs are not rendered by default.
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
0 commit comments