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

Function quant_weight_fp16

utils/preprocess-huggingface-bitnet.py:5–9  ·  view source on GitHub ↗
(weight)

Source from the content-addressed store, hash-verified

3import torch
4
5def quant_weight_fp16(weight):
6 weight = weight.to(torch.float)
7 s = 1.0 / weight.abs().mean().clamp_(min=1e-5)
8 new_weight = (weight * s).round().clamp(-1, 1) / s
9 return new_weight
10
11def quant_model(input, output):
12 tensors = {}

Callers 1

quant_modelFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected