Function
mlp_forward
(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 | |
| 233 | def 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 | |
| 249 | def layer_norm_2d(x: torch.Tensor, weight: torch.Tensor, bias: torch.Tensor, eps: float = 1e-6) -> torch.Tensor: |
Tested by
no test coverage detected