MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / pseudo_quantize_model_weight

Function pseudo_quantize_model_weight

test/test_utils.py:66–83  ·  view source on GitHub ↗
(
    model, w_bit, q_config, quant_type="int"
)

Source from the content-addressed store, hash-verified

64
65@torch.no_grad()
66def pseudo_quantize_model_weight(
67 model, w_bit, q_config, quant_type="int"
68):
69 if quant_type == "int":
70 layers = model.model.layers
71 for i in tqdm(range(len(layers)), desc=f"pseudo {quant_type} weight quantization..."):
72 named_linears = get_named_linears(layers[i])
73 for n, m in named_linears.items():
74 m.weight.data = pseudo_quantize_tensor(m.weight.data, n_bit=w_bit, **q_config)
75
76 elif quant_type == "nf3":
77 quantizer = SteN2F3Quantizer(q_group_size=q_config["q_group_size"])
78 layers = model.model.layers
79 for i in tqdm(range(len(layers)), desc=f"pseudo {quant_type} weight quantization..."):
80 named_linears = get_named_linears(layers[i])
81 for n, m in named_linears.items():
82 # m.cuda()
83 m.weight.data = quantizer(m.weight.data)

Callers 4

get_modelFunction · 0.90
llm_eval.pyFile · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls 3

SteN2F3QuantizerClass · 0.85
get_named_linearsFunction · 0.70
pseudo_quantize_tensorFunction · 0.70

Tested by

no test coverage detected