From 67ad2a031fc9ef22bb03d656243fb774fd6bda2e Mon Sep 17 00:00:00 2001 From: avlp12 Date: Tue, 25 Aug 2026 09:37:36 +0900 Subject: [PATCH] fix(gguf): compile the GGUF JIT extension as C++20 The extension does not build with gcc as nvcc's host compiler. nvcc's host pass rewrites static_castlist)::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. --- python/freetoken/kernel/gguf.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/freetoken/kernel/gguf.py b/python/freetoken/kernel/gguf.py index 04a16560..87c85324 100644 --- a/python/freetoken/kernel/gguf.py +++ b/python/freetoken/kernel/gguf.py @@ -51,7 +51,13 @@ def _c_compiler_for(cxx: str) -> str: def _module(): from torch.utils.cpp_extension import load - extra_cuda_cflags = ["-O3", "--expt-relaxed-constexpr"] + # ``-std=c++20`` is load-bearing, not a modernization: nvcc's host pass rewrites + # ``static_castlist)::difference_type>`` in libtorch's + # ``ATen/core/List_inl.h`` into a form that drops the ``typename``, which every + # g++ we have (12/13/15) rejects under C++17. C++20 (P0634) makes ``typename`` + # implicit in a static_cast type-id, so the rewritten form compiles. torch only + # appends its own ``-std=c++17`` when no ``-std=`` is present, so this wins. + extra_cuda_cflags = ["-O3", "--expt-relaxed-constexpr", "-std=c++20"] host_cxx = _host_compiler() if host_cxx is not None: # Point both nvcc's host pass (-ccbin) and torch's C++ compile (CXX) at a