Repository navigation
NF4 bitsandbytes GEMM gate: return before its lazy setup under torch.compile - #14608
Merged
Merged
Conversation
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.
#14386 added
_bnb_gemm_4bit_ok, the gate that sends 4-bit decode with 2 to 16 rows to bitsandbytes' GEMM on T4. On the first call its lazy setup runstorch.cuda.device_count()and the capability checks, and only then checks_is_compiling(). Dynamo cannot tracetorch.cuda.device_count(), so a cold compiled decode call fails withfullgraph=True:Without fullgraph it becomes a graph break. This happens on every GPU, not only T4, because the setup runs before the arch check. The existing compile test warms the function up eagerly first, which sets the gate up outside tracing and hides the failure.
Repro (fresh process):
Change
_bnb_gemm_4bit_oknow returns False undertorch.compileor with grad enabled before the lazy setup.Validation
test_fast_linear_forward_cold_compile_fullgraph(bsz 8 and 16) compilesfast_linear_forwardwithfullgraph=Truefrom the gate's cold state, with no eager warmup, and compares the result with eager.tests/test_bnb_integration_compile.py+tests/test_nf4_triton_gemv.py: 401 passed on torch 2.14.1 and on torch 2.10.0 (B200), incl. the eager bitsandbytes GEMM routing tests.Not covered: T4 hardware (the routing tests fake the arch); torch 2.11 to 2.13 (the change only moves existing Python checks).