Repository navigation
server: add option to output probabilities for completion - #1962
Conversation
server: add option to output probabilities for completion
server: fix comment about max n_probs
…ens for multibyte character generation
server: fix issue for multibyte character generation
server: fix some beginner mistakes
|
I have a question about partial UTF-8 character is generation: It seems like we are assuming that all partial character generation is 1 char long when converted to string. Is that true? I kinda used this assumption in tokens_to_output_formatted_string |
It seems to be 1 byte per token when I tested in practice and when I took a quick look at the tokenizer.json. But someone that knows more should check. |
|
@SlyEcho are there any other requested changes? Should we merge this? |
|
I'm taking a look now. I was occupied on the weekend by holidays and a certain bald Russian clown.
|
LOL What do you mean by
Are you saying there should be something is the server context like I feel like the current logic is the easiest. Under the assumption that |
|
I'm currently thinking what would be best way. It's also possible that other alternative tokens could come out as incomplete and should we keep generating until we have |
As in that we should continue generation for all |
server: remove n_probs upper limit of 5
Yeah, this is kind of a lot, we could keep the best 5 but it would mean a lot of token generating. Or to only keep the alternates from the last one. |
|
Not that we need to copy exactly openai's API. But here is an example of how they handle multibyte:
And I think we shouldn't just return probs of the last token either, as the probs of other partial chars are also useful information.
This would mean |
|
Ok, let's leave it like that for now and try to think how to improve in the future. |
…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]>
…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]>
…K kernels (engine ggml-org#1962) (#288) The Q6_K i8-prepacked and packed (aligned-skinny) kernels narrow their f32 activations to f16 for the multiply, so an activation above 65504 became inf and the result NaN. Narrow at 2^-6 and scale the f32 accumulator back by 2^6 before it is published, as the f32 matmul cores do: exact while the scaled value is a normal f16, window [3.9e-3, 4.19e6]. test_mul_mat_resident_weight_large_activation reaches these kernels with a resident weight and activations of 9.1e4 (NaN before, pass after) and with every activation at 2.4e-2 (the lower edge). The 512-token prefill kernels for Q4_K, Q5_K and Q6_K read activations a separate step has already narrowed, and are not changed here. Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Fable 5.2 <[email protected]>
…the f16 limit (engine ggml-org#1962) Review of #292: the comment now says why the rebuilt value cannot overflow and that inf and NaN are both rebuilt; a 6.5e4 case sits on the last ladder step where the stored sum is still finite, next to the 6.6e4 one where it is not. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ange (engine ggml-org#1962) (#292) * hrx: the Q5_K/IQ4_XS prefill rebuilds a block sum that left the f16 range (engine ggml-org#1962) The prefill kernel reads its activations as 8-bit blocks. Each block stores its scale and its scaled sum (scale times the sum of the 32 codes) as f16. The scale fits for activations up to 8.3e6, but the scaled sum is about as large as the largest activation in the block, so it became inf above 65504 and the offset correction of the K-quant weights turned the output into NaN. A stored sum that is not finite is now rebuilt in the reader from the codes the lane already holds; a finite one is used as stored, so ordinary data takes the path it always took and the block layout does not change. Cases: Q5_K, 512 tokens, resident weight, activations at 6.6e4, 9.1e4, 1e6 and the 2.4e-2 lower edge. Co-Authored-By: Claude Fable 5.2 <[email protected]> * hrx: state the rebuilt sum's range, and a case on the stored side of the f16 limit (engine ggml-org#1962) Review of #292: the comment now says why the rebuilt value cannot overflow and that inf and NaN are both rebuilt; a 6.5e4 case sits on the last ladder step where the stored sum is still finite, next to the 6.6e4 one where it is not. 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]>
…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]>
…written, and stays finite above the f16 range (engine ggml-org#1962) (#303) common.mul_mat.q6_k_token1_shortlist (a Q6_K projection onto a vocabulary of at least 65,536 at one token, downstream of the draft head's concat projection) had no test, and two defects: - The matcher asked for 96 selected activation groups at every width. The selection kernel writes one id per 32-wide group that exists and the scan reads as many ids as were asked for, so below a width of 3072 the tail of the id buffer was never written and was used as group indices: a device memory fault at width 256, 16 stray indices at 2560 (Qwen3.8-Flash-Next). The request is now min(96, input_size / 32). - The refine kernel narrowed the f32 activation to f16 unscaled and accumulated the logit in f16, so one activation above 65504 made every refined logit inf. The body now narrows at 2^-6 and the exported kernel scales the published logit back by 2^6. Tests: test-hrx-ops mul_mat.q6_k.token1_shortlist (ordinary data) and .large_activation (one activation above 65504, logits inside f16), comparing the refined candidates and the best token with the CPU; hrx-backend-test q6k_token1_shortlist_group_count.{256,2560,4096}, device-free. Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Fable 5.2 <[email protected]>
… small-batch token counts (engine ggml-org#1962) (#306) ffn.q4_k.prefill.large_activation ran at 256 and 512 tokens only. It now also runs at 1, 2, 4, 5, 8, 16, 64 and 128, where the decode and small-batch kernels take the gate/up and the down-projection. The case prints the kernels that ran. The fused prefill kernels are still required from 256 tokens up. Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Fable 5.2 <[email protected]>
…m that left the f16 range (engine ggml-org#2186) (#319) The 8-bit activation blocks store their scale and their scaled sum (scale times the sum of the 32 codes) as f16. The sum overflows once a block of same-signed activations averages above 2047, while the scale still fits. qwen3_moe_q4k_q8_1_dot, the one function every Q4_K reader of these blocks goes through, used the stored sum as is; it now rebuilds a non-finite sum from the 16 codes it already holds (the rule mul_mat_q5_k_q8_plane_wmma has had since engine ggml-org#1962). A finite stored sum is used unchanged. New device cases decode_routed_moe.q4_K.large_activation.{1,1000,3000,30000}. Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Fable 5.2 <[email protected]>
related to #1784
I was playing around with the server example and wanted to expose the probabilities of the generated tokens to the server client to implement custom stopping sequences and criteria(similar to openai's api here).
This PR returns the probabilities by reading it from
candidates_p.data[i].pafter sampling functions are called.