Repository navigation
fix(paro): make the non-identity rotation trace- and capture-clean (#5225) - #5258
Merged
Merged
Conversation
…5225) `ParoTritonLinear` declares COMPILE_LEVEL.CUDAGRAPH, but every real (non-identity) Paro layer graph-broke twice, so `optimize()` on a Paro checkpoint was slower than eager: * `_resolve_rotation_launch` called `_ensure_rotation_autotune_cache_loaded`, which entered `_ROTATION_AUTOTUNE_DISK_LOCK` before its "already loaded" check. Dynamo cannot trace a `threading.Lock` context manager. * The fused `gptqmodel_paro` rotation ops are CUDA-only and had no Meta implementation, so fake-tensor tracing raised "Operator does not support running with fake tensors". Fix: * check the per-device loaded flag before taking the lock, and make `_resolve_rotation_launch` trace-safe (lock-free process-local cache read; a cold shape falls back to the native legacy launch config instead of touching disk). * register Meta implementations for `rotate`, `rotate_pair`, `rotate_pair_grad` and `grad_theta`, returning exactly the metadata the CUDA kernels allocate. * do not JIT-load the extension from inside a trace (`_rotation_extension_ready_for_call`), and prewarm it in `ParoLinear.optimize()` so the compiled graph keeps the fused op. * `ParoTritonLinear._select_plan` returns the default plan while compiling instead of benchmarking kernels on the host. * the compile-level test now builds a non-identity rotation with group_size=128 (the identity shortcut and group_size 32 never reached the fused op, which is how the false CUDAGRAPH claim passed). Measured on RTX 5090 (sm_120), torch 2.15.0+cu132, 4-layer model: before 14 breaks / 4 graphs / 0.47x eager; after 0 breaks / 1 graph / 1.37x eager, bitwise-identical output.
Qubitium
marked this pull request as ready for review
November 18, 2026 14:58
This was referenced Nov 18, 2026
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.
Fixes #5225.
Problem
ParoTritonLineardeclaresCOMPILE_LEVEL.CUDAGRAPH, but every non-identity Paro layer graph-broke twice, sooptimize()on a real Paro checkpoint was slower than eager (52 breaks / 50 graphs, 0.6x). The identity-rotation compile-level test never reached the rotation at all, which is how the false claim passed CI.flowchart TD subgraph before["Before: every non-identity layer breaks"] A1["compiled forward"] --> B1["_resolve_rotation_launch"] B1 --> C1["_ensure_rotation_autotune_cache_loaded"] C1 --> D1["with _ROTATION_AUTOTUNE_DISK_LOCK<br/>(taken before the loaded check)"] D1 --> E1["Unsupported context manager<br/>graph break per layer"] B1 --> F1["gptqmodel_paro::rotate<br/>no Meta impl"] F1 --> G1["Operator does not support<br/>running with fake tensors"] E1 --> H1["52 breaks / 50 graphs<br/>0.6x eager"] G1 --> H1 end subgraph after["After: one graph, fused op"] A2["compiled forward"] --> B2["_resolve_rotation_launch"] B2 --> C2["lock-free cache read<br/>(cold shape → native default)"] C2 --> D2["Meta impls give fake-tensor metadata"] D2 --> E2["fused rotate traced"] E2 --> F2["0 breaks / 1 graph<br/>1.37x eager, bitwise equal"] endChanges
gptqmodel/utils/paro.py_ensure_rotation_autotune_cache_loadedchecks the per-device loaded flag before the lock, so a warmed process never enters it on the steady-state rotation path._resolve_rotation_launchis trace-safe: while compiling it reads the process-local launch cache without a lock, and a cold shape returns the native legacy launch config (-1, -1) instead of touching disk or benchmarking._rotation_extension_ready_for_callkeeps a cold JIT build out of a trace; the reference rotation is used for that trace and the fused op afterwards.gptqmodel_ext/paro/rotation.cu: Meta implementations forrotate,rotate_pair,rotate_pair_grad,grad_theta, registered viaTORCH_LIBRARY_IMPL(gptqmodel_paro, Meta, ...). They allocate exactly the metadata the CUDA kernels allocate and never touch device memory.gptqmodel/nn_modules/qlinear/paro.py:ParoLinear.optimize()prewarms the fused rotation extension beforetorch.compiletraces the layer, so the compiled graph keeps the fused op rather than the reference fallback.gptqmodel/nn_modules/qlinear/paro_triton.py:_select_planreturns the default plan while compiling instead of benchmarking kernels (host timing) inside a trace.tests/kernels/test_kernel_compile_levels_quant.py:_build_paronow usesgroup_size=128with a non-identitytheta/channel_scales, so the level test actually exercises the fused rotation. (Identity returns early; group_size 32 is rejected by the fused kernel.)tests/kernels/test_paro_triton_cudagraph_5225.py(new, 5 tests): non-identity layer traces with 0 breaks undereager/aot_eager/inductor; reaches the declared CUDAGRAPH level; the fused ops run underFakeTensorModewith CUDA metadata; model-leveloptimize()installs a 0-break forward; cold-trace falls back safely.docs/paro.md: new "Compiled inference and CUDA graphs" section.Evidence (RTX 5090, sm_120, torch 2.15.0+cu132, Triton 3.9.0)
4-layer
ParoTritonLinearmodel,optimize(backend="inductor"), interleaved min-of-50:upstream/main(7fcb03e85)Single non-identity layer: red 1 break / 2 graphs and
fullgraph=Truefails; green 0 breaks / 1 graph, exact match undereager,aot_eager,inductor, andreduce-overheadCUDA-graph capture.Tests:
tests/kernels/test_paro_triton_cudagraph_5225.py→ 5 passed (5 failed pre-fix).tests/kernels/test_paro.py+test_kernel_compile_levels_quant.py+ the new file → 82 passed, 3 skipped.uvx [email protected] check gptqmodel docs/eora tests setup.py→ clean;git diff --checkclean.Not verified
tests/kernels/test_paro.py::_paro_module.