Repository navigation
Conversation
- run_inference.py: add --single-turn to avoid interactive loop / hang on EOF stdin (was SIGSEGV/hang). - src/ggml-bitnet-mad.cpp: duplicate dequantize_row_i2_s (referenced by ggml.c type-traits but defined only in ggml-cpu/quants.c, unreachable from ggml-base); guard last-block reads. - 3rdparty/llama.cpp: bump submodule to the ARM64 fix commit. Build + run_inference.py verified locally (model loads, generates, exits cleanly). Note: output quality on this ARM path still degenerates to a single token for the test prompts; the matmul kernel (ggml_vec_dot_i2_i8_s) may need further attention from maintainers. Filing as a follow-up.
Author
|
@microsoft-github-policy-service agree [company=""] |
Author
|
@microsoft-github-policy-service agree |
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.
Summary
This PR fixes the ARM64 (Apple Silicon) build and runtime of
bitnet.cppfor theofficial
BitNet-b1.58-2B-4Ti2_s model. Before this change,setup_env.py -q i2_sfailed to link on arm64 and, even after manual source fixes,
run_inference.pyhung (infinite loop) or SIGSEGV'd.
Changes
1. Build wiring (vendored llama.cpp submodule)
The vendored
ggml/src/CMakeLists.txtis a 10-line stub that never compilessrc/ggml-bitnet-mad.cpp, soquantize_i2_s/dequantize_row_i2_swereundefined on arm64.
3rdparty/llama.cpp/ggml/src/CMakeLists.txt:target_sources(ggml-base PRIVATE ../../../../src/ggml-bitnet-mad.cpp)+ include dirs.ggml-cpu/ggml-cpu.c: declaresrc1_contin the I2_S fast path (was referencedundeclared at line ~1495).
ggml-cpu/quants.c: guarddequantize_row_i2_sagainst reading past the packeddata on the final partial block.
ggml-cpu/ggml-cpu.c: fix activation pointer addressingi11 * nb11(wasi11 * nb11 / 4). Activations are i8 (1 byte), not 4-per-byte packed; the/4caused out-of-bounds reads and degenerate output. This was the root cause of
the SIGSEGV.
src/ggml-bitnet-mad.cpp: duplicatedequantize_row_i2_s(referenced byggml.c's type-traits table but defined only in ggml-cpu/quants.c, unreachable
from ggml-base); guard last-block reads.
Submodule commit:
hari2353/llama.cpp@8d3a7d4(branchbitnet-arm64-i2s-fix).2. Runtime (run_inference.py)
--single-turnso llama-cli exits after generating instead of entering theinteractive loop (which spun forever / crashed on EOF stdin).
Verification (local, Apple M5 Pro, arm64)
cmake --build buildsucceeds.run_inference.py -m ...ggml-model-i2_s.gguf -p "The capital of France is" -n 8now loads, generates, and exits cleanly (no hang, no SIGSEGV). Previously:
SIGSEGV(11) / infinite loop.
Known limitation (not fixed by this PR)
Output is still degenerate (repeated
@tokens) for the test prompts. The matmulkernel
ggml_vec_dot_i2_i8_s(scalar fallback on ARM) and/or the activationscale convention may need further attention from maintainers; the
/4fix aboveremoved the crash but the kernel's numerical result is still wrong. I'm happy to
iterate with guidance on the expected i2_s layout on ARM.
Test plan
setup_env.py -md models/BitNet-b1.58-2B-4T -q i2_scompletes on arm64.run_inference.pyruns to completion without crash/hang.