Repository navigation
Feature: BF16/FP16 conversion to f32 chunking - #29442
Merged
ggerganov merged 4 commits intoOct 6, 2026
Merged
Conversation
|
Did you upload the compilation script |
Contributor
Author
I don't understand. |
JohannesGaessler
requested changes
Sep 26, 2026
JohannesGaessler
left a comment
Contributor
There was a problem hiding this comment.
- The implementation is way too complicated for what it is. All that should be needed is the on-the-fly creation of tensors that are slices of the original tensors in a loop.
- The size of 512 MiB should just be hard-coded. I don't consider it a parameter important enough to expose to users since that bloats the UI.
thelittlefireman
force-pushed
the
feature_bf16_f32_chunking
branch
from
September 27, 2026 08:56
9045583 to
ffa6c80
Compare
Contributor
Author
Is it better now ?
|
Co-authored-by: Johannes Gäßler <johannesg@5d6.de>
Co-authored-by: Johannes Gäßler <johannesg@5d6.de>
Contributor
Author
|
@JohannesGaessler Done. Also edit the initial PR message |
JohannesGaessler
approved these changes
Oct 4, 2026
Contributor
Author
|
@JohannesGaessler. Fix the dst stride for chunked, Sorry for the failling test. |
JohannesGaessler
approved these changes
Oct 5, 2026
danielhanchen
added a commit
to danielhanchen/llama.cpp
that referenced
this pull request
Oct 7, 2026
Resolves the conflicts with upstream ggml-org#29535 (K2 Horizon) and ggml-org#29442 (cuBLAS ldc and F16/BF16 src0 chunking): - Inkling and K2 Horizon both register: parser decl, parser source, model mapping case, EOG token, output tensor name. model.unembed moves a few lines up the OUTPUT tuple, away from upstream's embedding_projection, so pins that carry that line still merge. - LLAMA_VOCAB_PRE_TYPE_INKLING moves to 62, since upstream claimed 61 for K2_HORIZON. The id is internal; the GGUF carries tokenizer.ggml.pre as a string. - ggml_cuda_mul_mat_cublas_impl keeps the F32_PEDANTIC GemmEx path and passes upstream's ldc to both F32 branches; the pedantic compute-type override stays ahead of upstream's F16/BF16 src0 chunking, which it cannot overlap (pedantic only applies to F32 src0).
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 8, 2026
* ggml-cuda: chunk large BF16/FP16 to F32 conversions * Update ggml/src/ggml-cuda/ggml-cuda.cu Co-authored-by: Johannes Gäßler <johannesg@5d6.de> * Update ggml/src/ggml-cuda/ggml-cuda.cu Co-authored-by: Johannes Gäßler <johannesg@5d6.de> * ggml-cuda: respect dst stride in chunked cuBLAS matmul --------- Co-authored-by: Johannes Gäßler <johannesg@5d6.de> (cherry picked from commit ab09ea4)
1 task done
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Oct 24, 2026
* ggml-cuda: chunk large BF16/FP16 to F32 conversions * Update ggml/src/ggml-cuda/ggml-cuda.cu Co-authored-by: Johannes Gäßler <johannesg@5d6.de> * Update ggml/src/ggml-cuda/ggml-cuda.cu Co-authored-by: Johannes Gäßler <johannesg@5d6.de> * ggml-cuda: respect dst stride in chunked cuBLAS matmul --------- Co-authored-by: Johannes Gäßler <johannesg@5d6.de>
suishixingkong
pushed a commit
to suishixingkong/llama.cpp
that referenced
this pull request
Oct 27, 2026
…he replay case measure its own noise floor test-llama-context went from "CUDA error: out of memory" to 15/15 on this machine. Two independent defects, both reproduced and both measured. cuda/mul_mat_cublas: ggml-org#29442 chunks the conversion of src0 to the compute type, but only for F16/BF16 sources. A quantized weight reaches the same code path whenever the device has no fast fp16 (Maxwell, consumer Pascal) -- exactly the devices with the least free memory -- and is converted whole: the 254 M element Q4_K output layer becomes a 970 MiB f32 temporary, which a 2 GiB card cannot hold, so the graph died inside cuMemSetAccess with the device at 0 bytes free. Extend the row chunking to quantized sources (one row is a whole number of blocks, so it is as self-contained as an f16 row) and take the chunk budget from the free memory (a quarter of it, capped at the old 512 MiB), because a fixed budget cannot fit a 2 GiB device. Splitting along rows leaves each output element's K reduction untouched, so the numbers do not change. tests/llama-context/replay: the case compares a rolled-back sequence against a reference that never advanced past the rollback point, but the two cannot share the batch geometry -- the rolled-back context decodes the anchor inside the 4-token ubatch it is about to remove, the reference decodes it alone. A token's own arithmetic is not independent of that geometry (bit-exact for f16/q8_0 on CUDA, 1.6e-3 nmse for a 2-bit cache, 1.3e-3 for f16 on CPU) and the recurrent state carries the difference through the whole replay, so the fixed 1e-4 bound only held for one backend/type combination -- and non-monotonically: a q4_0 K cache fails while q4_0/q4_0 passes. Measure the geometry sensitivity in the case itself, on two short lived probe contexts, and scale the bound with it. Evidence. - Pool probe: cuMemSetAccess out of memory on device 1 (GTX 950, 2047.88 MiB) with free=0.00 MiB; the growth log names the node: result_output MUL_MAT, 970.00 MiB requested, 254279680 elements == n_vocab*n_embd at 4 B. - After the change the same run reserves 338.91 MiB instead of 970.00, and -dev CUDA1 -p 64 (a 2 GiB card, which always failed before) runs at 379.58 t/s. - llama-bench -dev CUDA0 -p 512 -n 32: pp512 13395 t/s, tg32 259.72 t/s (13392 / 258.18 before) -- no regression from the chunking. - test-llama-context --model Qwen3.5-0.8B-Q4_K_M.gguf (both GPUs, default KV): 14 OK / 0 FAIL / 1 SKIP (rot, by design), RC=0, three runs in a row; -dev CUDA0 the same; -dev CUDA0 -ctk f16 -ctv f16 gives 15/15. - replay alone passes with the default KV, f16, q8_0, q5_0, turbo4, turbo2_tcq and q4_0/f16 cache types. - Reverse control: making s_copy() ignore the pending rs_idx turns the case red again on both the default and the f16 configuration (nmse 8.8e-3 / 8.6e-3), so the new bound still catches the failure the case exists for. - ctest test-vbr-* and test-kv-cells pass; test-download-model fails for lack of network and test-thread-safety is skipped as its dependency, but the latter runs to RC=0 by hand.
auRose94
pushed a commit
to auRose94/llama.cpp
that referenced
this pull request
Oct 28, 2026
* ggml-cuda: chunk large BF16/FP16 to F32 conversions * Update ggml/src/ggml-cuda/ggml-cuda.cu Co-authored-by: Johannes Gäßler <johannesg@5d6.de> * Update ggml/src/ggml-cuda/ggml-cuda.cu Co-authored-by: Johannes Gäßler <johannesg@5d6.de> * ggml-cuda: respect dst stride in chunked cuBLAS matmul --------- Co-authored-by: Johannes Gäßler <johannesg@5d6.de>
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.
Overview
Follow #28846
Chuncking the BF16/FP16 to FP32 convertion for lowering VRAM usage.
Set chunck by 512MB after Heuristics tests.
Additional information
Test with BF16 to FP32 and FP16 to FP32 (useally when FA is set to OFF and context if growing)
MI50/gfx906:
pp512pp1024@LostRuins @eliah Can you test an tell me if it's ok for you ?
Requirements