(module, target_device)
| 37 | |
| 38 | |
| 39 | def compress_module(module, target_device): |
| 40 | for attr_str in dir(module): |
| 41 | target_attr = getattr(module, attr_str) |
| 42 | if type(target_attr) == torch.nn.Linear: |
| 43 | setattr( |
| 44 | module, |
| 45 | attr_str, |
| 46 | CLinear(target_attr.weight, target_attr.bias, target_device), |
| 47 | ) |
| 48 | for name, child in module.named_children(): |
| 49 | compress_module(child, target_device) |
| 50 | |
| 51 | |
| 52 | def compress(tensor, config): |