Repository navigation
Support native half-precision (Float16/BFloat16) GGUF transformers - #81
Merged
Merged
Conversation
- 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.
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.
Summary
Stage 3 of half-precision (
Float16/BFloat16) transformer support acrosscompute->gomlx->go-huggingface. Seedocs/HalfPrecision-Transformer.mdfor full architecture notes and benchmark details.go.mod/go.sumtocomputeandgomlxreleases with Stage 1 & 2 half-precision kernels (FusedSoftmax,FusedScaledDotProductAttention,FusedDense, strict norm dtype enforcement, andWithNormDType).models/transformer):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.) inFloat32withQuantGGML.CreateGoMLXModel,loadStoreGGUF, andloadSplitGGUFQKV(splitTensorFirstAxis3) to retainFloat16/BFloat16weights and split QKV tensors natively while configuringtm.WithNormDType(normDType)when norm weights areFloat32(matchingllama.cppF16/BF16exports).Model.WithForceFloat32(bool)/Model.ForceFloat32()(and-force_f32inexamples/msmarco/benchmark_embed) to forceFloat32conversion for GGUF and Safetensors models on backends without half-precision support.models/transformer/sentence.go):Float16/BFloat16inputs toFloat32innormalizeEmbeddingsandApplySentencePooling(PoolingModeMeanTokens) to preventSquareoverflow and1e-12epsilon underflow, casting back to the input dtype.Verification
GOWORK=off GOEXPERIMENT=simd go test -short ./...(includingTestGGUFHalfPrecisionEndToEndandTestSentenceHalfPrecisionPoolingAndNormalizeacrossxla:cuda,xla:cpu, andgo).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 inFloat16vs 100 items/s (7.7K tokens/s) with-force_f32=true.