CrackML by @ml.with.umang
Interview questions / ML Coding & PyTorch
ML Coding & PyTorch interview question

What bottlenecks would you optimize in a CUDA kernel used for model inference?

What bottlenecks would you optimize in a CUDA kernel used for model inference?

hardml codingEvidence 41/1001 source reportNVIDIA

The 60-second answer

Break end-to-end latency into queueing, preprocessing, host/device transfer, kernel execution, synchronization, decoding, and post-processing before optimizing. Profile utilization, memory bandwidth, occupancy, batch shape, cache behavior, and p50/p95/p99 latency to identify whether the bottleneck is compute, memory, launch overhead, or scheduling.

Build the answer in this order

1
State tensor contract

Break end-to-end latency into queueing, preprocessing, host/device transfer, kernel execution, synchronization, decoding, and post-processing before optimizing.

2
Implement the mechanism

Profile utilization, memory bandwidth, occupancy, batch shape, cache behavior, and p50/p95/p99 latency to identify whether the bottleneck is compute, memory, launch overhead, or scheduling.

3
Check numerics + gradients

Apply batching, kernel fusion, mixed precision, caching, layout changes, or paged/continuous-batching techniques only when profiling supports them.

4
Test shapes and edge cases

Validate under realistic concurrency and sequence-length distributions while tracking throughput, tail latency, memory headroom, and failure rate.

A useful interview mental model

This is the shape of a strong answer—not a script to memorize.

01Shapes
02Forward pass
03Loss / grads
04Numerics
05Tests

Senior-level signal

  • Design admission control and backpressure so throughput gains do not create OOMs or catastrophic tail latency.
  • Tie kernel-level wins to end-to-end request performance; microbenchmarks alone are not a production success metric.

What the interviewer is really testing

Tensor fluency, shape reasoning, numerics, gradients, batching, device awareness, and the ability to debug—not API memorization.

Likely follow-up questions

What are the tensor shapes at each step?
Where could numerical instability or silent broadcasting appear?
How would you verify gradients and batched behavior?

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.