Repository navigation
Take long options by their full name only (no argparse abbreviations) - #904
Merged
Merged
Conversation
argparse's default allow_abbrev=True resolved any unique prefix of a long option to that option, so a misspelled name silently set another one: `yeto launch --rollout-num-gpus 8` set --rollout-num-gpus-per-engine. yeto.exact_argparse.ExactArgumentParser turns abbreviations off and, on an unrecognized option, names the options probably meant (same destination, the options it is a prefix of, then difflib's closest spellings). It is used by the `yeto` command tree (sub-parsers inherit the class), the NC pool tool and the Miles island entry. Short options still combine. One repo test relied on the abbreviation: the memory-estimate case full_parameter_fixed_partition passed --rollout-num-gpus 4, which landed on --rollout-num-gpus-per-engine and recorded a colocated layout. It now passes --rl-rollout-gpus 4 and its record is the fixed partition it names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test passed --rollout-num-gpus 1, which the abbreviation turned into --rollout-num-gpus-per-engine 1, so the refusal it matched was "fixed partition needs --rollout-num-gpus >= 1" instead of the convertible-node colocation rule it is about. With the full name it hits that rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hints are added in error() for the "unrecognized arguments" message, from the argv parse_known_args saw, instead of overriding parse_args. Code and tests that wrap argparse.ArgumentParser.parse_args (the guide command-line check, the island lr-schedule check) see every yeto parser again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
michaellchung
added a commit
that referenced
this pull request
Nov 26, 2026
…fewer look-alike hints; quoted preflight command (#925) * run up: print the dry run's cluster preflight command quoted The command run up's dry run prints was joined with spaces; an argument with a space or a shell character (an inventory path, say) did not paste back as one word. It is shlex.join'ed now, as the launch gate already does. The customer K3.1 dry runs print the same line (nothing there needs quotes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * exact_argparse: offer a spelling only at difflib similarity 0.8 0.6 offered look-alikes: --rl-max named --rl-image (0.78) next to the --rl-max-* options it is a prefix of. 0.8 keeps typos such as --modle (--model, 0.86) and --rl-imgae (--rl-image, 0.9). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Every argparse entry point under yeto/ takes full option names only The command tree, the NC pool tool and the Miles island moved to ExactArgumentParser in #904; the module entry points did not. The 62 modules that build a parser (node-side ones whose argv the launcher renders: engine sampler, init_from_release, tape_upload, store_dispense, role_switch, controller, health readers, spot watchdog, ssh_harness, learners, exporters, ...) now build an ExactArgumentParser; their sub-parsers inherit it. weights_sync.py and preflight/bench.py run as single files on a node (no yeto package there): they keep argparse and set allow_abbrev=False on the parser and, through parser_class, on every subcommand. Tests: every parser under yeto/ is exact (a plain ArgumentParser fails), the two standalone tools refuse a prefix in a subcommand, and error() replaces argparse's "unrecognized arguments" message only (another error, a caller's look-alike message and parse_known_args stay as they were); look-alike options are not offered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * codepack: keep stdlib argparse (a node imports it from a partly unpacked pack) PACK_FETCH_PY puts the pack's yeto/ files on sys.path and imports yeto.codepack before the tree is unpacked and verified; its contract (test_rl_ssh_resident's tiny pack of __init__.py + codepack.py) is a module with no top-level yeto import. It keeps argparse and sets allow_abbrev=False on the parser and its subcommands, like the two tools shipped alone to a node; the coverage test names it with them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fleet_store: its merge CLI takes full option names too (new since the switch, #910) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
argparse's default
allow_abbrev=Trueresolves any unambiguous prefix of a long option to that option. A misspelled option name therefore set a different option without any warning. Example:yeto launch --rollout-num-gpus 8set--rollout-num-gpus-per-engine 8. The dedicated rollout GPUs option is--rl-rollout-gpus. Found by OC-H while re-reviewing #887.Change
yeto/exact_argparse.py:ExactArgumentParser, anargparse.ArgumentParserthat defaults toallow_abbrev=False.add_subparsersbuilds sub-parsers of the same class, so every subcommand inherits the setting.When an option is not recognized, the error names the options the user probably meant, at most 4, in this order:
The hints come from the selected subcommand's options.
yetocommand tree (60 parsers: launch, shape, run up/scale/..., fleet, rollout, cluster, preflight, breaker, island, dashboard, sandbox, cost/cleanup, adapt/model, ...);yeto.cli.parse_args;launch/rl_args.py;python -m yeto.launch.nc/yeto.launch.pool, all subcommands);The verl island entry already used
allow_abbrev=False.allow_abbrev=Falseonly disables prefix matching of--longoptions. Combined single-dash flags such as-vxn3still parse, and this is tested. The only short option in these trees besides-hisdashboard export -o.parse_known_args. Miles trainer flags travel as the value ofYETO_MILES_TRAIN_EXTRA_ARGV=...(--island-env/--modal-env), and yeto's parsers never interpret them as options. The island argv rendered by the launcher was already spelled out in full.parse_known_argsappears in two places, and neither one forwards argv:stage1._check_island_argv: a check that reports unknown flags;init_from_release: a probe of a single option.Scan: who relied on abbreviations
I used a one-off local script, not committed. It walked every parser above and checked each
--optiontoken in:docs/(includingKIMI_K31_ASYNC_RL_GUIDE.mdandK31_BARE_METAL_B300.md);examples/(includingexamples/k31andexamples/own-cluster);tests/goldenandtests/fixtures, including everytrainer.argvin the run configs.Each token was attributed to the command it belongs to. A token that is not a full option name of that command but is a prefix of one counts as relying on abbreviation. Every
trainer.argvwas also parsed by the launch parser twice, once with abbreviation on and once with it off, and the two results were compared.tests/test_memory_estimate_sampler.py, casefull_parameter_fixed_partition: it passed--rollout-num-gpus 4, which landed on--rollout-num-gpus-per-engine 4. Its golden record (tests/data/memory_estimate_records.json) therefore described a colocated layout (dp 8) instead of the fixed partition the case is named after. The case now passes--rl-rollout-gpus 4, and only that entry of the record changed: dp 4,colocated: false, no rollout-phase extra.tests/test_rl_convertible_pool_launch.py: the refusal it matched came from the misparse ("fixed partition needs --rollout-num-gpus >= 1"), not from the convertible-node colocation rule it is about. With--rl-rollout-gpus 1it hits that rule.Customer-visible change
A customer script that typed a shortened option name, e.g.
--rl-max-policy 12for--rl-max-policy-age 12, now fails at parse time with exit code 2, and the error names the full option. None of the shipped customer docs, examples or the customer kit uses a shortened name, so nothing there changes. The customer K3.1 path parses and renders exactly as before.Gates
run up --dry-runfor everyexamples/k31/run*.jsonand the pool--dry-run, compared line by line with origin/main. 5 outputs were compared.tests/test_exact_option_names.pychecks the following:yetosubcommand and the Miles island parser haveallow_abbrev=False;--rollout-num-gpusis refused and the hint names--rl-rollout-gpusand--rollout-num-gpus-per-engine, throughmain()and in the--opt=valueform;fleet show --gen,nc pool --dry);YETO_MILES_TRAIN_EXTRA_ARGVvalue reaches Miles unchanged;--shard i/4), run locally under heavy machine load: 18,104 passed. The 3 failures were timing tests (test_sync_lead_cap,test_peer_recovery_milesx2). They differ from run to run, also fail on main under the same load, and pass when rerun alone. After the rebase onto image adopt: manifest digest, image probe, fit to the nodes and parallel pre-pull #893, the touched and related files were rerun: 351 passed. With the audit hook enabled, no parser in the suite resolved an option by abbreviation.Not in this PR
About 60 standalone module entry points under
yeto/still use the argparse default. Examples arelearner.py,iso_worker.py,export.py, the diffusion and spot tools, andssh_harness. Most of them parse argv that yeto renders itself. The audit hook found no abbreviation in any of them across the suite. They can move toExactArgumentParserin a follow-up.🤖 Generated with Claude Code