Repository navigation
ggml : add ggml_clamp() - #1539
Merged
Merged
Conversation
Seunghhon
pushed a commit
to Seunghhon/llama.cpp
that referenced
this pull request
Apr 26, 2026
* ggml : add ggml_clamp() * ggml : indentation
phuongncn
pushed a commit
to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4
that referenced
this pull request
Apr 28, 2026
* ggml : add ggml_clamp() * ggml : indentation
phuongncn
pushed a commit
to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4
that referenced
this pull request
Apr 28, 2026
ljubomirj
pushed a commit
to ljubomirj/llama.cpp
that referenced
this pull request
May 6, 2026
* ggml : add ggml_clamp() * ggml : indentation
AlexiAlp
pushed a commit
to minghaop/llama.cpp
that referenced
this pull request
Jun 2, 2026
* ggml : add ggml_clamp() * ggml : indentation
AlexiAlp
pushed a commit
to minghaop/llama.cpp
that referenced
this pull request
Jun 2, 2026
* ggml : add ggml_clamp() * ggml : indentation
This was referenced Nov 10, 2026
bong-water-water-bong
pushed a commit
to 1bit-MONSTER/llama.cpp
that referenced
this pull request
Nov 10, 2026
…re (engine ggml-org#1962) The dense form of engine ggml-org#1539. The f32-activation matmul core narrows its activations to f16 for the multiply; a value above 65504 became inf and the product NaN (or, without a NaN, a wrong number nothing reports). Narrow at 2^-6 and scale the f32 accumulator back by 2^6 on publish, as the routed core now does: exact while the scaled value is a normal f16, window [3.9e-3, 4.19e6]. test-backend-ops gains MUL_MAT cases with activations of 9.1e4 (the magnitude measured in flint-40b) for the 47 weight-type / token-count combinations this backend now answers correctly. Nine combinations still overflow in other kernel families and are listed on the issue rather than in the suite. Co-Authored-By: Claude Fable 5.2 <[email protected]>
bong-water-water-bong
added a commit
to 1bit-MONSTER/llama.cpp
that referenced
this pull request
Nov 10, 2026
…re (engine ggml-org#1962; stacked on #284) (#285) * hrx: keep routed-expert activations inside the f16 range, so a large SwiGLU output is not inf (engine ggml-org#1539) The routed-expert matmul narrows its f32 activations to f16 for the multiply, and f16 ends at 65504. An expert's down-projection reads the SwiGLU output, which nothing normalises: flint-40b's layer 46 reaches +-9.1e4 on an ordinary 22-token prompt. The narrowing made that inf, the sum over the routes inf - inf = NaN, and the NaN was stored as those tokens' keys and values, where the next shorter request on the slot found it inside its masked attention window and returned all-NaN logits. The activations are now narrowed at 2^-6 of their value and the f32 accumulator is scaled back by 2^6 when a tile is published. Both factors are powers of two, so a value whose scaled form is a normal f16 is rounded exactly as before; the representable window moves from [6.1e-5, 6.55e4] to [3.9e-3, 4.19e6]. test-backend-ops gains MUL_MAT_ID cases at flint's contraction with activations of the measured magnitude: the 22-token one returned NaN against the CPU's 56214.23 before this change. Co-Authored-By: Claude Fable 5.2 <[email protected]> * tests: pin the lower edge of the routed-matmul f16 window too (review of #284) The prescale trades the top of the f16 range for the bottom, and the large case only pulls one way. Add the same contraction with every activation scaled to 3.2e-2, the smallest column maximum measured on flint's expert down-projections (37278 columns over 141 layer executions; median 4.1, maximum 91161). Co-Authored-By: Claude Fable 5.2 <[email protected]> * hrx: keep dense matmul activations inside the f16 range in the f32 core (engine ggml-org#1962) The dense form of engine ggml-org#1539. The f32-activation matmul core narrows its activations to f16 for the multiply; a value above 65504 became inf and the product NaN (or, without a NaN, a wrong number nothing reports). Narrow at 2^-6 and scale the f32 accumulator back by 2^6 on publish, as the routed core now does: exact while the scaled value is a normal f16, window [3.9e-3, 4.19e6]. test-backend-ops gains MUL_MAT cases with activations of 9.1e4 (the magnitude measured in flint-40b) for the 47 weight-type / token-count combinations this backend now answers correctly. Nine combinations still overflow in other kernel families and are listed on the issue rather than in the suite. Co-Authored-By: Claude Fable 5.2 <[email protected]> * tests: pin the lower edge of the dense f16 window too (review of #285) Every activation at 2.4e-2, the smallest column maximum measured on the dense matmul inputs of Qwen3-0.6B, Qwen3-4B, ZAYA1-8B and flint-40b, for q4_K, q8_0 and bf16 weights at the 22-token batch. Co-Authored-By: Claude Fable 5.2 <[email protected]> --------- Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Fable 5.2 <[email protected]>
bong-water-water-bong
added a commit
to 1bit-MONSTER/llama.cpp
that referenced
this pull request
Nov 11, 2026
…n activation above 65504 stays finite (engine ggml-org#1962) (#298) The Q4_K and Q6_K prefill kernels (128 tokens and up) multiply an f16 copy of the activation. The copy was a plain f32 -> f16 narrowing, so an activation above the f16 maximum became inf and the product NaN. - The copies the dispatch makes (ggml_copy_f32_f16, ggml_copy_f16_k16_major from f32) store value * 2^-6. - The fused SwiGLU prefill kernel publishes the f16 form of its result at 2^-6 too. That result is the down-projection's activation, the place where a model leaves the range (engine ggml-org#1539). - The scale is recorded with the alternate value / generated resource (scale_log2). A reader that does not ask for a scale only finds unscaled values, so no other kernel reads a scaled copy by accident. - The prefill body and the Q6_K narrow-tile body scale their f32 sums back by 2^6 (exact) when the dispatch passes ggml.f16_prefill.activation_scale_log2 = 6. An unscaled F16 value from another producer is read as before. - The Q6_K narrow-tile body also prescales its own f32 narrowing. Tests: test-backend-ops resident-weight cases for Q4_K at 256/512 tokens and Q6_K at 128/256/512 with 9.1e4 and 2.4e-2 activations; test-hrx-ops ffn.q4_k.prefill.large_activation.{256,512} runs down(swiglu(gate, up)) through the fused kernels with a gated maximum of 4.0e5; hrx-backend-test plan rows look the f16 copy up under its scale; the test-hrx-ops plan helper prints the plan status when a metadata append is refused. Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Fable 5.2 <[email protected]>
bong-water-water-bong
pushed a commit
to 1bit-MONSTER/llama.cpp
that referenced
this pull request
Nov 13, 2026
AMD's file binds common.mul_mat_id.f32_f32_wmma to AMD's tiled/skinny pair kernels, which do not keep activations inside the f16 range (ggml-org#1539/ggml-org#2167): on the device, MUL_MAT_ID f32/bf16 at activation_scale 1e4/1e5 and a q5_K magnitude row return inf with it and pass with ours (test-backend-ops -b HRX0, gpu-kernels add-on b0ed206). AMD's file also dropped our common.mul_mat_id_postops.completion_counters registration. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
sync from ggml repo
Used in replit / MPT inference