Repository navigation
feat: Inkling-2 followups for 32217 - #32268
Draft
danielhanchen wants to merge 1 commit into
Draft
danielhanchen wants to merge 1 commit into
danielhanchen wants to merge 1 commit into
Conversation
danielhanchen
force-pushed
the
inkling2-followups
branch
from
November 14, 2026 13:54
716ad2e to
da5532a
Compare
Member
Make this a separate PR please (well, to be honest, all of them should probably be). |
danielhanchen
force-pushed
the
inkling2-followups
branch
from
November 14, 2026 15:55
da5532a to
ac469d4
Compare
- inkling2: apply per-expert gate_up / down scales when present (NVFP4 expert files) - inkling2: apply the embedding norm to token embeddings only, not image embeddings - inkling2: opt out of mixed token + embedding batches and -sm tensor, as Inkling 1 does - mtmd: put each image in its own <|content_image|> block - mtmd: reproduce the reference bf16 patch preprocessing (test-mtmd-impl updated) - chat: Inkling 2 template and parser (thinking, text, tool calls, parallel calls, turns without the opening header); Inkling 1 templates are not routed to it - jinja: support tojson(sort_keys=True)
danielhanchen
force-pushed
the
inkling2-followups
branch
from
November 14, 2026 16:03
ac469d4 to
7260752
Compare
ngxson
reviewed
Nov 14, 2026
Comment on lines
+2194
to
+2207
| // the reference CLIP-normalises to bf16, then the encoder maps back to [-1, 1] in bf16; a single affine step cannot match it | ||
| constexpr float proc_mean[3] = { 0.48145466f, 0.4578275f, 0.40821073f }; | ||
| constexpr float proc_std[3] = { 0.26862954f, 0.2613026f, 0.2757771f }; | ||
| constexpr float enc_mean[3] = { 0.48145466f, 0.4578275f, 0.40821073f }; | ||
| constexpr float enc_std[3] = { 0.26862954f, 0.26130258f, 0.27577711f }; | ||
| const auto bf16_round = [](float v) { return ggml_bf16_to_fp32(ggml_fp32_to_bf16(v)); }; | ||
| for (int c = 0; c < 3; ++c) { | ||
| mean[c] = hparams.image_mean[c] * 255.0f; | ||
| std[c] = hparams.image_std[c] * 255.0f; | ||
| const float m = bf16_round(enc_mean[c]), sd = bf16_round(enc_std[c]); | ||
| for (size_t i = c; i < pixels.size(); i += 3) { | ||
| const float x = bf16_round((pixels[i] / 255.0f - proc_mean[c]) / proc_std[c]); | ||
| pixels[i] = bf16_round(2.0f * (x * sd + m) - 1.0f); | ||
| } | ||
| } | ||
| padded.normalize(mean, std); | ||
| padded.cpy_buf(pixels); |
Collaborator
There was a problem hiding this comment.
I have my agent reviewed this and confirmed that this is wrong, please revert changes here
Reasons:
- It is the identity in exact arithmetic. The two steps undo each other, so the output equals
(v - 127.5) / 127.5plus rounding error and nothing else. - Size of the error: up to 1.07 gray levels per pixel (0.67 and 0.51 on the other two channels). In the blue channel two of the 256 pixel values map to the same output. A single bf16 cast of the plain formula would be at most 0.25 levels. I computed this in numpy with round-to-nearest-even, like
ggml_fp32_to_bf16. - Constants: the CLIP mean/std are hardcoded in the preprocessor and the
image_mean/image_stdfrom the GGUF are ignored. Those CLIP values are in Inkling 1'sprocessor_config.json; Inkling 2's has 0.5/0.5. - Transformers does not do this.
Inkling2ImageProcessor._preprocessdoes one float32rescale_and_normalizewith the config mean/std, andInkling2VisionEmbeddings.forwardapplies the patch embedding straight topixel_valueswith no un-normalize step. - The PR does not name its reference. The description only says "the reference bf16 patch preprocessing".
- Its own test admits the drift. The updated
test_image_preprocessor_inkling2adds a tolerance of 1/64 against the exact value, which is about 2 gray levels.
ngxson
reviewed
Nov 14, 2026
Comment on lines
+57
to
+66
| // mapped back to [-1, 1] in bf16 as the reference encoder does, so (v - 127.5) / 127.5 up to bf16 rounding | ||
| static float inkling2_pixel(float v, int c) { | ||
| static const float proc_mean[3] = { 0.48145466f, 0.4578275f, 0.40821073f }; | ||
| static const float proc_std[3] = { 0.26862954f, 0.2613026f, 0.2757771f }; | ||
| static const float enc_mean[3] = { 0.48145466f, 0.4578275f, 0.40821073f }; | ||
| static const float enc_std[3] = { 0.26862954f, 0.26130258f, 0.27577711f }; | ||
| const auto bf16 = [](float f) { return ggml_bf16_to_fp32(ggml_fp32_to_bf16(f)); }; | ||
| const float x = bf16((v / 255.0f - proc_mean[c]) / proc_std[c]); | ||
| return bf16(2.0f * (x * bf16(enc_std[c]) + bf16(enc_mean[c])) - 1.0f); | ||
| } |
jesdga95
added a commit
to jesdga95/basalt
that referenced
this pull request
Nov 22, 2026
…ised and rounded to bf16, then mapped to [-1, 1] and rounded again; one affine step from the byte left the rows 1.2 to 2.4% (rel L2) from that form - The class-token tower's patch rows (CUDA patch_rows_k and the CPU patchify_padded, which only the Inkling 2 encoder uses) take the processor's CLIP mean and std and the encoder's own, with ggml-org/llama.cpp#32268's two roundings; the device's multiply-adds are not contracted, so its rows equal the host's bit for bit (cls_encoder_parity). - The rows of five pictures against the one-step rows: 57x23 1.2e-2, 640x480 1.9e-2, 512x512 with alpha 1.5e-2, 1280x720 2.4e-2, 4096x4096 2.2e-2 (lowest row cosine 0.990). CUDA against the CPU encoder stays as before (out 5.3e-3 to 1.1e-2, inkling2_vision_parity --cpu). - transformers' Inkling2ImageProcessor (5.24) normalises once in fp32; the release's own pipeline, which llama.cpp matched to 6.8e-4, rounds twice.
FahadAlAlawi
pushed a commit
to FahadAlAlawi/basalt-RTX40
that referenced
this pull request
Nov 25, 2026
…ised and rounded to bf16, then mapped to [-1, 1] and rounded again; one affine step from the byte left the rows 1.2 to 2.4% (rel L2) from that form - The class-token tower's patch rows (CUDA patch_rows_k and the CPU patchify_padded, which only the Inkling 2 encoder uses) take the processor's CLIP mean and std and the encoder's own, with ggml-org/llama.cpp#32268's two roundings; the device's multiply-adds are not contracted, so its rows equal the host's bit for bit (cls_encoder_parity). - The rows of five pictures against the one-step rows: 57x23 1.2e-2, 640x480 1.9e-2, 512x512 with alpha 1.5e-2, 1280x720 2.4e-2, 4096x4096 2.2e-2 (lowest row cosine 0.990). CUDA against the CPU encoder stays as before (out 5.3e-3 to 1.1e-2, inkling2_vision_parity --cpu). - transformers' Inkling2ImageProcessor (5.24) normalises once in fp32; the release's own pipeline, which llama.cpp matched to 6.8e-4, rounds twice.
This branch has not been deployed
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-ups for Inkling 2 on top of #32217:
gate_up/downexperts. NVFP4 expert GGUFs need these: they keepffn_gate_up_exps.scale/ffn_down_exps.scalebecause the scale is too small to fold into the FP8 block scales. Without this they are refused at load, andffn_down_exps.scalewas loaded but never applied.-sm tensor, as Inkling 1 does (mixed-batch NMSE 0.35;-sm tensorasserted at split setup)<|content_image|>block, as the template renders ittest_image_preprocessor_inkling2updated to match<|message_model|>NAME<|content_invoke_tool_json|>{...}), parallel calls, turns without the opening<|message_model|>read as text (was HTTP 500), no<|end_message|>leak. Inkling 1 templates (with<|content_audio_input|>) are not routed to ittojson(sort_keys=True), used by the official template (rendering failed with HTTP 400)Additional information
Tested: CPU and CUDA builds; test-backend-ops, test-chat, test-mtmd-impl and test-llama-archs -a inkling2 pass. test-chat / test-jinja pass with Inkling 2 cases (not included here to keep the diff small). GGUFs from IQ1_S to BF16 converted to this layout give the same KLD as before, and the vision caption is correct.
Requirements