← All problems
#41 Simple Inference Easy

Run inference on a PyTorch model. Given an input tensor and a trained torch.nn.Linear model, compute the forward pass and store the result in the output tensor.

The model performs a linear transformation: output = input @ weight.T + bias where weight has shape [output_size, input_size] and bias has shape [output_size].

Implementation Requirements

Example 1:

  Input:  input = [[1.0, 2.0]]  (batch_size=1, input_size=2)
          model: Linear layer with weight=[[0.5, 1.0], [1.5, 0.5]], bias=[0.1, 0.2]
  Output: output = [[2.6, 2.7]]  (batch_size=1, output_size=2)
  

Example 2:

  Input:  input = [[1.0], [2.0], [3.0]]  (batch_size=3, input_size=1)
          model: Linear layer with weight=[[2.0]], bias=[1.0]
  Output: output = [[3.0], [5.0], [7.0]]  (batch_size=3, output_size=1)
  

Constraints

Guided walkthrough coming soon. Below is the official starter signature in each language; the clickable line-by-line explanation hasn't been authored yet.
Problem text & starters from the official AlphaGPU/leetgpu-challenges. Solve it on leetgpu.com.