← ClaudeAtlas

tinygradlisted

Deep learning framework development with tinygrad - a minimal tensor library with autograd, JIT compilation, and multi-device support. Use when writing neural networks, training models, implementing tensor operations, working with UOps/PatternMatcher for graph transformations, or contributing to tinygrad internals. Triggers on tinygrad imports, Tensor operations, nn modules, optimizer usage, schedule/codegen work, or device backends.
av/skills · ★ 13 · AI & Automation · score 80
Install: claude install-skill av/skills
# tinygrad A minimal deep learning framework focused on beauty and minimalism. Every line must earn its keep. ## Quick Reference ```python from tinygrad import Tensor, TinyJit, nn, dtypes, Device, GlobalCounters # Tensor creation x = Tensor([1, 2, 3]) x = Tensor.rand(2, 3) x = Tensor.kaiming_uniform(128, 784) # Operations are lazy until realized y = (x + 1).relu().sum() y.realize() # or y.numpy() # Training context with Tensor.train(): loss = model(x).sparse_categorical_crossentropy(labels).backward() optim.step() ``` ## Architecture Pipeline 1. **Tensor** (`tinygrad/tensor.py`) - User API, creates UOp graph 2. **UOp** (`tinygrad/uop/ops.py`) - Unified IR for all operations 3. **Schedule** (`tinygrad/engine/schedule.py`) - Converts tensor UOps to kernel UOps 4. **Codegen** (`tinygrad/codegen/`) - Converts kernel UOps to device code 5. **Runtime** (`tinygrad/runtime/`) - Device-specific execution ## Training Loop Pattern ```python from tinygrad import Tensor, TinyJit, nn from tinygrad.nn.datasets import mnist X_train, Y_train, X_test, Y_test = mnist() model = Model() optim = nn.optim.Adam(nn.state.get_parameters(model)) @TinyJit @Tensor.train() def train_step(): optim.zero_grad() samples = Tensor.randint(512, high=X_train.shape[0]) loss = model(X_train[samples]).sparse_categorical_crossentropy(Y_train[samples]).backward() return loss.realize(*optim.schedule_step()) for i in range(100): loss = train_step() ``` ## Model Definition Models are plain P