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
Open
fix(kernel): GGUF JIT extension fails to build with gcc under C++17 - compile as C++20#159avlp12 wants to merge 1 commit into
avlp12 wants to merge 1 commit into
Conversation
The extension does not build with gcc as nvcc's host compiler. 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 gcc tested (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
available -- is not installed everywhere, 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: clean JIT rebuild under CUDA 13.3 / nvcc 13.3.73 with g++-13 as
-ccbin, torch 2.11.0+cu130, sm_120.
avlp12
force-pushed
the
fix/gguf-jit-cxx20
branch
from
August 26, 2026 07:17
20aca67 to
67ad2a0
Compare
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.
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:static_cast<typename decltype(impl_->list)::difference_type>in libtorch'sATen/core/List_inl.hinto a form that drops thetypename, which g++ rejects under C++17 (two hard errors;-fpermissiveonly downgrades the first).Net effect: any deployment without clang++ cannot build the GGUF MoE kernels at all —
ggml_moe_a8_vecetc. are unavailable, so GGUF-quant serving is broken on such hosts.Fix
Compile the extension as
-std=c++20: P0634 makestypenameimplicit in a static_cast type-id, so the nvcc-rewritten header parses cleanly.torch.utils.cpp_extensiononly appends its own-std=c++17when no-std=flag is present, so passing it viaextra_cuda_cflagsis sufficient and does not fight torch's defaults.No kernel source changes; the emitted device code is unchanged.
Verification
ggml_moe_a8_vecnumeric comparisons on q4_0/q4_K/iq2_xs/iq3_xxs) bit-identically to a clang-built binary of the same sources.🤖 Generated with Claude Code