MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / mlp_forward

Function mlp_forward

tests/dump_phase6_reference.py:233–246  ·  view source on GitHub ↗
(x: torch.Tensor,
                weights: Dict[str, torch.Tensor],
                prefix: str,
                num_layers: int,
                sigmoid_output: bool = False)

Source from the content-addressed store, hash-verified

231
232
233def mlp_forward(x: torch.Tensor,
234 weights: Dict[str, torch.Tensor],
235 prefix: str,
236 num_layers: int,
237 sigmoid_output: bool = False) -> torch.Tensor:
238 for i in range(num_layers):
239 w = weights[f"{prefix}.layers.{i}.weight"].float()
240 b = weights[f"{prefix}.layers.{i}.bias"].float()
241 x = F.linear(x, w, b)
242 if i < num_layers - 1:
243 x = F.relu(x)
244 if sigmoid_output:
245 x = torch.sigmoid(x)
246 return x
247
248
249def layer_norm_2d(x: torch.Tensor, weight: torch.Tensor, bias: torch.Tensor, eps: float = 1e-6) -> torch.Tensor:

Callers 1

dump_caseFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected