fix(env_check): use the amp_bf16 precision for the CPU autocast branch - #2705
Open
Anai-Guo wants to merge 1 commit into
Open
fix(env_check): use the amp_bf16 precision for the CPU autocast branch#2705Anai-Guo wants to merge 1 commit into
Anai-Guo wants to merge 1 commit into
Conversation
The elif tested tbmodel.dargs.precision == "amp" and tbmodel.dargs.precision == "bf16", which can never both hold, so torch.cpu.amp.autocast was never appended to contexts and check_accuracy always ran the CPU bf16 configuration in plain fp32. "amp_bf16" is the single precision value that AVAILABLE_PRECISIONS defines for this mode, and extra_args.py already pairs it with the CPU device for the same autocast context. Signed-off-by: Anai-Guo <antai12232931@outlook.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
check_accuracy()intorchbenchmark/util/env_check.pybuilds the list of autocast contexts the accuracy run executes under. The CPU branch is unreachable:tbmodel.dargs.precisioncannot be both"amp"and"bf16"at the same time, so this condition is alwaysFalseandtorch.cpu.amp.autocastis never appended.contextsis whatforward_pass/forward_and_backward_passopen vianested(*contexts), so a CPU bf16-autocast accuracy run silently executes in plain fp32 — it reports on a configuration it never actually exercised.Why
amp_bf16is the intended value"amp"and"bf16"are two separate entries inAVAILABLE_PRECISIONS, and the mode this branch wants has its own third entry,"amp_bf16". The repo already pairs that value with the CPU device for this exact autocast context, intorchbenchmark/util/extra_args.py:and
is_staged_train_testsupport is gated the same way atextra_args.py:54(precision == "amp_bf16"+device == "cpu"). So this is theenv_check.pycopy of an existing, correct condition.Fix
Verification
I sliced the
contexts = []…contexts.append(torch.cpu.amp.autocast)block straight out of the file (before and after the patch, viagit show HEAD:…vs the working copy — not hand-transcribed) and replayed it over every cell ofAVAILABLE_PRECISIONS× {cpu,cuda} × {eval, train}, withtorchstubbed so the appended context is identifiable:The CUDA branch above it is untouched, and 38 of the 40 cells are bit-identical — the only behaviour change is that the two cells
extra_args.pyalready documents now actually get the autocast context.black(repopyproject.toml, line-length 88) reports the file unchanged.🤖 Generated with Claude Code