You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] requantize(embed_quant_mode=...) leaves the new endpoints on CPU (in-session forward fails) and TorchQuantEmbeddings emits fp16 in a bf16 model (INPUT-requantized bf16 checkpoint cannot run: 'float != BFloat16' at lm_head) #5116
Dtype (also after reload).TorchQuantEmbeddings.forward (nn_modules/qlinear/torch.py:1410-1429) returns F.embedding(ids, self.dequantize_weight()), which has the dtype of scales. GPTQ stores scales as F16 even for a bf16 model, so a bf16 model gets an fp16 embedding output. Adding it to the bf16 norm/residual math promotes the residual stream to fp32. With INPUT alone, the dense bf16 lm_head then raises expected mat1 and mat2 to have the same dtype, but got: float != c10::BFloat16 on every forward of the saved and reloaded checkpoint, with or without dtype=torch.bfloat16. With BOTH, the quantized head accepts the fp32 activations, so it runs, but the whole decoder computes in fp32 instead of bf16.
tests/test_requant_embed_lm_head_e2e.py misses both problems. It never runs an in-session forward after requantize(), it only covers BOTH, and its checkpoint (Qwen2.5-0.5B-Instruct-gptq-4bit) is fp16, so the dtypes happen to match.
INPUT:
in-session embed ('TorchQuantEmbeddings', ['cpu/torch.float16', 'cpu/torch.int32', 'cpu/torch.int64']) lm_head ('Linear', ['cuda:0/torch.bfloat16'])
in-session forward ERR RuntimeError Expected all tensors to be on the same device, but got index is on cuda:0, different from other tensors on cpu
saved: model.embed_tokens.scales F16, lm_head.weight BF16
reload {} -> RuntimeError expected mat1 and mat2 to have the same dtype, but got: float != c10::BFloat16 (at lm_head)
reload {dtype: torch.bfloat16} -> RuntimeError expected mat1 and mat2 to have the same dtype, but got: float != c10::BFloat16
BOTH:
in-session embed and lm_head on cpu/float16 -> same device-mismatch error
reload -> runs ("The capital of France is Paris. Which of the following"), activations fp32
Suggested fix
At the end of _requantize_embeddings, place each new endpoint on the device of the module it replaced (or run rehome_quantized_kernel over the endpoints).
Have TorchQuantEmbeddings return the model compute dtype instead of scales.dtype: record the replaced embedding's weight dtype on the module, or cast in forward, the way TorchLinear casts its output to the input dtype.
Extend the e2e test with a bf16 checkpoint, INPUT mode, and an in-session forward before save().
Severity
Medium. On a bf16 model, INPUT requantize produces a checkpoint that cannot run a single forward. The in-session model is unusable after any successful embedding requantize.
Activity
Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-f60b36e15e6dfinished this issue.Pull request: #5156
Fixing requantize endpoint device/dtype placement so the in-session model runs and a bf16 INPUT checkpoint reloads
fix(requantize): place embedding endpoints on the model device and dt…