← Tesla Interview Insights

Tesla·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Tesla ML Engineer interview, got a coding question that was basically 'implement conv2d from scratch, no torch, no nothing.' Pretty technical for a phone screen but I guess that's on brand for them.

Questions Asked (1)

Q1

Implement the forward pass of a 2D convolution from scratch, without using any deep learning library functions. Given an input tensor in NCHW format, filter weights, an optional bias, stride, and padding parameters, compute the output tensor correctly.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew the math well enough but translating it into clean indexing code under pressure is a different thing.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the input dimensions and parameters, then derive the output shape using the convolution formula. Implement the forward pass using nested loops over batch, output channels, output height, and output width, computing the dot product between the input patch and the filter, adding bias if present. Emphasize correctness and efficiency considerations like vectorization or im2col.

Pro tip: Mention that you would validate the implementation against a known library (e.g., PyTorch) on small random inputs to catch off-by-one errors in padding and stride. Also, discuss how to handle edge cases like non-divisible strides or asymmetric padding.

1. Clarify Inputs and Output Shape

Confirm the input tensor shape (N, C, H, W), filter shape (K, C, R, S), stride, padding, and bias. Compute the output dimensions using H_out = floor((H + 2*pad - R)/stride) + 1 and similarly for W_out.

2. Initialize Output Tensor

Create an output tensor of shape (N, K, H_out, W_out) filled with zeros. If bias is provided, initialize each output channel with the corresponding bias value.

3. Implement Convolution Loops

Loop over batch (n), output channel (k), output row (i), and output column (j). For each output position, compute the sum over input channels (c) and filter rows/cols (r, s) of input[n, c, i*stride + r - pad, j*stride + s - pad] * weight[k, c, r, s], handling out-of-bounds as zero.

4. Add Bias and Store Result

After the inner loops, add the bias (if any) to the accumulated sum and assign it to output[n, k, i, j].

5. Optimize and Validate

Discuss potential optimizations like im2col or vectorization, and validate correctness by comparing with a deep learning library on small random inputs.

Key Points to Mention

  • Output shape formula and handling of padding/stride
  • Zero-padding for out-of-bounds indices
  • Loop ordering and memory access patterns for cache efficiency
  • Bias addition and broadcasting
  • Edge cases: non-divisible strides, asymmetric padding, dilation (if applicable)
  • Validation against a reference implementation

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.