Skip to content

fix(paro): keep the CPU rotation forward graph-safe (#5115) - #5167

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-5115-paro-rotation-compile
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-5115-paro-rotation-compile

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5115. ParoLinear declares CPU INDUCTOR, but only a layer whose rotation is the identity reached it: every projection of a real Paro checkpoint broke the graph twice on CPU.

What Changed

  • _ensure_rotation_runtime_dtype no longer keys its cache with tensor_cache_key (is_inference()/_version/data_ptr()) inside the traced region. Under torch.compiler.is_compiling() it reads the eager-built runtime tensors, or converts them without publishing on a cold trace — the same shape as the existing _ensure_cpu_layout guard.
  • apply_paro_rotation_vectorized read its padding mask with bool(valid.any()). A fully padded rotation row is a no-op for the code below (every slot keeps its value), so the skip stays an eager-only speedup and the traced graph runs the row.
  • _forward_cpu_avx512 resolved the AVX512 JIT handle (importlib + setattr) inside the graph whenever the eager warmup had not published one — which is the case on hosts without AVX512-BF16. It now falls through to the ATen/dense paths while compiling, exactly as the eager path already does when the validator fails.

No declaration, output or eager-path change.

Tests

# new cases: non-identity rotation, bf16 and fp16 (red on main, green here)
python -m pytest tests/kernels/test_kernel_compile_levels_cpu.py -q -k paro
# 4 passed

python -m pytest tests/kernels/test_kernel_compile_protocol.py -q
# 63 passed, 153 skipped

python -m pytest tests/test_paro_rotation_lifecycle.py tests/test_paro_single_rounding_4317.py '"\\
  tests/test_paro_bf16_rotation_4221.py tests/test_paro_capture_order.py '"\\
  tests/kernels/test_paro_cpu_lock_concurrency_4885.py tests/test_paro_rocm_auto_4914.py -q
# 29 passed, 2 skipped

ruff check gptqmodel tests
# All checks passed
"'```

Host: one NVIDIA GB10 (sm_121, aarch64), torch 2.11.0+cu130.

End-to-end on a real quantized Paro checkpoint (tiny Llama, 2 layers, CPU, `backend="auto"` -> 14 rotated `ParoLinear` layers): with this change every layer compiles under `torch.compile(fullgraph=True, backend="inductor")` (0 failures); on unmodified `main` all 14 raise `Encountered tensor.is_inference() during tracing`.

Note on this host: `tests/kernels/test_kernel_compile_levels_cpu.py` has pre-existing red cases (NF12/QQQ/embeddings, identical on `origin/main`) whose torch `PythonDispatcherTLS` assertion poisons the rest of the file, so the new Paro cases are validated standalone here; they run in-file on x86 CI. `tests/test_paro.py` keeps its 23 pre-existing host failures (identical on baseline).

## Kernel Accuracy Requirements

- [x] No arithmetic change: the eager rotation path is untouched; the guard only makes the traced graph branch-free, and a fully padded row writes each slot back unchanged.
- [x] Verified `apply_paro_rotation_vectorized` vs the reference suites (`test_paro_single_rounding_4317.py`, `test_paro_bf16_rotation_4221.py`) still pass.
- [x] No dense/expanded weight cache added; only the same `theta`/`channel_scales` conversion, now performed without publishing module state while tracing.

`ParoLinear` declares `SUPPORTS_COMPILE_LEVEL_BY_DEVICE = {"cpu": INDUCTOR}`,
but only a layer whose rotation is the identity reached it. Every projection of
a real Paro checkpoint broke the graph twice on CPU:

- `_ensure_rotation_runtime_dtype` keyed its cache with `tensor_cache_key`
  (`is_inference()`/`_version`/`data_ptr()`) inside the traced region. Under
  `torch.compiler.is_compiling()` it now reads the eager-built runtime tensors
  (or converts without publishing on a cold trace), so no host key is read.
- `apply_paro_rotation_vectorized` read the padding mask with
  `bool(valid.any())`. A fully padded row is a no-op for the code below, so the
  early skip stays an eager-only speedup; the traced graph runs the row.
- `_forward_cpu_avx512` resolved the AVX512 JIT handle (importlib + `setattr`)
  inside the graph when the eager warmup had not published one, which happens
  on hosts without AVX512-BF16. It now falls through to the ATen/dense paths
  while compiling, as the eager path already did.

Tests: `test_kernel_compile_levels_cpu.py` gains a non-identity rotation case
for bf16 and fp16 (`_pack_paro_rotated`), which is red on `main` and asserts
the fullgraph trace, the declared level and inductor output parity.

Verified on one NVIDIA GB10 (sm_121, aarch64, torch 2.11.0+cu130):
- a real 2-layer Paro checkpoint (14 rotated `ParoLinear` layers) compiles
  every layer with `fullgraph=True, backend="inductor"`; on unmodified `main`
  14/14 fail with `is_inference() during tracing`.
- `pytest tests/kernels/test_kernel_compile_levels_cpu.py -k paro` -> 4 passed.
- `tests/test_paro.py` keeps its 23 pre-existing host failures (identical on
  baseline); the Paro rotation/rounding/lifecycle suites pass (29 passed).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant