Fix --do-sample / --enable-bucketing argparse type=bool bug#32
Open
vyom-hai wants to merge 1 commit intoaws-neuron:mainfrom
Open
Fix --do-sample / --enable-bucketing argparse type=bool bug#32vyom-hai wants to merge 1 commit intoaws-neuron:mainfrom
vyom-hai wants to merge 1 commit intoaws-neuron:mainfrom
Conversation
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.
Summary
main.py:--do-sample Falseparses asTrue,--enable-bucketing Falseparses asTrue.argparse.BooleanOptionalActionso the standard--flag/--no-flagidiom works.main.py:113(--do-sample) andmain.py:157(--enable-bucketing).The bug
argparse(type=bool)is not a string→bool converter. Thetype=callable is invoked on the raw CLI argument string, andbool(non_empty_string)is alwaysTruein Python. So every textual "off" value the user might reasonably pass is silently coerced toTrue.Empirically (with the unpatched
main.py):The only reachable "off" path is
--do-sample '', which is awkward to type from most shells and obviously not what users intend.--no-do-sampleis rejected outright because the action doesn't declare it. The same is true for--enable-bucketing.Why it matters for the contest
This isn't a stylistic concern — it materially affects accuracy validation in
evaluate_all:args.do_sample=True(the default, and what every reasonable string also resolves to) is propagated intoOnDeviceSamplingConfig(do_sample=True, ...)atmain.py:380-383.OnDeviceSamplingConfigis consumed at trace time byprepare_inference, sodo_sample=Trueis baked into the compiled graph. There's no runtime override.run_accuracy_check→logit_validation→generate_fn), the call atmain.py:604ismodel.generate(..., do_sample=False, ...). That kwarg is silently ignored: whenself.on_device_sampling=True,hf_adapter._sampleusesoutputs.tokensfrom the on-device multinomial sampler (hf_adapter.py:229-230), not the host-sidedo_sampleargument.logit_validation's divergence-handling fallback path, which is slower and non-deterministic. Multiple teams have had to programmatically work around this by mutatingargs.do_sample = Falsebeforeprepare_inference.The fix converts the validation accuracy run into the deterministic greedy/argmax path it was always supposed to use, simply by allowing
--no-do-sampleto actually parse asFalse.The fix
argparse.BooleanOptionalActionis the standard library idiom for paired--flag/--no-flagboolean options. It has been part ofargparsesince Python 3.9; the contest harness already requires Python ≥3.10 transitively vianeuronx_distributed.Test plan
--no-do-sample→False,--do-sample→True, no-flag →True(default).--no-enable-bucketing→False,--enable-bucketing→True, no-flag →True(default).argparsewas already imported atmain.py:3).