← Pinterest Interview Insights
This is a single question but it's really like five questions stitched together.
Start by breaking down the memory components: model parameters, activations, KV cache, and framework overhead. Then, calculate the maximum batch size that fits within 60 GB, considering the latency-throughput trade-off, and validate empirically by measuring latency and throughput across batch sizes.
Pro tip: Always measure actual memory usage and latency with profiling tools, as theoretical estimates can be off due to framework-specific optimizations and overheads. Also, consider dynamic batching and sequence length variability in real-world serving.
Calculate the memory required to store the model weights based on the number of parameters and precision (e.g., FP16, FP32).
For transformer models, compute activation memory per layer and KV cache size per token, then multiply by batch size and sequence length.
Add memory overhead from the deep learning framework (e.g., CUDA context, cuDNN workspaces) and any other runtime components.
Subtract fixed costs from total GPU memory and divide remaining memory by per-sample memory (activations + KV cache) to get an upper bound on batch size.
Run experiments with different batch sizes, measure latency and throughput, and select the batch size that meets latency SLOs while maximizing throughput.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.