[PR #290] [CLOSED] Token embedding in BF16 from the checkpoint (--embd-gguf) #2556

Closed
opened 2026-11-04 02:01:17 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/290
Author: @sergqwer
Created: 9/30/2026
Status: ❌ Closed

Base: main ← Head: pr/embd-bf16


📝 Commits (1)

  • 379908d Token embedding in BF16 from the checkpoint (--embd-gguf)

📊 Changes

5 files changed (+110 additions, -6 deletions)

View changed files

📝 include/strata/kernels/iq_kernels.hpp (+2 -0)
📝 src/core/native_head.cpp (+1 -1)
📝 src/kernels/cuda/iq_kernels.cu (+12 -2)
📝 src/program/generate.cpp (+8 -3)
➕ tools/embd_bf16_pack.py (+87 -0)

📄 Description

Summary

The native path reads the token embedding from the model GGUF, where it is quantized (IQ4_XS in ISTA-DASLab's
IQ2_XS). The checkpoint ships it in BF16.

  • tools/embd_bf16_pack.py copies embed_tokens into a one-tensor GGUF, bytes unchanged. Only the safetensors shard
    that holds it is needed: 3 GB for Qwen/Qwen3.8-Flash-Next (model-00130-of-00131.safetensors).
  • --embd-gguf PATH makes the native embedding read token_embd from that file. iq_embed_rows and
    iq_dequant_f32 decode BF16 (embed_type_supported).
  • The table stays in mapped host memory, as before: 1.2 GiB instead of 0.3, and no VRAM.

Measured

Measured on current main (0.1.29, d6708a4) with ISTA-DASLab's IQ2_XS, RTX 5090 32 GB, Ryzen 9 9950X3D, 128 GB DDR5, Windows 11. KL is first-token KL divergence (STRATA_DUMP_FIRST_LOGITS, #276); two runs of main itself differ by 0 on 5 of 6 short prompts and by 0.00013 on the sixth.

First-token KL of the GGUF's IQ4_XS embedding against the BF16 one: 0.0015 (1K), 0.0089 (2K; the top token changes), 0.0010 (4K), 0.037 (32K); mean 0.012, ~100x the run-to-run noise. On the NVFP4 fork, whose GGUF embedding is Q8_0, the same comparison gave 0.0025. Decode and prompt speed are unchanged (fork); the start takes ~0.2 s more.

Switch

Off unless --embd-gguf is given.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/290 **Author:** [@sergqwer](https://github.com/sergqwer) **Created:** 9/30/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/embd-bf16` --- ### 📝 Commits (1) - [`379908d`](https://github.com/Niko1221/Strata/commit/379908da150917cdc411747169e5ad5c5b969e31) Token embedding in BF16 from the checkpoint (--embd-gguf) ### 📊 Changes **5 files changed** (+110 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/kernels/iq_kernels.hpp` (+2 -0) 📝 `src/core/native_head.cpp` (+1 -1) 📝 `src/kernels/cuda/iq_kernels.cu` (+12 -2) 📝 `src/program/generate.cpp` (+8 -3) ➕ `tools/embd_bf16_pack.py` (+87 -0) </details> ### 📄 Description ## Summary The native path reads the token embedding from the model GGUF, where it is quantized (IQ4_XS in ISTA-DASLab's IQ2_XS). The checkpoint ships it in BF16. - `tools/embd_bf16_pack.py` copies `embed_tokens` into a one-tensor GGUF, bytes unchanged. Only the safetensors shard that holds it is needed: 3 GB for `Qwen/Qwen3.8-Flash-Next` (`model-00130-of-00131.safetensors`). - `--embd-gguf PATH` makes the native embedding read `token_embd` from that file. `iq_embed_rows` and `iq_dequant_f32` decode BF16 (`embed_type_supported`). - The table stays in mapped host memory, as before: 1.2 GiB instead of 0.3, and no VRAM. ## Measured Measured on current main (0.1.29, d6708a4) with ISTA-DASLab's IQ2_XS, RTX 5090 32 GB, Ryzen 9 9950X3D, 128 GB DDR5, Windows 11. KL is first-token KL divergence (`STRATA_DUMP_FIRST_LOGITS`, #276); two runs of main itself differ by 0 on 5 of 6 short prompts and by 0.00013 on the sixth. First-token KL of the GGUF's IQ4_XS embedding against the BF16 one: 0.0015 (1K), 0.0089 (2K; the top token changes), 0.0010 (4K), 0.037 (32K); mean 0.012, ~100x the run-to-run noise. On the NVFP4 fork, whose GGUF embedding is Q8_0, the same comparison gave 0.0025. Decode and prompt speed are unchanged (fork); the start takes ~0.2 s more. ## Switch Off unless `--embd-gguf` is given. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:01:17 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2556
No description provided.