(model, verbose=False)
| 74 | |
| 75 | |
| 76 | def make_Act(model, verbose=False): |
| 77 | replace_map = dict() |
| 78 | for name, module in model.named_modules(): |
| 79 | if isinstance(module, nn.Linear): |
| 80 | replace_map[name] = ActLinear(module) |
| 81 | |
| 82 | for name, module in model.named_modules(): |
| 83 | if verbose: |
| 84 | print("current:", name) |
| 85 | for k, v in replace_map.items(): |
| 86 | k_ = k.split(".") |
| 87 | name_prefix, name_suffix = ".".join(k_[:-1]), k_[-1] |
| 88 | if name_prefix == "": # outer layer |
| 89 | if name == name_suffix: |
| 90 | if verbose: |
| 91 | print(" not modifying ", name_suffix) |
| 92 | # setattr(model, name_suffix, v) |
| 93 | elif name == name_prefix: |
| 94 | if verbose: |
| 95 | print(" modifying ", name_suffix, "inside", name) |
| 96 | setattr(module, name_suffix, v) |
| 97 | return model |
| 98 | |
| 99 | |
| 100 | def revert_Act_to_Linear(model): |
no test coverage detected