[GH-ISSUE #327] tools/mtp_fetch.py silently saves wrong data when a mirror ignores the Range header - MTP acceptance stays 0 with no visible error #154

Closed
opened 2026-11-04 01:40:31 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @lifeidle on GitHub (Oct 1, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/327

Summary

On first setup, MTP acceptance was 0 in every configuration — drafts accepted 0 of 0 on defaults, and 0 of 765 with spec_min_p=0 (windows forced open). The engine loaded fine and chat worked; only speculation was dead, with no visible error anywhere.

Root cause: 20 of 31 fetched mtp.* tensor files did not contain tensors at all — they contained the beginning of their safetensors shard (JSON header + unrelated data). The mirror ignored the HTTP Range header and returned 200 with the whole file; tools/mtp_fetch.py kept the first n_bytes, which is exactly the shard's header region.

Why it was invisible

Two checks that look sufficient are not:

  1. Size check: the saved blob's size equals the requested range exactly (a proxy truncated the 200 response to the requested length) — so a length assertion passes
  2. sha256 in the manifest: it hashes the bytes that were downloaded, so it also passes. It cannot detect "you downloaded the wrong bytes"

The failure mode is fully silent: the engine loads the weights, decodes fine (they are garbage but bounded), and only the drafter collapses — dprob=NaN, draft tokens pinned at 0, and the window logic keeps T=1 so most users just see "MTP doesn't help".

How it was found

  • Read the engine source: the second zero in drafts accepted 0 of 0 is the offered count → T was always 1, the drafter was never given a chance (earlier reading: "all drafts rejected" — wrong)
  • Forced windows open (spec_min_p=0): drafts accepted 0 of 765 — proposals exist and are 100% wrong
  • Self-compiled the engine with a probe after the draft round: dprob=NaN, draft ids pinned at 0 → NaN enters at the first fc_embedding matmul
  • Per-tensor inspection of the drafter weights: f32 norm weights at ~2.1e37 magnitude from tensor #11 on, q8_0 scales = inf
  • The bad raw files literally start with {"__metadata__"... — the shard's own safetensors header
BEFORE (corrupted fetch)                            AFTER (re-fetched)
mlp.gate.weight                 bf16 maxabs=2.1e+37     bf16 maxabs=1.547
mlp_hyper_connection.hc_norm    f32  mean=inf           f32  mean=2.731
self_attn.q_proj.weight         q8_0 scale_inf=57       q8_0 scale_inf=0
pre_fc_norm_embedding.weight    f32  maxabs=2.1e+37     f32  maxabs=0.7246

Full data: https://github.com/lifeidle/qwen3.8-flash-next-5090-laptop-256k/blob/main/docs/mtp-corruption-postmortem.md

Result after re-fetching the 20 files (~110 MB; the two 5 GB expert tensors were fine)

speculation  128 rounds, drafts accepted 0 of 381 (0.000)  ->  62 of 195 (0.318), 1.94 tokens/round
decode       42.7 tok/s                                    ->  69.9 tok/s  (+64%, same forced-window protocol)

serve (spec_min_p tuned per model):
  Q2_0 full:       93.5 tok/s, acceptance 44-54%
  IQ3_XXS full:    77.4 tok/s, acceptance 59-71%

Suggested fix in tools/mtp_fetch.py

When a Range was requested, verify the response is actually partial:

with urllib.request.urlopen(req, timeout=120) as r:
    if r.status != 206:
        raise IOError(f"range request not honored: HTTP {r.status} (mirror ignored Range?)")
    data = r.read()

and optionally assert the saved blob does not begin with a safetensors header ([u64 len][b'{"']). One more layer: since the shard headers are already downloaded by inventory, a spot check that the first bytes are not {" would have caught this immediately.

Environment

  • Windows 11, RTX 5090 Laptop 24 GB + 64 GB RAM, engine 0.1.27 → 0.1.28
  • Models: Q2_0, IQ3_XXS, Coder IQ1_M (all affected — they share the drafter weights)
  • Fetch source: an HF mirror (the default huggingface.co was proxied); mirrors/proxies are exactly where Range headers get dropped, so this is not an exotic path
Originally created by @lifeidle on GitHub (Oct 1, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/327 ## Summary On first setup, MTP acceptance was **0 in every configuration** — `drafts accepted 0 of 0` on defaults, and `0 of 765` with `spec_min_p=0` (windows forced open). The engine loaded fine and chat worked; only speculation was dead, with no visible error anywhere. **Root cause: 20 of 31 fetched `mtp.*` tensor files did not contain tensors at all — they contained the beginning of their safetensors shard (JSON header + unrelated data).** The mirror ignored the HTTP Range header and returned `200` with the whole file; `tools/mtp_fetch.py` kept the first `n_bytes`, which is exactly the shard's header region. ## Why it was invisible Two checks that look sufficient are not: 1. **Size check**: the saved blob's size equals the requested range exactly (a proxy truncated the 200 response to the requested length) — so a length assertion passes 2. **sha256 in the manifest**: it hashes *the bytes that were downloaded*, so it also passes. It cannot detect "you downloaded the wrong bytes" The failure mode is fully silent: the engine loads the weights, decodes fine (they are garbage but bounded), and only the drafter collapses — `dprob=NaN`, draft tokens pinned at 0, and the window logic keeps `T=1` so most users just see "MTP doesn't help". ## How it was found - Read the engine source: the second zero in `drafts accepted 0 of 0` is the **offered** count → `T` was always 1, the drafter was never given a chance (earlier reading: "all drafts rejected" — wrong) - Forced windows open (`spec_min_p=0`): `drafts accepted 0 of 765` — proposals exist and are 100% wrong - Self-compiled the engine with a probe after the draft round: `dprob=NaN`, draft ids pinned at 0 → NaN enters at the first `fc_embedding` matmul - Per-tensor inspection of the drafter weights: `f32` norm weights at ~2.1e37 magnitude from tensor #11 on, `q8_0` scales = inf - The bad raw files literally start with `{"__metadata__"...` — the shard's own safetensors header ``` BEFORE (corrupted fetch) AFTER (re-fetched) mlp.gate.weight bf16 maxabs=2.1e+37 bf16 maxabs=1.547 mlp_hyper_connection.hc_norm f32 mean=inf f32 mean=2.731 self_attn.q_proj.weight q8_0 scale_inf=57 q8_0 scale_inf=0 pre_fc_norm_embedding.weight f32 maxabs=2.1e+37 f32 maxabs=0.7246 ``` Full data: https://github.com/lifeidle/qwen3.8-flash-next-5090-laptop-256k/blob/main/docs/mtp-corruption-postmortem.md ## Result after re-fetching the 20 files (~110 MB; the two 5 GB expert tensors were fine) ``` speculation 128 rounds, drafts accepted 0 of 381 (0.000) -> 62 of 195 (0.318), 1.94 tokens/round decode 42.7 tok/s -> 69.9 tok/s (+64%, same forced-window protocol) serve (spec_min_p tuned per model): Q2_0 full: 93.5 tok/s, acceptance 44-54% IQ3_XXS full: 77.4 tok/s, acceptance 59-71% ``` ## Suggested fix in `tools/mtp_fetch.py` When a Range was requested, verify the response is actually partial: ```python with urllib.request.urlopen(req, timeout=120) as r: if r.status != 206: raise IOError(f"range request not honored: HTTP {r.status} (mirror ignored Range?)") data = r.read() ``` and optionally assert the saved blob does not begin with a safetensors header (`[u64 len][b'{"']`). One more layer: since the shard headers are already downloaded by `inventory`, a spot check that the first bytes are not `{"` would have caught this immediately. ## Environment - Windows 11, RTX 5090 Laptop 24 GB + 64 GB RAM, engine 0.1.27 → 0.1.28 - Models: Q2_0, IQ3_XXS, Coder IQ1_M (all affected — they share the drafter weights) - Fetch source: an HF mirror (the default `huggingface.co` was proxied); mirrors/proxies are exactly where Range headers get dropped, so this is not an exotic path
Author
Owner

@Niko1221 commented on GitHub (Oct 1, 2026):

Confirmed. 0.1.32: mtp_fetch requires HTTP 206 with a matching Content-Range, re-reads an inventory from another repository, and checks per-tensor sha256 for the pinned revision so a corrupt install is detected and fetched again.

<!-- gh-comment-id:5925967682 --> @Niko1221 commented on GitHub (Oct 1, 2026): Confirmed. 0.1.32: mtp_fetch requires HTTP 206 with a matching Content-Range, re-reads an inventory from another repository, and checks per-tensor sha256 for the pinned revision so a corrupt install is detected and fetched again.
Author
Owner

@Niko1221 commented on GitHub (Oct 1, 2026):

Fixed in 0.1.32: HTTP 206 + Content-Range required, per-tensor SHA-256 checked (a corrupt tensor is fetched again), another repository's inventory is re-read. Thanks!

<!-- gh-comment-id:5936872271 --> @Niko1221 commented on GitHub (Oct 1, 2026): Fixed in [0.1.32](https://github.com/Niko1221/Strata/releases/tag/v0.1.32): HTTP 206 + Content-Range required, per-tensor SHA-256 checked (a corrupt tensor is fetched again), another repository's inventory is re-read. Thanks!
Author
Owner

@lifeidle commented on GitHub (Oct 2, 2026):

Wonderful — thanks for the lightning-fast fix! Verified that both checks we suggested (206 + Content-Range enforcement, and per-tensor hashes against a trusted reference) made it into v0.1.32, plus the cross-repo inventory re-read is a nice extra layer we hadn't thought of.

One note for anyone reading this thread: our postmortem with the full investigation trail and the corruption-detection/repair scripts is here — lifeidle/qwen3.8-flash-next-strata-5090-laptop-24gb. We'll upgrade to v0.1.32 and confirm.

<!-- gh-comment-id:5944569105 --> @lifeidle commented on GitHub (Oct 2, 2026): Wonderful — thanks for the lightning-fast fix! Verified that both checks we suggested (206 + Content-Range enforcement, and per-tensor hashes against a trusted reference) made it into v0.1.32, plus the cross-repo inventory re-read is a nice extra layer we hadn't thought of. One note for anyone reading this thread: our postmortem with the full investigation trail and the corruption-detection/repair scripts is here — [lifeidle/qwen3.8-flash-next-strata-5090-laptop-24gb](https://github.com/lifeidle/qwen3.8-flash-next-strata-5090-laptop-24gb/blob/main/docs/mtp-corruption-postmortem.md). We'll upgrade to v0.1.32 and confirm.
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#154
No description provided.