Recursively replaces every nn.Linear inside *module* with BitLinear, skipping the token embedding and lm_head (which stay full-precision).
(module: nn.Module)
| 151 | # ────────────────────────────────────────────────────────────────────────────── |
| 152 | |
| 153 | def _replace_linear_in_module(module: nn.Module) -> None: |
| 154 | """ |
| 155 | Recursively replaces every nn.Linear inside *module* with BitLinear, |
| 156 | skipping the token embedding and lm_head (which stay full-precision). |
| 157 | """ |
| 158 | for name, child in module.named_children(): |
| 159 | if isinstance(child, nn.Linear): |
| 160 | setattr(module, name, BitLinear.from_linear(child)) |
| 161 | else: |
| 162 | _replace_linear_in_module(child) |
| 163 | |
| 164 | |
| 165 | def _remove_decoder_prenorms(model: LlamaForCausalLM) -> None: |
no test coverage detected