Skip to content

fix(jit): refuse sccache < 0.18 (drops cicc/ptxas on CUDA 13.3), remember failed builds - #6502

Merged
Qubitium merged 1 commit into
mainfrom
jit-build-failure-cache
Dec 1, 2026
Merged

Qubitium merged 1 commit into
mainfrom
jit-build-failure-cache

Conversation

@Qubitium

@Qubitium Qubitium commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

On a host with sccache < 0.18 on PATH and CUDA 13.3+, every CUDA JIT kernel build failed and quantization silently fell back to the eager path. The failed build was also retried in every process, costing 6–15 s each time. This PR:

  • refuses to compile through sccache older than 0.18.0;
  • adds a jit_compiler_launcher setting to KernelConfig / RuntimeConfig;
  • remembers failed builds across processes;
  • fixes a misleading stale-lock warning.

Root cause

torch 2.13 started putting ccache or sccache in front of every C++/nvcc JIT compile whenever one is on PATH (pytorch/pytorch#175696). The only opt-out is TORCH_NO_COMPILER_WRAPPER=1.

sccache does not run nvcc as one command. It reads the steps from nvcc --dryrun and runs them itself. Before 0.18.0 it found cicc's input file by position: the third argument from the end. CUDA 13.3 appends a new flag after that input:

cicc ... "x.cpp1.ii" --simt-only -o "x.ptx"

So the lookup returns --simt-only, and sccache silently drops cicc (CUDA C++ → PTX) and ptxas (PTX → cubin). fatbinary then fails:

fatbinary fatal   : Could not open input file 'gptq_block.sm_80.cubin'

Upstream fix: mozilla/sccache#2722, released in sccache 0.18.0.

How this was confirmed:

  • The sccache 0.13 trace runs exactly gcc -E, cudafe++, gcc -E, fatbinary, gcc -c.
  • Replaying sccache 0.13's grouping code on real CUDA 13.3 --dryrun output reproduces that list.
  • Finding the input by its .cpp1.ii suffix (the upstream fix) keeps all 7 steps.
  • Plain nvcc builds the same source in 28 s.
flowchart TD
    A[kernel needed] --> B{cached binary loads?}
    B -- yes --> R[use kernel]
    B -- no --> C{recent failure recorded<br/>for this environment?}
    C -- yes --> F[fallback path, no compile]
    C -- no --> P{KernelConfig<br/>jit_compiler_launcher}
    P -- False --> N[build without launcher]
    P -- True --> W1[build through launcher]
    P -- None --> K{sccache &lt; 0.18<br/>or unknown version?}
    K -- yes --> N
    K -- no --> W2[build through launcher]
    W2 -- failed --> N
    W2 -- ok --> R
    W1 -- ok --> R
    W1 -- failed --> M[record failure] --> F
    N -- ok --> R
    N -- failed --> M
Loading

Changes (gptqmodel/utils/cpp.py)

Refuse old sccache. Read sccache --version once per process. Never compile through sccache < 0.18.0, or one whose version cannot be read, and log the version found plus the override. ccache and sccache ≥ 0.18 are still used.

jit_compiler_launcher (KernelConfig and RuntimeConfig):

Value Behaviour
None (default) The rule above, plus one retry without the launcher if a build through an allowed launcher fails.
False Never use a launcher.
True Always use one, with no retry.

Remember failed builds. A failed build writes .gptqmodel_build_failed.json in its fingerprinted cache directory, and later processes go straight to the fallback. A successful build deletes it. The record is ignored when any of these holds:

  • PATH, CC/CXX, CUDA_HOME/CUDA_PATH/ROCM_PATH, the tool binaries, TORCH_NO_COMPILER_WRAPPER or the launcher policy changed;
  • it is more than 24 h old;
  • GPTQMODEL_KERNEL_REBUILD or the kernel's *_FORCE_REBUILD is set.

Retry correctness. torch records the build inputs before compiling, so an unchanged record makes a retry skip the compile and load a .so that was never built. The retry clears that in-process record.

Stale-lock warning.

Docs: new docs/jit-kernel-builds.md (step table, the bug, the policy); docs/kernel-config.md gets the field.

Test plan

  • tests/test_torch_ops_jit_extension.py: 11 new tests fail on main and pass here. More tests were then added for the version gate: sccache 0.13 / 0.17.9 / unknown are refused for .cu and .cpp sources on nvcc 12.9 and 13.3; sccache 0.18.0 / 0.20.1 and ccache are kept; plus policy False/True, a policy change invalidating a recorded failure, the RuntimeConfig → KernelConfig mapping and the version parser.

  • All 25 JIT/config test files, run per file, including the real Marlin/Machete/QQQ/ExLlama builds: 514 passed, 3 skipped.

  • Real GPTQ block kernel builds on sccache 0.13.0, CUDA 13.3 and A100, from an empty cache each time:

    Policy Result
    default sccache refused; built in 24 s
    False built in 25 s
    True failed in 6 s, fallback path

    Marlin fp16/bf16 and TT blockfloat CUDA also build with the default policy.

  • [email protected] lint gate clean.

🤖 Generated with Claude Code

…ck log

torch >= 2.13 prepends ccache/sccache to every JIT kernel compile when one
is on PATH. sccache before 0.18.0 finds cicc's input as the third argument
from the end; CUDA 13.3 nvcc appends `--simt-only` after it, so sccache
silently drops the cicc and ptxas steps and `fatbinary` fails on the missing
`.cubin` (fixed upstream in mozilla/sccache#2722). Every CUDA JIT kernel
(GPTQ block update, Marlin, TT blockfloat, ...) then failed to build and
quantization fell back to the slower eager path, paying the failed compile
again in every process.

- Read `sccache --version` and never compile through sccache < 0.18.0 (or
  one whose version cannot be read); log why and how to override.
- New `KernelConfig` / `RuntimeConfig` field `jit_compiler_launcher`:
  None (default) = the rule above plus one retry without an allowed
  launcher that fails; False = never use a launcher; True = always, no retry.
- Record a failed build in its cache dir so later processes take the
  fallback at once; the record expires after 24h and is ignored when the
  toolchain, PATH, CUDA_HOME, launcher policy or a force-rebuild env changes.
- The retry clears torch's in-process build record, which otherwise makes
  the retry skip the compile and load a library that was never produced.
- Stale torch build-lock cleanup only runs on torch < 2.14 (FileBaton);
  the warning no longer prints this process's own pid as the "dead" owner.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Qubitium
Qubitium marked this pull request as ready for review December 1, 2026 00:58
@Qubitium
Qubitium merged commit 69e159e into main Dec 1, 2026
6 checks passed
@Qubitium
Qubitium deleted the jit-build-failure-cache branch December 1, 2026 00:59
Qubitium added a commit that referenced this pull request Dec 1, 2026
…er_cache (#6505)

- Rename `jit_compiler_launcher` to `compiler_cache` (#6502 just merged;
  no release carries the old name). `RuntimeConfig.compiler_cache` is the
  one public setting; the `KernelConfig` field is only the internal carrier
  every RuntimeConfig field uses. Log messages point at RuntimeConfig.
- Document that an sccache on PATH must be >= 0.18.0 (older drops the
  cicc/ptxas steps of CUDA 13.3+ builds) in docs/jit-kernel-builds.md,
  docs/kernel-config.md, README install notes, AGENTS.md and the
  gptqmodel-agent-workflow skill (check `sccache --version` before
  building or testing kernels; distro packages ship 0.13).
- Make the jit-kernel-builds.md example runnable on a CPU-only, offline
  host (it referenced an undefined `model_id` and failed the docs test).

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant