vondp/TorchCode
0
1---2title: TorchCode3emoji: ๐ฅ4colorFrom: red5colorTo: yellow6sdk: docker7app_port: 78608pinned: false9---10 11<div align="center">12 13# ๐ฅ TorchCode14 15**Crack the PyTorch interview.**16 17Practice implementing operators and architectures from scratch โ the exact skills top ML teams test for.18 19*Like LeetCode, but for tensors. Self-hosted. Jupyter-based. Instant feedback.*20 21[](https://pytorch.org)22[](https://jupyter.org)23[](https://www.docker.com)24[](https://python.org)25[](LICENSE)26 27[](https://github.com/duoan/TorchCode)28[](https://ghcr.io/duoan/torchcode)29[](https://huggingface.co/spaces/duoan/TorchCode)303132 33[](https://star-history.com/#duoan/TorchCode&Date)34 35</div>36 37---38 39## ๐ฏ Why TorchCode?40 41Top companies (Meta, Google DeepMind, OpenAI, etc.) expect ML engineers to implement core operations **from memory on a whiteboard**. Reading papers isn't enough โ you need to write `softmax`, `LayerNorm`, `MultiHeadAttention`, and full Transformer blocks code.42 43TorchCode gives you a **structured practice environment** with:44 45| | Feature | |46|---|---|---|47| ๐งฉ | **40 curated problems** | The most frequently asked PyTorch interview topics |48| โ๏ธ | **Automated judge** | Correctness checks, gradient verification, and timing |49| ๐จ | **Instant feedback** | Colored pass/fail per test case, just like competitive programming |50| ๐ก | **Hints when stuck** | Nudges without full spoilers |51| ๐ | **Reference solutions** | Study optimal implementations after your attempt |52| ๐ | **Progress tracking** | What you've solved, best times, and attempt counts |53| ๐ | **One-click reset** | Toolbar button to reset any notebook back to its blank template โ practice the same problem as many times as you want |54| [](#) | **Open in Colab** | Every notebook has an "Open in Colab" badge + toolbar button โ run problems in Google Colab with zero setup |55 56No cloud. No signup. No GPU needed. Just `make run` โ or try it instantly on Hugging Face.57 58---59 60## ๐ Quick Start61 62### Option 0 โ Try it online (zero install)63 64**[Launch on Hugging Face Spaces](https://huggingface.co/spaces/duoan/TorchCode)** โ opens a full JupyterLab environment in your browser. Nothing to install.65 66Or open any problem directly in Google Colab โ every notebook has an [](https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/01_relu.ipynb) badge.67 68### Option 1 โ Pull the pre-built image (fastest)69 70```bash71docker run -p 8888:8888 -e PORT=8888 ghcr.io/duoan/torchcode:latest72```73 74### Option 2 โ Build locally75 76```bash77make run78```79 80Open **<http://localhost:8888>** โ that's it. Works with both Docker and Podman (auto-detected).81 82---83 84## ๐ Problem Set85 86> **Frequency**: ๐ฅ = very likely in interviews, โญ = commonly asked, ๐ก = emerging / differentiator87 88### ๐งฑ Fundamentals โ "Implement X from scratch"89 90The bread and butter of ML coding interviews. You'll be asked to write these without `torch.nn`.91 92| # | Problem | What You'll Implement | Difficulty | Freq | Key Concepts |93|:---:|---------|----------------------|:----------:|:----:|--------------|94| 1 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/01_relu.ipynb" target="_blank">ReLU</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/01_relu.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `relu(x)` |  | ๐ฅ | Activation functions, element-wise ops |95| 2 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/02_softmax.ipynb" target="_blank">Softmax</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/02_softmax.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `my_softmax(x, dim)` |  | ๐ฅ | Numerical stability, exp/log tricks |96| 16 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/16_cross_entropy.ipynb" target="_blank">Cross-Entropy Loss</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/16_cross_entropy.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `cross_entropy_loss(logits, targets)` |  | ๐ฅ | Log-softmax, logsumexp trick |97| 17 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/17_dropout.ipynb" target="_blank">Dropout</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/17_dropout.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `MyDropout` (nn.Module) |  | ๐ฅ | Train/eval mode, inverted scaling |98| 18 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/18_embedding.ipynb" target="_blank">Embedding</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/18_embedding.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `MyEmbedding` (nn.Module) |  | ๐ฅ | Lookup table, `weight[indices]` |99| 19 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/19_gelu.ipynb" target="_blank">GELU</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/19_gelu.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `my_gelu(x)` |  | โญ | Gaussian error linear unit, `torch.erf` |100| 20 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/20_weight_init.ipynb" target="_blank">Kaiming Init</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/20_weight_init.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `kaiming_init(weight)` |  | โญ | `std = sqrt(2/fan_in)`, variance scaling |101| 21 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/21_gradient_clipping.ipynb" target="_blank">Gradient Clipping</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/21_gradient_clipping.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `clip_grad_norm(params, max_norm)` |  | โญ | Norm-based clipping, direction preservation |102| 31 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/31_gradient_accumulation.ipynb" target="_blank">Gradient Accumulation</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/31_gradient_accumulation.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `accumulated_step(model, opt, ...)` |  | ๐ก | Micro-batching, loss scaling |103| 40 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/40_linear_regression.ipynb" target="_blank">Linear Regression</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/40_linear_regression.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `LinearRegression` (3 methods) |  | ๐ฅ | Normal equation, GD from scratch, nn.Linear |104| 3 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/03_linear.ipynb" target="_blank">Linear Layer</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/03_linear.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `SimpleLinear` (nn.Module) |  | ๐ฅ | `y = xW^T + b`, Kaiming init, `nn.Parameter` |105| 4 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/04_layernorm.ipynb" target="_blank">LayerNorm</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/04_layernorm.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `my_layer_norm(x, ฮณ, ฮฒ)` |  | ๐ฅ | Normalization, running stats, affine transform |106| 7 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/07_batchnorm.ipynb" target="_blank">BatchNorm</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/07_batchnorm.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `my_batch_norm(x, ฮณ, ฮฒ)` |  | โญ | Batch vs layer statistics, train/eval behavior |107| 8 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/08_rmsnorm.ipynb" target="_blank">RMSNorm</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/08_rmsnorm.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `rms_norm(x, weight)` |  | โญ | LLaMA-style norm, simpler than LayerNorm |108| 15 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/15_mlp.ipynb" target="_blank">SwiGLU MLP</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/15_mlp.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `SwiGLUMLP` (nn.Module) |  | โญ | Gated FFN, `SiLU(gate) * up`, LLaMA/Mistral-style |109| 22 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/22_conv2d.ipynb" target="_blank">Conv2d</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/22_conv2d.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `my_conv2d(x, weight, ...)` |  | ๐ฅ | Convolution, unfold, stride/padding |110 111### ๐ง Attention Mechanisms โ The heart of modern ML interviews112 113If you're interviewing for any role touching LLMs or Transformers, expect at least one of these.114 115| # | Problem | What You'll Implement | Difficulty | Freq | Key Concepts |116|:---:|---------|----------------------|:----------:|:----:|--------------|117| 23 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/23_cross_attention.ipynb" target="_blank">Cross-Attention</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/23_cross_attention.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `MultiHeadCrossAttention` (nn.Module) |  | โญ | Encoder-decoder, Q from decoder, K/V from encoder |118| 5 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/05_attention.ipynb" target="_blank">Scaled Dot-Product Attention</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/05_attention.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `scaled_dot_product_attention(Q, K, V)` |  | ๐ฅ | `softmax(QK^T/โd_k)V`, the foundation of everything |119| 6 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/06_multihead_attention.ipynb" target="_blank">Multi-Head Attention</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/06_multihead_attention.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `MultiHeadAttention` (nn.Module) |  | ๐ฅ | Parallel heads, split/concat, projection matrices |120| 9 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/09_causal_attention.ipynb" target="_blank">Causal Self-Attention</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/09_causal_attention.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `causal_attention(Q, K, V)` |  | ๐ฅ | Autoregressive masking with `-inf`, GPT-style |121| 10 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/10_gqa.ipynb" target="_blank">Grouped Query Attention</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/10_gqa.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `GroupQueryAttention` (nn.Module) |  | โญ | GQA (LLaMA 2), KV sharing across heads |122| 11 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/11_sliding_window.ipynb" target="_blank">Sliding Window Attention</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/11_sliding_window.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `sliding_window_attention(Q, K, V, w)` |  | โญ | Mistral-style local attention, O(nยทw) complexity |123| 12 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/12_linear_attention.ipynb" target="_blank">Linear Attention</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/12_linear_attention.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `linear_attention(Q, K, V)` |  | ๐ก | Kernel trick, `ฯ(Q)(ฯ(K)^TV)`, O(nยทdยฒ) |124| 14 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/14_kv_cache.ipynb" target="_blank">KV Cache Attention</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/14_kv_cache.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `KVCacheAttention` (nn.Module) |  | ๐ฅ | Incremental decoding, cache K/V, prefill vs decode |125| 24 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/24_rope.ipynb" target="_blank">RoPE</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/24_rope.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `apply_rope(q, k)` |  | ๐ฅ | Rotary position embedding, relative position via rotation |126| 25 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/25_flash_attention.ipynb" target="_blank">Flash Attention</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/25_flash_attention.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `flash_attention(Q, K, V, block_size)` |  | ๐ก | Tiled attention, online softmax, memory-efficient |127 128### ๐๏ธ Architecture & Adaptation โ Put it all together129 130| # | Problem | What You'll Implement | Difficulty | Freq | Key Concepts |131|:---:|---------|----------------------|:----------:|:----:|--------------|132| 26 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/26_lora.ipynb" target="_blank">LoRA</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/26_lora.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `LoRALinear` (nn.Module) |  | โญ | Low-rank adaptation, frozen base + `BA` update |133| 27 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/27_vit_patch.ipynb" target="_blank">ViT Patch Embedding</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/27_vit_patch.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `PatchEmbedding` (nn.Module) |  | ๐ก | Image โ patches โ linear projection |134| 13 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/13_gpt2_block.ipynb" target="_blank">GPT-2 Block</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/13_gpt2_block.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `GPT2Block` (nn.Module) |  | โญ | Pre-norm, causal MHA + MLP (4x, GELU), residual connections |135| 28 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/28_moe.ipynb" target="_blank">Mixture of Experts</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/28_moe.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `MixtureOfExperts` (nn.Module) |  | โญ | Mixtral-style, top-k routing, expert MLPs |136 137### โ๏ธ Training & Optimization138 139| # | Problem | What You'll Implement | Difficulty | Freq | Key Concepts |140|:---:|---------|----------------------|:----------:|:----:|--------------|141| 29 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/29_adam.ipynb" target="_blank">Adam Optimizer</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/29_adam.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `MyAdam` |  | โญ | Momentum + RMSProp, bias correction |142| 30 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/30_cosine_lr.ipynb" target="_blank">Cosine LR Scheduler</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/30_cosine_lr.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `cosine_lr_schedule(step, ...)` |  | โญ | Linear warmup + cosine annealing |143 144### ๐ฏ Inference & Decoding145 146| # | Problem | What You'll Implement | Difficulty | Freq | Key Concepts |147|:---:|---------|----------------------|:----------:|:----:|--------------|148| 32 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/32_topk_sampling.ipynb" target="_blank">Top-k / Top-p Sampling</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/32_topk_sampling.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `sample_top_k_top_p(logits, ...)` |  | ๐ฅ | Nucleus sampling, temperature scaling |149| 33 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/33_beam_search.ipynb" target="_blank">Beam Search</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/33_beam_search.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `beam_search(log_prob_fn, ...)` |  | ๐ฅ | Hypothesis expansion, pruning, eos handling |150| 34 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/34_speculative_decoding.ipynb" target="_blank">Speculative Decoding</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/34_speculative_decoding.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `speculative_decode(target, draft, ...)` |  | ๐ก | Accept/reject, draft model acceleration |151 152### ๐ฌ Advanced โ Differentiators153 154| # | Problem | What You'll Implement | Difficulty | Freq | Key Concepts |155|:---:|---------|----------------------|:----------:|:----:|--------------|156| 35 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/35_bpe.ipynb" target="_blank">BPE Tokenizer</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/35_bpe.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `SimpleBPE` |  | ๐ก | Byte-pair encoding, merge rules, subword splits |157| 36 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/36_int8_quantization.ipynb" target="_blank">INT8 Quantization</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/36_int8_quantization.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `Int8Linear` (nn.Module) |  | ๐ก | Per-channel quantize, scale/zero-point, buffer vs param |158| 37 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/37_dpo_loss.ipynb" target="_blank">DPO Loss</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/37_dpo_loss.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `dpo_loss(chosen, rejected, ...)` |  | ๐ก | Direct preference optimization, alignment training |159| 38 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/38_grpo_loss.ipynb" target="_blank">GRPO Loss</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/38_grpo_loss.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `grpo_loss(logps, rewards, group_ids, eps)` |  | ๐ก | Group relative policy optimization, RLAIF, within-group normalized advantages |160| 39 | <a href="https://github.com/duoan/TorchCode/blob/master/templates/39_ppo_loss.ipynb" target="_blank">PPO Loss</a> <a href="https://colab.research.google.com/github/duoan/TorchCode/blob/master/templates/39_ppo_loss.ipynb" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" height="20"></a> | `ppo_loss(new_logps, old_logps, advantages, clip_ratio)` |  | ๐ก | PPO clipped surrogate loss, policy gradient, trust region |161 162---163 164## โ๏ธ How It Works165 166Each problem has **two** notebooks:167 168| File | Purpose |169|------|---------|170| `01_relu.ipynb` | โ๏ธ Blank template โ write your code here |171| `01_relu_solution.ipynb` | ๐ Reference solution โ check when stuck |172 173### Workflow174 175```text1761. Open a blank notebook โ Read the problem description1772. Implement your solution โ Use only basic PyTorch ops1783. Debug freely โ print(x.shape), check gradients, etc.1794. Run the judge cell โ check("relu")1805. See instant colored feedback โ โ
pass / โ fail per test case1816. Stuck? Get a nudge โ hint("relu")1827. Review the reference solution โ 01_relu_solution.ipynb1838. Click ๐ Reset in the toolbar โ Blank slate โ practice again!184```185 186### In-Notebook API187 188```python189from torch_judge import check, hint, status190 191check("relu") # Judge your implementation192hint("causal_attention") # Get a hint without full spoiler193status() # Progress dashboard โ solved / attempted / todo194```195 196---197 198## ๐
Suggested Study Plan199 200> **Total: ~12โ16 hours spread across 3โ4 weeks. Perfect for interview prep on a deadline.**201 202| Week | Focus | Problems | Time |203|:----:|-------|----------|:----:|204| **1** | ๐งฑ Foundations | ReLU โ Softmax โ CE Loss โ Dropout โ Embedding โ GELU โ Linear โ LayerNorm โ BatchNorm โ RMSNorm โ SwiGLU MLP โ Conv2d | 2โ3 hrs |205| **2** | ๐ง Attention Deep Dive | SDPA โ MHA โ Cross-Attn โ Causal โ GQA โ KV Cache โ Sliding Window โ RoPE โ Linear Attn โ Flash Attn | 3โ4 hrs |206| **3** | ๐๏ธ Architecture + Training | GPT-2 Block โ LoRA โ MoE โ ViT Patch โ Adam โ Cosine LR โ Grad Clip โ Grad Accumulation โ Kaiming Init | 3โ4 hrs |207| **4** | ๐ฏ Inference + Advanced | Top-k/p Sampling โ Beam Search โ Speculative Decoding โ BPE โ INT8 Quant โ DPO Loss โ GRPO Loss โ PPO Loss + speed run | 3โ4 hrs |208 209---210 211## ๐๏ธ Architecture212 213```text214โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ215โ Docker / Podman Container โ216โ โ217โ JupyterLab (:8888) โ218โ โโโ templates/ (reset on each run) โ219โ โโโ solutions/ (reference impl) โ220โ โโโ torch_judge/ (auto-grading) โ221โ โโโ torchcode-labext (JLab plugin) โ222โ โ ๐ Reset โ restore template โ223โ โ ๐ Colab โ open in Colab โ224โ โโโ PyTorch (CPU), NumPy โ225โ โ226โ Judge checks: โ227โ โ Output correctness (allclose) โ228โ โ Gradient flow (autograd) โ229โ โ Shape consistency โ230โ โ Edge cases & numerical stability โ231โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ232```233 234Single container. Single port. No database. No frontend framework. No GPU.235 236## ๐ ๏ธ Commands237 238```bash239make run # Build & start (http://localhost:8888)240make stop # Stop the container241make clean # Stop + remove volumes + reset all progress242```243 244## ๐งฉ Adding Your Own Problems245 246TorchCode uses auto-discovery โ just drop a new file in `torch_judge/tasks/`:247 248```python249TASK = {250 "id": "my_task",251 "title": "My Custom Problem",252 "difficulty": "medium",253 "function_name": "my_function",254 "hint": "Think about broadcasting...",255 "tests": [ ... ],256}257```258 259No registration needed. The judge picks it up automatically.260 261---262 263## โ FAQ264 265<details>266<summary><b>Do I need a GPU?</b></summary>267<br>268No. Everything runs on CPU. The problems test correctness and understanding, not throughput.269</details>270 271<details>272<summary><b>Can I keep my solutions between runs?</b></summary>273<br>274Blank templates reset on every <code>make run</code> so you practice from scratch. Save your work under a different filename if you want to keep it. You can also click the <b>๐ Reset</b> button in the notebook toolbar at any time to restore the blank template without restarting.275</details>276 277<details>278<summary><b>Can I use Google Colab instead?</b></summary>279<br>280Yes! Every notebook has an <b>Open in Colab</b> badge at the top. Click it to open the problem directly in Google Colab โ no Docker or local setup needed. You can also use the <b>Colab</b> toolbar button inside JupyterLab.281</details>282 283<details>284<summary><b>How are solutions graded?</b></summary>285<br>286The judge runs your function against multiple test cases using <code>torch.allclose</code> for numerical correctness, verifies gradients flow properly via autograd, and checks edge cases specific to each operation.287</details>288 289<details>290<summary><b>Who is this for?</b></summary>291<br>292Anyone preparing for ML/AI engineering interviews at top tech companies, or anyone who wants to deeply understand how PyTorch operations work under the hood.293</details>294 295---296 297<div align="center">298 299**Built for engineers who want to deeply understand what they build.**300 301If this helped your interview prep, consider giving it a โญ302 303---304 305### โ Buy Me a Coffee306 307<a href="https://buymeacoffee.com/duoan" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>308 309<img src="./bmc_qr.png" alt="BMC QR Code" width="150" height="150">310 311*Scan to support*312 313</div>314 