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

Method from_linear

utils.py:134–146  ·  view source on GitHub ↗

Construct a BitLinear from an existing nn.Linear, copying its weight.

(cls, linear: nn.Linear)

Source from the content-addressed store, hash-verified

132 # ------------------------------------------------------------------
133 @classmethod
134 def from_linear(cls, linear: nn.Linear) -> "BitLinear":
135 """Construct a BitLinear from an existing nn.Linear, copying its weight."""
136 bl = cls(
137 in_features=linear.in_features,
138 out_features=linear.out_features,
139 bias=linear.bias is not None,
140 dtype=linear.weight.dtype,
141 )
142 with torch.no_grad():
143 bl.weight.copy_(linear.weight)
144 if linear.bias is not None and bl.bias is not None:
145 bl.bias.copy_(linear.bias)
146 return bl
147
148
149# ──────────────────────────────────────────────────────────────────────────────

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected