MCPcopy Create free account
hub / github.com/microsoft/BitNet / quant_weight_int8

Function quant_weight_int8

gpu/convert_checkpoint.py:23–27  ·  view source on GitHub ↗
(weight)

Source from the content-addressed store, hash-verified

21 print(f"Model config {config.__dict__}")
22
23 def quant_weight_int8(weight):
24 s = 1.0 / weight.abs().mean().clamp_(min=1e-5)
25 new_weight = (weight * s).round().clamp(-1, 1).to(torch.int8)
26 new_scale = (1.0 / s).to(torch.bfloat16)
27 return new_weight, new_scale.reshape(1)
28
29 def quant_weight_fp16(weight):
30 s = 1.0 / weight.abs().mean().clamp_(min=1e-5)

Callers 1

convert_ts_checkpointFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected