Skip to content

Take long options by their full name only (no argparse abbreviations) - #904

Merged
michaellchung merged 3 commits into
mainfrom
fix/argparse-no-abbrev
Nov 26, 2026
Merged

michaellchung merged 3 commits into
mainfrom
fix/argparse-no-abbrev

Conversation

@michaellchung

Copy link
Copy Markdown
Contributor

Problem

argparse's default allow_abbrev=True resolves 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 8 set --rollout-num-gpus-per-engine 8. The dedicated rollout GPUs option is --rl-rollout-gpus. Found by OC-H while re-reviewing #887.

Change

  • New yeto/exact_argparse.py: ExactArgumentParser, an argparse.ArgumentParser that defaults to allow_abbrev=False. add_subparsers builds 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:
    1. the option with the same destination;
    2. the options the token is a prefix of (the ones the abbreviation used to pick);
    3. difflib's closest spellings.
      The hints come from the selected subcommand's options.
    yeto: error: unrecognized arguments: --rollout-num-gpus 8
      --rollout-num-gpus: options are taken by their full name; did you mean --rl-rollout-gpus, --rollout-num-gpus-per-engine, --rollout-pool, --rollout-model?
    
  • Parsers switched to it:
    • the whole yeto command tree (60 parsers: launch, shape, run up/scale/..., fleet, rollout, cluster, preflight, breaker, island, dashboard, sandbox, cost/cleanup, adapt/model, ...);
    • the legacy yeto.cli.parse_args;
    • the contract-default parser in launch/rl_args.py;
    • the NC pool tool (python -m yeto.launch.nc / yeto.launch.pool, all subcommands);
    • the Miles island entry.
      The verl island entry already used allow_abbrev=False.
  • Short options are unaffected: on Python 3.8+, allow_abbrev=False only disables prefix matching of --long options. Combined single-dash flags such as -vxn3 still parse, and this is tested. The only short option in these trees besides -h is dashboard export -o.
  • Flags passed through to Miles are unaffected. yeto does not pass unknown argv on to Miles or SGLang with parse_known_args. Miles trainer flags travel as the value of YETO_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_args appears 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 --option token in:

  • docs/ (including KIMI_K31_ASYNC_RL_GUIDE.md and K31_BARE_METAL_B300.md);
  • examples/ (including examples/k31 and examples/own-cluster);
  • tests/golden and tests/fixtures, including every trainer.argv in 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.argv was also parsed by the launch parser twice, once with abbreviation on and once with it off, and the two results were compared.

  • Customer docs, examples, goldens and fixtures: no abbreviation. 12 launch argvs parsed identically both ways.
  • I also ran the full test suite on main with an argparse hook that logs any option resolved only by abbreviation. Two tests relied on it, and both had the exact bug this PR fixes:
    • tests/test_memory_estimate_sampler.py, case full_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 1 it hits that rule.

Customer-visible change

A customer script that typed a shortened option name, e.g. --rl-max-policy 12 for --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

  • K3.1 customer plan golden + breakers golden: 52 passed (main: 52 passed).
  • customer dry-run diff: none. That covers run up --dry-run for every examples/k31/run*.json and the pool --dry-run, compared line by line with origin/main. 5 outputs were compared.
  • New tests/test_exact_option_names.py checks the following:
    • every yeto subcommand and the Miles island parser have allow_abbrev=False;
    • --rollout-num-gpus is refused and the hint names --rl-rollout-gpus and --rollout-num-gpus-per-engine, through main() and in the --opt=value form;
    • a misspelling gets the difflib suggestion;
    • full names parse as before;
    • subcommand hints come from that subcommand's options (fleet show --gen, nc pool --dry);
    • short options still combine;
    • the customer kit argv parses and its YETO_MILES_TRAIN_EXTRA_ARGV value reaches Miles unchanged;
    • the Miles island refuses a prefix and still renders Miles' own flag names.
  • Full suite, 4 shards (--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_miles x2). 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 are learner.py, iso_worker.py, export.py, the diffusion and spot tools, and ssh_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 to ExactArgumentParser in a follow-up.

🤖 Generated with Claude Code

michaellchung and others added 3 commits November 27, 2026 00:11
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
michaellchung merged commit 18ac70f into main Nov 26, 2026
7 checks passed
@michaellchung
michaellchung deleted the fix/argparse-no-abbrev branch November 26, 2026 19:50
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant