OpenAI

Verified interview challenge

Matrix Prefix Products

Multiply an ordered sequence of matrices and work out how every prefix contributes to the gradient.

Unlock with Full Access

The challenge

Start with an in-place implementation, then preserve PyTorch's autograd graph in an out-of-place version. Derive the backward pass yourself before expressing both passes with a supplied associative scan. The four parts share one Python file, with guided practice or a 75-minute timed mock.

What you'll practise

  • Ordered matrix products

    Compute every prefix while respecting matrix order and tensor storage.

  • Manual derivatives

    Account for gradients arriving at intermediate outputs as well as the final one.

  • Associative scan

    Express a sequential recurrence as an operation that can combine adjacent ranges.

Your coding workspacePreview
Current partFurther parts unlock as you progress
solution.pyPython 3.13
# Build on your implementation

# Run checks for the current part

# Full starter code included
Current-part checks

Run your code to see results.

The complete sequence, starter code and checks are included with Full Access.