(weight)
| 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) |
no outgoing calls
no test coverage detected