mirror of
https://github.com/FlashML-org/FreeToken.git
synced 2026-12-03 03:35:59 +08:00
chore(ggml): replace freetoken.patch with the llama.cpp pin (#873)
The patch repeats every edit to a copied file and nothing checks that the two agree. The pin and the tree reproduce it. scripts/sync-llama-cpp.sh diffs the copy against the pin and merges a newer llama.cpp from it, and docs/ggml-kernels.md says how to maintain the copy.
This commit is contained in:
@@ -1,19 +1,3 @@
|
||||
llama.cpp 8c2134a8755d8a9792af513dab20282affe903e4 (2026-10-14)
|
||||
|
||||
Only the ggml files that FreeToken compiles or includes:
|
||||
- the GGUF ops (freetoken/ggml_ops.cu, built by kernel/ggml.py): ggml/include -> include, ggml/src -> src, ggml/src/ggml-cuda -> ggml-cuda.
|
||||
- the CPU MoE row kernels (freetoken/cpu_kernels.c and freetoken/variant_module.cpp, one freetoken.kernel.ggml_cpu module per x86 variant, built by setup.py): ggml/src/{ggml-quants.c,ggml-quants.h,ggml-backend-impl.h} -> src, ggml/include/ggml-cpu.h -> include, ggml/src/ggml-cpu/{quants.c,quants.h,vec.cpp,vec.h,ggml-cpu-impl.h,simd-mappings.h,arch-fallback.h,arch/x86/quants.c,arch/x86/cpu-feats.cpp} -> ggml-cpu. These have no local changes.
|
||||
|
||||
Local changes, kept in freetoken.patch (already applied):
|
||||
- quantize.cu/.cuh: the q8_1 quantize kernels read fp32, bf16 or fp16 activations.
|
||||
- mmq.cu/.cuh: MMQ takes bf16 or fp16 activations, except on the native fp4 path. Its kernels are built for fp32 and bf16 results (dst_t); a bf16 result that needs the stream-k fixup is computed in fp32 first, and so is an fp16 result unless GGML_MMQ_F16_DST builds fp16 kernels too.
|
||||
- mmvq.cu/.cuh: MMVQ takes bf16 or fp16 activations, can write bf16 or fp16 results, and can reuse activations already quantized to q8_1 (src1_q8_1_pre).
|
||||
- mmq.cu/.cuh, mmid.cu/.cuh: MoE MMQ runs a flat grid over only the (expert, column tile) pairs that hold tokens, which mm_ids_helper lists while it sorts; ncols_max > 0 keeps the regular grid.
|
||||
- mmid.cu/.cuh, mmq.cu: mm_ids_helper is a counting sort over blocks of routes (count, scan, scatter) instead of one warp per expert scanning every route, so its cost no longer grows with n_experts x n_tokens and n_tokens is not bounded by shared memory (n_experts is, at 8192). Up to 4096 routes it runs as one kernel. Within an expert the blocks keep token order; the routes inside one block do not, which the flat MoE grid does not see (one tile per block) but a stream-k regular grid (ncols_max > 0) would, in its fp32 summation order.
|
||||
- common.cuh: the native fp4 MMA (BLACKWELL_MMA_AVAILABLE, blackwell_mma_available) is off unless GGML_CUDA_FP4_MMA is defined; it needs an sm_120a/sm_120f build.
|
||||
- mmvq.cu, common.cuh: the NVFP4 scale fusion (x_scale, gate_scale) reads strided scale vectors, e.g. columns of a per-expert scale bank.
|
||||
- getrows.cu, dequantize.cuh: get_rows reads NVFP4 rows, e.g. an NVFP4 token_embd.
|
||||
- mmq.cu/.cuh, mmq-load-tiles.cuh, template-instances/mmq-instance-iq1_m.cu: MMQ runs IQ1_M, which llama.cpp has no MMQ kernel for. Its values times 8 are int8, so it loads into IQ2_XS's tile layout and takes IQ2_XS's configs.
|
||||
- mmvq.cu, mmid.cu, mmq.cu/.cuh, quantize.cu: a negative expert id is an inactive route (hybrid decode): MMVQ writes zero rows for it without reading an expert, and MMQ gives it no compact row when called with inactive_ids.
|
||||
|
||||
To update: copy the same files from a newer llama.cpp, apply freetoken.patch, and update this file.
|
||||
Copied from llama.cpp and edited in place, see docs/ggml-kernels.md.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -195,7 +195,9 @@ int64_t ggml_cuda_mm_ids_helper_scratch_size(const int n_experts, const int n_to
|
||||
// ids_src1 describes how to permute the flattened column indices of src1 in order to get a compact src1 tensor sorted by expert.
|
||||
// ids_dst describes the same mapping but for the dst tensor.
|
||||
// The upper and lower bounds for the ith expert in the compact src1 tensor are stored in expert_bounds[i:i+1].
|
||||
// FreeToken: a counting sort over blocks of routes; within an expert the blocks keep token order, the routes inside one block do not.
|
||||
// FreeToken: a counting sort over blocks of routes. One warp per expert over every route costs n_experts x n_tokens and bounds n_tokens by shared memory.
|
||||
// Within an expert the blocks keep token order, the routes inside one block do not.
|
||||
// The flat MoE grid does not see that order (one tile per CUDA block), but a stream-k regular grid (ncols_max > 0) would, in its fp32 summation order.
|
||||
void ggml_cuda_launch_mm_ids_helper(
|
||||
const int32_t * __restrict__ ids, int32_t * __restrict__ ids_src1, int32_t * __restrict__ ids_dst, int32_t * __restrict__ expert_bounds,
|
||||
int32_t * __restrict__ scratch, int2 * __restrict__ tile_map, const int J, const int ntiles, const int jt_none,
|
||||
|
||||
+1
-6
@@ -1,10 +1,5 @@
|
||||
llama.cpp 8c2134a8755d8a9792af513dab20282affe903e4 (2026-10-14), the same pin as kernel/csrc/ggml
|
||||
|
||||
Only the gguf-py modules that the GGUF reader and the ggml type tables need: gguf-py/gguf/{constants,gguf_reader,quants,lazy}.py.
|
||||
The PyPI gguf release lags the ggml types in this tree (gguf 0.19.0 cannot read Q2_0 tensors), so FreeToken reads GGUF files with this copy.
|
||||
|
||||
Local changes, kept in freetoken.patch (already applied):
|
||||
- __init__.py: imports only the vendored modules (upstream also pulls in the writer, vocab and metadata modules and their dependencies).
|
||||
- gguf_reader.py: imports constants relatively, so the installed gguf package is never picked up.
|
||||
|
||||
To update: copy the same files from the llama.cpp commit that kernel/csrc/ggml pins, apply freetoken.patch, and update this file.
|
||||
Copied from llama.cpp and edited in place, see docs/ggml-kernels.md.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# FreeToken: only the modules vendored here, llama.cpp also imports the writer, vocab and metadata modules
|
||||
from .constants import *
|
||||
from .lazy import *
|
||||
from .gguf_reader import *
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
--- a/gguf-py/gguf/__init__.py
|
||||
+++ b/gguf-py/gguf/__init__.py
|
||||
@@ -1,9 +1,4 @@
|
||||
from .constants import *
|
||||
from .lazy import *
|
||||
from .gguf_reader import *
|
||||
-from .gguf_writer import *
|
||||
from .quants import *
|
||||
-from .tensor_mapping import *
|
||||
-from .vocab import *
|
||||
-from .utility import *
|
||||
-from .metadata import *
|
||||
--- a/gguf-py/gguf/gguf_reader.py
|
||||
+++ b/gguf-py/gguf/gguf_reader.py
|
||||
@@ -21,7 +21,7 @@
|
||||
# Allow running file in package as a script.
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
-from gguf.constants import (
|
||||
+from .constants import (
|
||||
GGML_MAX_DIMS,
|
||||
GGML_QUANT_SIZES,
|
||||
GGUF_DEFAULT_ALIGNMENT,
|
||||
@@ -21,6 +21,7 @@ if __name__ == "__main__":
|
||||
# Allow running file in package as a script.
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
# FreeToken: a relative import, so an installed gguf package is never picked up
|
||||
from .constants import (
|
||||
GGML_MAX_DIMS,
|
||||
GGML_QUANT_SIZES,
|
||||
|
||||
Reference in New Issue
Block a user