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

Function auto_clip_block

quantization/autoclip.py:87–107  ·  view source on GitHub ↗
(module,
                    w_bit, q_config,
                    input_feat)

Source from the content-addressed store, hash-verified

85
86@torch.no_grad()
87def auto_clip_block(module,
88 w_bit, q_config,
89 input_feat):
90
91 named_linears = {name: m for name,
92 m in module.named_modules() if isinstance(m, nn.Linear)}
93
94 clip_list = []
95 for name in named_linears:
96 # due to qk bmm, it is hard to clip precisely
97 if any([_ in name for _ in ["q_", "k_", "query", "key", "Wqkv"]]):
98 continue
99 named_linears[name].cuda()
100
101 max_val, min_val = auto_2clip_layer(
102 named_linears[name].weight, input_feat[name], n_bit=w_bit, q_config=q_config)
103
104 clip_list.append((name, max_val, min_val))
105
106 named_linears[name].cpu()
107 return clip_list
108
109@torch.no_grad()
110def run_clip(

Callers 2

run_awqFunction · 0.85
run_clipFunction · 0.85

Calls 1

auto_2clip_layerFunction · 0.85

Tested by

no test coverage detected