I struggled to grind for ML/AI interviews so I went back to the basics and created a list after careful research.
TorchLeet is broken into two sets of questions:
- Question Set: A collection of PyTorch practice problems, ranging from basic to hard, designed to enhance your skills in deep learning and PyTorch.
- LLM Set: A new set of questions focused on understanding and implementing Large Language Models (LLMs) from scratch, including attention mechanisms, embeddings, and more.
Note
Avoid using GPT. Try to solve these problems on your own. The goal is to learn and understand PyTorch concepts deeply.
Note
Yes. I used GPT to help write the code and I ended up testing it out myself as practise. I found the strategy to be super useful
Mostly for beginners to get started with PyTorch.
- Implement linear regression (Solution)
- Write a custom Dataset and Dataloader to load from a CSV file (Solution)
- Write a custom activation function (Simple) (Solution)
- Implement Custom Loss Function (Huber Loss) (Solution)
- Implement a Deep Neural Network (Solution)
- Visualize Training Progress with TensorBoard in PyTorch (Solution)
- Save and Load Your PyTorch Model (Solution)
- Implement Softmax function from scratch
Recommended for those who have a basic understanding of PyTorch and want to practice their skills.
- Implement a CNN on CIFAR-10 (Solution)
- Implement an RNN from Scratch (Solution)
- Use
torchvision.transformsto apply data augmentation (Solution) - Add a benchmark to your PyTorch code (Solution)
- Train an autoencoder for anomaly detection (Solution)
- Quantize your language model (Solution)
- Implement Mixed Precision Training using torch.cuda.amp (Solution)
These problems are designed to challenge your understanding of PyTorch and deep learning concepts. They require you to implement things from scratch or apply advanced techniques.
- Implement parameter initialization for a CNN (Solution)
- Implement a CNN from Scratch (Solution)
- Implement an LSTM from Scratch (Solution)
- Implement AlexNet from scratch
- Build a Dense Retrieval System using PyTorch
- Implement KNN from scratch in PyTorch
- Train a 3D CNN network for segmenting CT images Solution
These problems are for advanced users who want to push their PyTorch skills to the limit. They involve complex architectures, custom layers, and advanced techniques.
- Write a custom Autograd function for activation (SILU) (Solution)
- Write a Neural Style Transfer
- Build a Graph Neural Network (GNN) from scratch
- Build a Graph Convolutional Network (GCN) from scratch
- Write a Transformer (Solution)
- Write a GAN (Solution)
- Write Sequence-to-Sequence with Attention (Solution)
- [Enable distributed training in pytorch (DistributedDataParallel)]
- [Work with Sparse Tensors]
- Add GradCam/SHAP to explain the model. (Solution)
- Linear Probe on CLIP Features
- Add Cross Modal Embedding Visualization to CLIP (t-SNE/UMAP)
- Implement a Vision Transformer
- Implement a Variational Autoencoder
An all new set of questions to help you understand and implement Large Language Models from scratch.
Each question is designed to take you one step closer to building your own LLM.
- Implement KL Divergence Loss
- Implement RMS Norm
- Implement Byte Pair Encoding from Scratch (Solution)
- Create a RAG Search of Embeddings from a set of Reviews
- Implement Predictive Prefill with Speculative Decoding
- Implement Attention from Scratch (Solution)
- Implement Multi-Head Attention from Scratch (Solution)
- Implement Grouped Query Attention from Scratch (Solution)
- Implement KV Cache in Multi-Head Attention from Scratch
- Implement Sinusoidal Embeddings (Solution)
- Implement ROPE Embeddings (Solution)
- Implement SmolLM from Scratch (Solution)
- Implement Quantization of Models
- GPTQ
- Implement Beam Search atop LLM for decoding
- Implement Top K Sampling atop LLM for decoding
- Implement Top p Sampling atop LLM for decoding
- Implement Temperature Sampling atop LLM for decoding
- Implement LoRA on a layer of an LLM
- QLoRA
- Mix two models to create a mixture of Experts
- Apply SFT on SmolLM
- Apply RLHF on SmolLM
- Implement DPO based RLHF
- Add continuous batching to your LLM
- Chunk Textual Data for Dense Passage Retrieval
- Implement Large scale Training => 5D Parallelism
What's cool? π
- Diverse Questions: Covers beginner to advanced PyTorch concepts (e.g., tensors, autograd, CNNs, GANs, and more).
- Guided Learning: Includes incomplete code blocks (
...and#TODO) for hands-on practice along with Answers
A research-backed set of 30 questions covering what top AI companies actually ask in 2024-2025 interviews. Each question is tagged with the companies known to test that topic.
Note
These questions were compiled from real interview reports across Glassdoor, Blind, Reddit, and first-person accounts from candidates who interviewed at 15+ frontier AI labs. Questions are organized by interview role rather than just difficulty.
Still asked at traditional FAANG companies (Google, Meta, Amazon, Uber, LinkedIn).
- Implement Softmax from Scratch (numerically stable) (Solution) π’ Easy β
AppleMetaGoogleAmazon - Implement K-Means Clustering in PyTorch (Solution) π’ Easy β
UberLinkedInGoogleAmazon - Implement KNN in PyTorch (Solution) π’ Easy β
UberLinkedInMeta - Implement Logistic Regression with Gradient Descent (Solution) π’ Easy β
GoogleMetaAmazon
Core questions at frontier AI labs β Anthropic, OpenAI, DeepMind, Cohere, Perplexity.
- Implement Contrastive Loss (InfoNCE) + CLIP Training Loop (Solution) π‘ Medium β
OpenAIAnthropicDeepMindMidjourneyApple - Implement 2D Positional Embeddings (Solution) π‘ Medium β
AnthropicDeepMindMidjourneyRunway - Implement Top-p (Nucleus) Sampling (Solution) π‘ Medium β
AnthropicOpenAIDeepMindPerplexityCohere - Implement Top-k Sampling (Solution) π‘ Medium β
AnthropicOpenAIDeepMindCohere - Implement Beam Search for LLM Decoding (Solution) π‘ Medium β
GoogleDeepMindMetaApple - Implement Temperature Sampling (Solution) π’ Easy β
OpenAIAnthropicCoherePerplexity
Hot topic for LLM infrastructure roles at Perplexity, Together AI, Anyscale, Meta.
- Implement LoRA on a Linear Layer (Solution) π‘ Medium β
MetaGoogleAnthropicOpenAIDatabricks - Implement KV Cache for Autoregressive Generation (Solution) π‘ Medium β
AnthropicOpenAIMetaPerplexityTogether AI - Implement Sliding Window Attention (Solution) π‘ Medium β
MistralAnthropicGoogleDeepMind - Implement DPO Loss from Scratch (Solution) π΄ Hard β
AnthropicOpenAIDeepMindMeta - Implement PPO for RLHF (Solution) π΄ Hard β
AnthropicOpenAIDeepMindMeta - Implement Gradient Checkpointing (Solution) π΄ Hard β
MetaGoogleNVIDIATesla - Implement Mixture of Experts Layer (Solution) π΄ Hard β
GoogleDeepMindMistralDatabricksxAI - Implement Speculative Decoding (Solution) π΄ Hard β
GoogleDeepMindAnthropicApple - Implement Continuous Batching for LLM Inference (Solution) π΄ Hard β
PerplexityTogether AIAnyscaleMeta
Cutting-edge topics at image-gen companies, research labs, and autonomous driving.
- Implement DDPM (Denoising Diffusion) from Scratch (Solution) π΄ Hard β
MidjourneyRunwayStability AIAdobeGoogle - Implement DDIM Sampling + Classifier-Free Guidance (Solution) π΄ Hard β
MidjourneyRunwayStability AIAdobe - Implement Selective State Space Model (Mamba Block) (Solution) π΄ Hard β
DeepMindGoogleAnthropic - Implement Vision Transformer + MAE Pretraining (Solution) π΄ Hard β
MetaGoogleAppleTeslaWaymo - Implement Knowledge Distillation (Solution) π‘ Medium β
GoogleAppleMetaQualcommTesla
For ML infrastructure and systems roles at NVIDIA, Meta, xAI, and frontier labs.
- Write a Fused Softmax Kernel in Triton (Solution) π£ Expert β
NVIDIAMetaGooglexAITesla - Implement FlashAttention-2 in Triton (Solution) π£ Expert β
NVIDIAMetaTogether AIxAI - Implement FSDP (Fully Sharded Data Parallel) from Scratch (Solution) π£ Expert β
MetaGoogleNVIDIAAnthropicxAI - Implement GRPO (DeepSeek-R1 Algorithm) (Solution) π£ Expert β
DeepMindAnthropicOpenAI - Build a Complete LLM Inference Engine (Solution) π£ Expert β
PerplexityTogether AIAnyscaleFireworks AI - Implement Ring Attention for Long Contexts (Solution) π£ Expert β
AnthropicGoogleMetaxAI
"If I'm interviewing at X, which v3 questions should I prioritize?"
| Company | Priority Questions |
|---|---|
| Anthropic | 5, 6, 7, 8, 10, 12, 13, 14, 15, 18, 22, 26, 27, 30 |
| OpenAI | 5, 7, 8, 10, 11, 12, 14, 15, 27 |
| DeepMind | 5, 6, 7, 8, 9, 13, 14, 15, 17, 18, 22, 27 |
| Meta | 1, 2, 3, 4, 9, 11, 12, 14, 15, 16, 19, 23, 24, 25, 26, 30 |
| 1, 2, 4, 9, 11, 13, 16, 17, 18, 20, 22, 23, 24, 26, 29, 30 | |
| Apple | 1, 5, 9, 18, 23, 29 |
| NVIDIA | 16, 24, 25, 26 |
| Midjourney / Runway / Stability AI | 5, 6, 20, 21 |
| Perplexity / Together AI / Anyscale | 7, 10, 12, 19, 25, 28 |
| Tesla / Waymo | 16, 23, 24, 29 |
| xAI | 17, 24, 25, 26, 30 |
| Mistral / Cohere | 7, 8, 10, 13, 17 |
- Install pytorch: Install pytorch locally
- Some problems need other packages. Install as needed.
<E/M/H><ID>/: Easy/Medium/Hard along with the question ID.<E/M/H><ID>/qname.ipynb: The question file with incomplete code blocks.<E/M/H><ID>/qname_SOLN.ipynb: The corresponding solution file.
- Navigate to questions/ and pick a problem
- Fill in the missing code blocks
(...)and address the#TODOcomments. - Test your solution and compare it with the corresponding file in
solutions/.
Happy Learning! π
Feel free to contribute by adding new questions or improving existing ones. Ensure that new problems are well-documented and follow the project structure. Submit a PR and tag the authors.
|
Chandrahas Aroori π» AI/ML Dev |
Caslow Chien π» Developer |
