y = xW^T + b, Kaiming init, nn.Parameter
Medium FundamentalsImplement a fully-connected linear layer: y = xW^T + b
• self.weight: shape (out_features, in_features), init with randn * (1/√in_features)
• self.bias: shape (out_features,), init as zeros
• Both must have requires_grad=True
• forward(x) computes x @ W^T + b
• Do NOT use torch.nn.Linear
Implement the function below. Use only basic PyTorch operations.
Use this code to debug before submitting.
Try solving it yourself first! Click below to reveal the solution.
For interactive practice with auto-grading, run TorchCode locally:pip install torch-judge then use check("linear")
y = xW^T + b, Kaiming init, nn.Parameter