fix(npu): extend bf16 autocast to NPU in MossAudioTokenizer decode (#6664)

Signed-off-by: Wallbreazzz <110282866+Wallbreazzz@users.noreply.github.com>
Signed-off-by: Canlin Guo <961750412@qq.com>
Co-authored-by: Canlin Guo <961750412@qq.com>
Co-authored-by: Canlin Guo <canlinguosdu@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-08-28 04:01:49 -07:00
1 parent d5aced9296
commit be335a86f9
1 file changed
+6 -2
@@ -2000,8 +2000,12 @@ class MossAudioTokenizerModel(MossAudioTokenizerPreTrainedModel):
if codes_lengths is None:
codes_lengths = torch.full((B,), T, device=device, dtype=torch.long)
# Keep eager execution and CUDA Graph capture on the same BF16 path.
with torch.autocast(device_type=device.type, dtype=torch.bfloat16, enabled=device.type == "cuda"):
# Keep eager execution and CUDA/NPU Graph capture on the same BF16 path.
# Autocast is required on NPU because #5235's decode-LUT uses .float()
# for precision, producing float32 embeddings. Without autocast, these
# float32 tensors flow into bf16 LayerNorm weights and NPU's aclnnLayerNorm
# rejects the mixed dtype (CUDA auto-casts; NPU does not).
with torch.autocast(device_type=device.type, dtype=torch.bfloat16, enabled=device.type != "cpu"):
quantizer = cast(MossAudioTokenizerResidualVQ | MossAudioTokenizerResidualLFQ, self.quantizer)
zq = quantizer.decode_codes(codes)