The 60-second answer
Define tensor shapes, parameter initialization, forward semantics, dtype/device behavior, and whether broadcasting is intentional. Prefer vectorized framework operations first; verify gradients with autograd/gradcheck before optimizing.
Build the answer in this order
Define tensor shapes, parameter initialization, forward semantics, dtype/device behavior, and whether broadcasting is intentional.
Prefer vectorized framework operations first; verify gradients with autograd/gradcheck before optimizing.
Profile to identify kernel launch, memory movement, or compute bottlenecks; then consider fusion, layout changes, custom kernels, or reduced precision.
Benchmark representative batch/shape regimes and preserve numerical/error tolerances against a reference implementation.
A useful interview mental model
This is the shape of a strong answer—not a script to memorize.
Senior-level signal
- Senior answers optimize only after establishing a correctness oracle and profile evidence.
- Discuss backward-pass cost, memory saved tensors, compile/fusion behavior, and portability across accelerators.
What the interviewer is really testing
Likely follow-up questions
Common weak-answer patterns
- Ignoring shape, dtype, device, masking, or broadcasting assumptions.
- Using a framework call without explaining the underlying operation.
- Skipping gradient, numerical-stability, and batching checks.