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

Function apply_clip

quantization/clip_utils.py:193–211  ·  view source on GitHub ↗
(module, clip_results)

Source from the content-addressed store, hash-verified

191
192@torch.no_grad()
193def apply_clip(module, clip_results):
194 if not isinstance(clip_results, list):
195 clip_list = clip_results["clip"]
196 else:
197 clip_list = clip_results
198 if len(clip_list) == 0:
199 return
200 if len(clip_list[0]) == 3:
201 for name, max_val, min_val in clip_list:
202 layer = get_op_by_name(module, name)
203 layer.cuda()
204 max_val = max_val.to(layer.weight.device)
205 min_val = min_val.to(layer.weight.device)
206 org_shape = layer.weight.shape
207 layer.weight.data = layer.weight.data.reshape(*max_val.shape[:2], -1)
208 layer.weight.data = torch.clamp(layer.weight.data, min_val, max_val)
209 layer.weight.data = layer.weight.data.reshape(org_shape)
210 else:
211 raise 1

Callers 4

trainFunction · 0.90
run_awqFunction · 0.85
apply_awqFunction · 0.85
run_clipFunction · 0.85

Calls 1

get_op_by_nameFunction · 0.85

Tested by

no test coverage detected