Skip to content

fix: emit real I2_S tensors for offline-quantized LlamaModel checkpoints - #623

Open
Pujitha Paladugu (pujitha24) wants to merge 1 commit into
microsoft:mainfrom
pujitha24:auto/issue-621
Open

fix: emit real I2_S tensors for offline-quantized LlamaModel checkpoints#623
Pujitha Paladugu (pujitha24) wants to merge 1 commit into
microsoft:mainfrom
pujitha24:auto/issue-621

Conversation

@pujitha24

Copy link
Copy Markdown

Motivation:
convert-hf-to-gguf-bitnet.py --outtype i2_s mishandled offline-quantized
LlamaForCausalLM BitNet checkpoints (ternary weights packed as uint8 plus a
separate <name>.weight_scale tensor): the scale division was applied
unconditionally, and the I2_S quantization dispatch only had TL1/TL2
branches, so these tensors fell through to the F16 default instead of
producing real I2_S data.

Approach:
In LlamaModel, skip the unconditional scale_map division when the
requested ftype is I2_S, so the ternary values stay undivided. Add an I2_S
branch to the quantization dispatch, gated on the tensor name being present
in scale_map, which calls quantize_to_i2_s with the corresponding
scale as override_scale. Tensors not present in scale_map (ordinary,
non-offline-quantized checkpoints) still fall through to the existing
F16 path, so the division and dispatch changes only affect genuinely
offline-quantized tensors.

Report: #621
Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com
Assisted-by: claude-sonnet-5 (via Claude Code)

Motivation:
`convert-hf-to-gguf-bitnet.py --outtype i2_s` mishandled offline-quantized
LlamaForCausalLM BitNet checkpoints (ternary weights packed as uint8 plus a
separate `<name>.weight_scale` tensor): the scale division was applied
unconditionally, and the I2_S quantization dispatch only had TL1/TL2
branches, so these tensors fell through to the F16 default instead of
producing real I2_S data.

Approach:
In `LlamaModel`, skip the unconditional `scale_map` division when the
requested ftype is I2_S, so the ternary values stay undivided. Add an I2_S
branch to the quantization dispatch, gated on the tensor name being present
in `scale_map`, which calls `quantize_to_i2_s` with the corresponding
scale as `override_scale`. Tensors not present in `scale_map` (ordinary,
non-offline-quantized checkpoints) still fall through to the existing
F16 path, so the division and dispatch changes only affect genuinely
offline-quantized tensors.

Report: microsoft#621
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Assisted-by: claude-sonnet-5 (via Claude Code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant