[Bug]: I2_S GEMM fast path produces garbage for multi-token prompts on AVX-only CPUs
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 68/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- cmake, cpp
- Bereich
- machine-learning, performance
Rechercherichtung
Beginnen Sie in ggml-cpu.c beim schnellen I2_S-GEMM-Pfad um Zeile 1492 und untersuchen Sie ggml_gemm_i2_i8_s auf die Behandlung des Spalten-Strides, wenn nr e 1. Bauen Sie mit deaktiviertem AVX2 unter Verwendung der dokumentierten CMake flags und reproduzieren Sie das Problem mit kurzen und längeren Prompts. Vergleichen Sie den GEMM-Pfad mit dem funktionierenden GEMV-Pfad um Zeile 1217. Als abgeschlossen gilt die Aufgabe, wenn Multi-Token-I2_S-Prompts auf AVX-only-CPUs eine konsistente Ausgabe erzeugen, ohne den schnellen Pfad zu deaktivieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
On CPUs without AVX2 (e.g., Intel Xeon E5-2690 v2, Ivy Bridge, AVX-only), the I2_S GEMM fast path in ggml-cpu.c:1492 produces corrupt output when processing prompts with more than ~3 tokens. Single-token generation (GEMV path) works correctly.
Symptoms
- 1-3 token prompts → coherent output
- 5+ token prompts →
??????or garbled output - The corruption affects the KV cache: even after the prompt is processed, subsequent generation tokens are garbled
Root Cause
The GEMM fast path (ggml_gemm_i2_i8_s) is called for multi-token prompt evaluation (when src1 has multiple columns). The scalar fallback implementation has a bug in how it indexes the I2_S weight matrix and/or activation matrix for column strides > 1.
Workaround
Disabling the GEMM fast path forces I2_S through the dequantize-then-float-matmul path:
// ggml-cpu.c:1492 — change from:
if (src0->type == GGML_TYPE_I2_S && ggml_n_dims(src0) == 2) {
// to:
if (false && src0->type == GGML_TYPE_I2_S && ggml_n_dims(src0) == 2) {
This produces correct results but is slower (~0.6 tok/s prompt eval vs ~26 tok/s for F16 on the same hardware).
Key Distinction from #547
This is distinct from #547/PR #580 which covers the empty-body scalar fallback for ggml_vec_dot_i2_i8_s_* kernels. After applying those fixes (or equivalent scalar implementations), the GEMM path still produces wrong results for multi-token prompts.
The GEMV path (line ~1217) works correctly for single-token generation. The issue is specifically in ggml_gemm_i2_i8_s when called with nr > 1 (multiple activation columns).
Reproduction
# Build with AVX2 disabled (forces scalar fallback)
cmake -B build -DBITNET_ARM_TL1=OFF -DBITNET_X86_TL2=OFF
cmake --build build --target llama-server -j8
# Short prompt works
curl http://localhost:8081/v1/completions \
-d '{"model":"bitnet","prompt":"Hello","max_tokens":20}'
# → " there! I'm happy to help" ✓
# Longer prompt fails
curl http://localhost:8081/v1/completions \
-d '{"model":"bitnet","prompt":"The weather today is","max_tokens":20}'
# → "?????" ✗
Also requires fixes #588 (ReLU²) and PR #616 (weight scale direction) for coherent F16 output.
Environment
- CPU: Intel Xeon E5-2690 v2 (Ivy Bridge, AVX only, no AVX2)
- OS: Ubuntu 24.04 LTS
- Compiler: Clang 18.1.3
- CMake flags:
-DBITNET_ARM_TL1=OFF -DBITNET_X86_TL2=OFF - Model: BitNet-b1.58-2B-4T (I2_S format)
- BitNet commit: 390c30775
- Vorherrschende Sprache
- C++
- Sterne
- 40.3k
- Forks
- 3.7k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus microsoft/BitNet
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
-
i2_s SIGSEGVs at n_ubatch >= 32: BLAS backend dequantises by a row stride 4x the real packed rowOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Alle Issues in microsoft/BitNet
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
tesseract-ocr/tesseract#4627 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
lxqt/lxqt-panel#2492 ·
-
bug-unconfirmed
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
[models/demos/gemma4 dFlash]: _shard_argmax returns a view of a force-freed tensor when rows == 1Offencommunity
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
tenstorrent/tt-metal#57989 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100