MCPcopy Create free account
hub / github.com/dhakalnirajan/LLaMA-BitNet / _replace_linear_in_module

Function _replace_linear_in_module

utils.py:153–162  ·  view source on GitHub ↗

Recursively replaces every nn.Linear inside *module* with BitLinear, skipping the token embedding and lm_head (which stay full-precision).

(module: nn.Module)

Source from the content-addressed store, hash-verified

151# ──────────────────────────────────────────────────────────────────────────────
152
153def _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
165def _remove_decoder_prenorms(model: LlamaForCausalLM) -> None:

Callers 1

convert_to_bitnetFunction · 0.85

Calls 1

from_linearMethod · 0.80

Tested by

no test coverage detected