8000 Support native half-precision (Float16/BFloat16) GGUF transformers by janpfeifer · Pull Request #81 · gomlx/go-huggingface · GitHub
[go: up one dir, main page]

Skip to content

Support native half-precision (Float16/BFloat16) GGUF transformers - #81

Merged
janpfeifer merged 1 commit into
mainfrom
transformers-half-precision
Nov 15, 2026
Merged

janpfeifer merged 1 commit into
mainfrom
transformers-half-precision

Conversation

@janpfeifer
Copy link
Copy Markdown
Contributor

Summary

Stage 3 of half-precision (Float16 / BFloat16) transformer support across compute -> gomlx -> go-huggingface. See docs/HalfPrecision-Transformer.md for full architecture notes and benchmark details.

  • Dependencies: Updated go.mod / go.sum to compute and gomlx releases with Stage 1 & 2 half-precision kernels (FusedSoftmax, FusedScaledDotProductAttention, FusedDense, strict norm dtype enforcement, and WithNormDType).
  • Native half-precision GGUF loading (models/transformer):
    • Added ggufDTypes() to detect primary 2D weight dtype (Float16 / BFloat16 / Float32) and normalization parameter dtype for unquantized GGUFs while keeping quantized GGUFs (Q4_K_M, Q4_0, etc.) in Float32 with QuantGGML.
    • Updated CreateGoMLXModel, loadStoreGGUF, and loadSplitGGUFQKV (splitTensorFirstAxis3) to retain Float16/BFloat16 weights and split QKV tensors natively while configuring tm.WithNormDType(normDType) when norm weights are Float32 (matching llama.cpp F16/BF16 exports).
    • Added Model.WithForceFloat32(bool) / Model.ForceFloat32() (and -force_f32 in examples/msmarco/benchmark_embed) to force Float32 conversion for GGUF and Safetensors models on backends without half-precision support.
  • Half-precision pooling & L2 normalization stability (models/transformer/sentence.go):
    • Promoted Float16/BFloat16 inputs to Float32 in normalizeEmbeddings and ApplySentencePooling (PoolingModeMeanTokens) to prevent Square overflow and 1e-12 epsilon underflow, casting back to the input dtype.

Verification

  • GOWORK=off GOEXPERIMENT=simd go test -short ./... (including TestGGUFHalfPrecisionEndToEnd and TestSentenceHalfPrecisionPoolingAndNormalize across xla:cuda, xla:cpu, and go).
  • MS-MARCO benchmark (ChristianAzinn/bge-base-en-v1.5-gguf, bge-base-en-v1.5_fp16.gguf, GOMLX_BACKEND=go:quantized_cache, -bucket=0 -limit=100 -num_embedders=32 -warmup -dynamic=true): 177 items/s (13.6K tokens/s) natively in Float16 vs 100 items/s (7.7K tokens/s) with -force_f32=true.

- Update compute and gomlx dependencies (Stage 1 & 2 half-precision support).
- Detect unquantized half-precision GGUF weight and norm dtypes via ggufDTypes(), preserve Float16/BFloat16 weights and split QKV natively, and configure WithNormDType when norm weights are Float32.
- Add Model.WithForceFloat32 / ForceFloat32 and -force_f32 flag in benchmark_embed.
- Promote Float16/BFloat16 inputs to Float32 in normalizeEmbeddings and PoolingModeMeanTokens.
- Add unit tests (TestGGUFHalfPrecisionEndToEnd, TestSentenceHalfPrecisionPoolingAndNormalize), CHANGELOG entry, and Stage 3 benchmark notes.
@janpfeifer
janpfeifer merged commit 8646e0c into main Nov 15, 2026
5 checks passed
@janpfeifer
janpfeifer deleted the transformers-half-precision branch November 28, 2026 09:14
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

0