microsoft / microsoft/BitNet

bitnet-b1.58-2B-4T runs FFN with SiLU instead of relu2 - wrong logits on every backend

Open
#602 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
40.3k
Forks
3.7k
PR merge metrics
No merged PRs in 30d

Description

bitnet-b1.58-2B-4T runs the FFN with SiLU instead of relu² — wrong logits on every backend

Summary

The official microsoft/bitnet-b1.58-2B-4T model declares "hidden_act": "relu2" in its config.json, but the BitNet.cpp runtime never reads it: the FFN graph is built with a hardcoded LLM_FFN_SILU. The model therefore runs with the wrong activation function on every backend (CPU and GPU), producing wrong-but-finite output — the same failure class as #586.

Root cause

  • src/models/bitnet.cpp:133build_ffn(...) is called with a hardcoded LLM_FFN_SILU.
  • src/llama-model.cpp — the LLM_FFN_OP_TYPES_FROM_STRING map has "relu" but no "relu2", and llm_ffn_op_type_from_string() is never wired into the bitnet arch.
  • utils/convert-hf-to-gguf-bitnet.py / utils/convert-ms-to-gguf-bitnet.py — neither converter writes <arch>.hidden_activation, so the existing plumbing (llama_hparams::llm_ffn_op, LLM_KV_HIDDEN_ACT, LLM_FFN_RELU_SQR in src/llama-graph.cpp) is never exercised for bitnet models.

The graph builder already implements LLM_FFN_RELU_SQR (relu → sqr, src/llama-graph.cpp:1690); with LLM_FFN_PAR gating it produces exactly relu²(gate) * up, matching the HF BitnetMLP (act_fn(gate) * up).

Fix (attached patches)

  1. src/llama-model.cpp: add { "relu2", LLM_FFN_RELU_SQR } to LLM_FFN_OP_TYPES_FROM_STRING.
  2. src/models/bitnet.cpp: read <arch>.hidden_activation in load_arch_hparams (mirroring llama_model_modern_bert), defaulting to LLM_FFN_SILU for backward compatibility with existing GGUF files; use hparams.llm_ffn_op in the graph.
  3. Converters: write add_hidden_act("relu2").

Verification

  • Convert microsoft/bitnet-b1.58-2B-4T with the patched converter; gguf-dump should show bitnet_b158.hidden_activation = "relu2".
  • Compare logits before/after: with the fix the model produces coherent text; without it, output is wrong-but-finite.
  • Old GGUF files (no key) keep the previous SiLU behavior — no regression.

Related

  • #586 — same wrong-but-finite class (ARM i2_s layout).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/models/bitnet.cpp and src/llama-model.cpp, then inspect the hidden-activation handling in src/llama-graph.cpp and both BitNet conversion scripts. Verify the converted GGUF with gguf-dump and compare logits or generated text for the microsoft/bitnet-b1.58-2B-4T model. Done means relu2 is recorded and used, while older GGUF files retain SiLU behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.