Skip to content

fix(kernel): GGUF JIT extension fails to build with gcc under C++17 - compile as C++20 - #159

Open
avlp12 wants to merge 1 commit into
FlashML-org:mainfrom
avlp12:fix/gguf-jit-cxx20
Open

fix(kernel): GGUF JIT extension fails to build with gcc under C++17 - compile as C++20#159
avlp12 wants to merge 1 commit into
FlashML-org:mainfrom
avlp12:fix/gguf-jit-cxx20

Conversation

@avlp12

@avlp12 avlp12 commented Aug 25, 2026

Copy link
Copy Markdown

Problem

The GGUF JIT extension (freetoken/kernel/gguf.py) fails to build from a clean environment with recent libtorch + g++ 12/13/15 under the default -std=c++17:

  • nvcc's host-compiler pass rewrites static_cast<typename decltype(impl_->list)::difference_type> in libtorch's ATen/core/List_inl.h into a form that drops the typename, which g++ rejects under C++17 (two hard errors; -fpermissive only downgrades the first).
  • The file's existing comment assumes clang++ is the host compiler, but clang++ is not present on many systems (including ours), and torch's JIT helper happily picks g++.

Net effect: any deployment without clang++ cannot build the GGUF MoE kernels at all — ggml_moe_a8_vec etc. are unavailable, so GGUF-quant serving is broken on such hosts.

Fix

Compile the extension as -std=c++20: P0634 makes typename implicit in a static_cast type-id, so the nvcc-rewritten header parses cleanly. torch.utils.cpp_extension only appends its own -std=c++17 when no -std= flag is present, so passing it via extra_cuda_cflags is sufficient and does not fight torch's defaults.

No kernel source changes; the emitted device code is unchanged.

Verification

  • Repro environment: WSL2 Ubuntu, torch 2.11.0+cu130, CUDA 13.3 nvcc, g++ 13 (also reproduced with g++ 12 and 15): build fails before, succeeds after.
  • Behavior: kernels JIT-build and pass our full GGUF MoE test battery (dequant reference checks, ggml_moe_a8_vec numeric comparisons on q4_0/q4_K/iq2_xs/iq3_xxs) bit-identically to a clang-built binary of the same sources.
  • In production use on our deployment (DeepSeek-V4-Flash, RTX 5090) since this change with no regressions.

🤖 Generated with Claude Code

The extension did not build on this box at all. nvcc's host pass rewrites

    static_cast<typename decltype(impl_->list)::difference_type>(pos)

in libtorch's ATen/core/List_inl.h into a qualified form that drops the
`typename`, and every g++ available here (12, 13, 15) then rejects the
template body under C++17 ("need 'typename' before ...", followed by a
brace-init conversion error). clang++ -- which the host-compiler comment in
this file assumes -- is not installed, and -fpermissive only downgrades the
first of the two errors.

C++20 (P0634 "down with typename!") makes `typename` implicit in a
static_cast type-id, so the rewritten form is valid and the file compiles
with the g++-13 already selected by _host_compiler(). torch appends its own
-std=c++17 only when no -std= flag is present, so passing it here wins
rather than conflicting.

Verified: JIT rebuild is clean under CUDA 13.3 / nvcc 13.3.73 with
g++-13 as -ccbin, torch 2.11.0+cu130, sm_120.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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