(module, names, w_bit, groupsize, device, name="")
| 83 | |
| 84 | |
| 85 | def make_quant_linear(module, names, w_bit, groupsize, device, name=""): |
| 86 | if isinstance(module, WQLinear): |
| 87 | return |
| 88 | for attr in dir(module): |
| 89 | tmp = getattr(module, attr) |
| 90 | name1 = name + "." + attr if name != "" else attr |
| 91 | if name1 in names: |
| 92 | delattr(module, attr) |
| 93 | setattr( |
| 94 | module, |
| 95 | attr, |
| 96 | WQLinear( |
| 97 | w_bit, |
| 98 | groupsize, |
| 99 | tmp.in_features, |
| 100 | tmp.out_features, |
| 101 | tmp.bias is not None, |
| 102 | device, |
| 103 | ), |
| 104 | ) |
| 105 | for name1, child in module.named_children(): |
| 106 | make_quant_linear( |
| 107 | child, |
| 108 | names, |
| 109 | w_bit, |
| 110 | groupsize, |
| 111 | device, |
| 112 | name + "." + name1 if name != "" else name1, |
| 113 | ) |
| 114 | |
| 115 | |
| 116 | def find_layers(module, layers=[nn.Linear], name=""): |
no test coverage detected