(model, verbose=False)
| 89 | |
| 90 | |
| 91 | def make_Act(model, verbose=False): |
| 92 | replace_map = dict() |
| 93 | for name, module in model.named_modules(): |
| 94 | if isinstance(module, nn.Linear): |
| 95 | replace_map[name] = ActLinear(module) |
| 96 | |
| 97 | for name, module in model.named_modules(): |
| 98 | if verbose: |
| 99 | print("current:", name) |
| 100 | for k, v in replace_map.items(): |
| 101 | k_ = k.split(".") |
| 102 | name_prefix, name_suffix = ".".join(k_[:-1]), k_[-1] |
| 103 | if name_prefix == "": # outer layer |
| 104 | if name == name_suffix: |
| 105 | if verbose: |
| 106 | print(" not modifying ", name_suffix) |
| 107 | # setattr(model, name_suffix, v) |
| 108 | elif name == name_prefix: |
| 109 | if verbose: |
| 110 | print(" modifying ", name_suffix, "inside", name) |
| 111 | setattr(module, name_suffix, v) |
| 112 | return model |
| 113 | |
| 114 | |
| 115 | def revert_Act_to_Linear(model): |
no test coverage detected