Official implementation of FlashAttention, a memory-efficient exact attention kernel for training and inference of Transformer models on GPUs.
duoan/TorchCode
Interactive practice platform for implementing PyTorch operators and architectures from scratch, with automated grading in Jupyter.
Open-source alternative to:LeetCode
- Stars
- 4,695
- Forks
- 420
- Open issues
- 16
- Last commit
- 3 months ago
What is it?
TorchCode is a set of 41 coding problems for practicing PyTorch from scratch, similar in format to LeetCode. Each problem asks you to implement a common operation or model component, such as softmax, LayerNorm, multi-head attention, RoPE, LoRA, or a GPT-2 block, typically without relying on torch.nn. Problems are delivered as Jupyter notebooks with a blank template and a separate reference solution.
A judge module (torch_judge) runs your implementation against test cases. It checks numerical correctness with torch.allclose, verifies gradient flow through autograd, and tests shape consistency and edge cases, then reports pass or fail for each test. Hints and a progress dashboard are available from notebook cells, and a toolbar button resets a notebook to its blank state.
The platform runs as a single Docker or Podman container on CPU, with no GPU or database required. It can also be opened on Hugging Face Spaces or in Google Colab, where the judge can be installed from PyPI. A separate Next.js and FastAPI web UI is included as an alternative interface.
Key features
- 0141 problems covering fundamentals, attention variants, transformer blocks, training, decoding, and preference-based losses.
- 02Automated judge checks output correctness, gradient flow, shapes, and edge cases with per-test pass/fail feedback.
- 03Hints and reference solutions are available for each problem.
- 04Toolbar reset restores a notebook to its blank template for repeated practice.
- 05Runs on CPU in a single Docker or Podman container, or in Google Colab without local setup.
Use cases
- Preparing for ML engineering interviews that ask candidates to write PyTorch operations on a whiteboard or in a coding session.
- Learning how softmax, attention, normalization, or LoRA work by implementing them without high-level helpers.
- Practicing PyTorch tensor operations and autograd on a laptop without a GPU.
- Running guided exercises in a classroom or study group through Colab links.
Quick start
- 1
Pull and run the pre-built Docker image
docker run -p 8888:8888 -e PORT=8888 ghcr.io/duoan/torchcode:latest - 2
Open the app in your browser
Things to know
- Requires Docker or Podman, or a local build via make.
- Judge runs in Jupyter and is primarily designed for PyTorch practice, not general use.
- No license is specified in the project metadata.
Topics
FAQ
- What is TorchCode?
- Interactive practice platform for implementing PyTorch operators and architectures from scratch, with automated grading in Jupyter. TorchCode is a set of 41 coding problems for practicing PyTorch from scratch, similar in format to LeetCode. Each problem asks you to implement a common operation or model component, such as softmax, LayerNorm, multi-head attention, RoPE, LoRA, or a GPT-2 block, typically without relying on torch.nn. Problems are delivered as Jupyter notebooks with a blank template and a separate reference solution.
- Is TorchCode free to use? What license does it have?
- TorchCode has no declared license. Its code is public, but without a license you have no explicit permission to reuse it; ask the author before relying on it.
- Is TorchCode still maintained?
- Updated within 6 months. The last commit to TorchCode was on Jul 31, 2026.
- What can I use TorchCode for?
- Preparing for ML engineering interviews that ask candidates to write PyTorch operations on a whiteboard or in a coding session. Learning how softmax, attention, normalization, or LoRA work by implementing them without high-level helpers. Practicing PyTorch tensor operations and autograd on a laptop without a GPU. Running guided exercises in a classroom or study group through Colab links.
- How do I install TorchCode?
- Pull and run the pre-built Docker image: docker run -p 8888:8888 -e PORT=8888 ghcr.io/duoan/torchcode:latest Open the app in your browser
- Where can I get TorchCode?
- The source code and installation instructions are on GitHub: https://github.com/duoan/TorchCode
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A Chinese-language LeetCode study guide with a curated problem order, illustrated solutions, video explanations, and code in C++, Java, Python, Go and JavaScript.
Chinese translation of the book "Build a Large Language Model (From Scratch)", covering LLM principles and GPT-style implementation.
Go solutions to LeetCode problems with a companion Cookbook e-book, covering data structures and algorithms for interview prep.
A study guide that groups LeetCode interview questions by reusable solving patterns, with a web app to browse and track them.
A collection of DSA, competitive programming and CS fundamentals notes and solutions in Jupyter Notebook, aimed at FAANG-style interview prep.