tinygrad skill
✓ VerifiedDevelop deep learning models using a minimal tensor library featuring autograd, JIT compilation, and multi-device support.
- GitHub stars
- 28
- Files
- 2
- Last commit
- Nov 11, 2026
- License
- MIT
- Allowed tools
- —
What does the tinygrad skill do?
tinygrad is an agent skill. Develop deep learning models using a minimal tensor library featuring autograd, JIT compilation, and multi-device support.
Summary generated from the skill's SKILL.md.
About the tinygrad skill
Building neural networks and managing tensor operations is what developers achieve using this minimal deep learning framework. It provides a lightweight alternative for those who need to implement custom tensor operations, write training loops, or contribute to the internal architecture of a deep learning library. An agent should load this skill when tasked with designing model architectures, optimizing kernel graphs, or managing multi-device execution across hardware like CUDA, METAL, or CPU.
The framework operates through a specific pipeline that moves from a user-facing Tensor API to a unified IR called UOp, then through a schedule and codegen phase before reaching the device runtime. It distinguishes itself by using lazy execution, where operations are only realized when explicitly requested. Developers can also interact with the internal graph transformations using the PatternMatcher and UOp systems to rewrite computation graphs for better performance.
What an agent can do with it
- 1Define neural network architecturesCreate custom model classes using standard Python syntax and built-in modules like Linear or Conv2d.
- 2Perform graph transformationsUse the PatternMatcher tool to rewrite UOp graphs for specific operation optimizations.
- 3Manage multi-device workloadsDirect tensor computations to specific hardware backends such as CUDA or AMD.
Written from the skill's SKILL.md. Every use case is checked against a quote from it.
How to install the tinygrad skill
Each command copies the skill folder into the client's skills directory. Restart the client or start a new session to load it.Install the tinygrad skill in Claude Code
~/.claude/skills/tinygrad/SKILL.md
$ npx degit av/skills/tinygrad ~/.claude/skills/tinygradInstall the tinygrad skill in Claude Code (project)
.claude/skills/tinygrad/SKILL.md
$ npx degit av/skills/tinygrad .claude/skills/tinygradInstall the tinygrad skill in Codex
~/.agents/skills/tinygrad/SKILL.md
$ npx degit av/skills/tinygrad ~/.agents/skills/tinygradInstall the tinygrad skill in Gemini CLI
~/.gemini/skills/tinygrad/SKILL.md
$ npx degit av/skills/tinygrad ~/.gemini/skills/tinygradInstall the tinygrad skill in Claude.ai
npx degit av/skills/tinygrad tinygrad && zip -r tinygrad.zip tinygrad # claude.ai → Customize → Skills → + → Create skill → Upload a skill → tinygrad.zip
Automated checks
Ran Nov 14, 2026Full report →Passed our automated checks. That is not a security audit: read the scripts before you let an agent run them. How checks work
- Source repository linked and reachableav/skills/tinygrad is public and reachablegithub.com/av/skills/tree/HEAD/tinygrad ↗Pass
- Open source license (OSI)MITspdx.org/licenses/MIT.html ↗Pass
- Commit or release in the last yearLast commit 2026-11-11github.com/av/skills/commits ↗Pass
- No download-and-run or credential theft in scriptsNo scripts in the skill folderPass
- No hidden instructions in SKILL.mdNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/av/skills/blob/HEAD/tinygrad/SKILL.md ↗Pass
- Pre-approved tools are scopedNo pre-approved tools; the agent asks before using onegithub.com/av/skills/blob/HEAD/tinygrad/SKILL.md ↗Pass
- SKILL.md follows the Agent Skills formatValid name and description; says when to use it; 170 linesgithub.com/av/skills/blob/HEAD/tinygrad/SKILL.md ↗Pass
SKILL.md
View on GitHubtinygrad
A minimal deep learning framework focused on beauty and minimalism. Every line must earn its keep.
Quick Reference
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
- Tensor (
tinygrad/tensor.py) - User API, creates UOp graph - UOp (
tinygrad/uop/ops.py) - Unified IR for all operations - Schedule (
tinygrad/engine/schedule.py) - Converts tensor UOps to kernel UOps - Codegen (
tinygrad/codegen/) - Converts kernel UOps to device code - Runtime (
tinygrad/runtime/) - Device-specific execution
Training Loop Pattern
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 Python classes with __call__. No base class required.
class Model:
def __init__(self):
self.l1 = nn.Linear(784, 128)
self.l2 = nn.Linear(128, 10)
def __call__(self, x):
return self.l1(x).relu().sequential([self.l2])
Available nn modules: Linear, Conv2d, BatchNorm, LayerNorm, RMSNorm, Embedding, GroupNorm, LSTMCell
Optimizers: SGD, Adam, AdamW, LARS, LAMB, Muon
State Dict / Weights
from tinygrad.nn.state import safe_save, safe_load, get_state_dict, load_state_dict, get_parameters
# Save/load safetensors
safe_save(get_state_dict(model), "model.safetensors")
load_state_dict(model, safe_load("model.safetensors"))
# Get all trainable params
params = get_parameters(model)
JIT Compilation
TinyJit captures and replays kernel graphs. Input shapes must be fixed.
@TinyJit
def forward(x):
return model(x).realize()
# First call captures, subsequent calls replay
out = forward(batch)
Device Management
from tinygrad import Device
print(Device.DEFAULT) # Auto-detected: METAL, CUDA, AMD, CPU, etc.
# Force device
x = Tensor.rand(10, device="CPU")
x = x.to("CUDA")
Environment Variables
| Variable | Values | Description |
|---|---|---|
DEBUG |
1-7 | Increasing verbosity (4=code, 7=asm) |
VIZ |
1 | Graph visualization |
BEAM |
# | Kernel beam search width |
NOOPT |
1 | Disable optimizations |
SPEC |
1-2 | UOp spec verification |
Debugging
# Visualize computation graph
VIZ=1 python -c "from tinygrad import Tensor; Tensor.ones(10).sum().realize()"
# Show generated code
DEBUG=4 python script.py
# Run tests
python -m pytest test/test_tensor.py -xvs
UOp and PatternMatcher (Internals)
UOps are immutable, cached graph nodes. Use PatternMatcher for transformations:
from tinygrad.uop.ops import UOp, Ops
from tinygrad.uop.upat import UPat, PatternMatcher, graph_rewrite
pm = PatternMatcher([
(UPat(Ops.ADD, src=(UPat.cvar("x"), UPat.cvar("x"))), lambda x: x * 2),
])
result = graph_rewrite(uop, pm)
Key UOp properties: op, dtype, src, arg, tag
Define PatternMatchers at module level - they're slow to construct.
Style Guide
- 2-space indentation, 150 char line limit
- Prefer readability over cleverness
- Never mix functionality changes with whitespace changes
- All functionality changes must be tested
- Run
pre-commit run --all-filesbefore commits
Testing
python -m pytest test/test_tensor.py -xvs
python -m pytest test/unit/test_schedule_cache.py -x --timeout=60
SPEC=2 python -m pytest test/test_something.py # With spec verification
Files in this skill
2tinygrad skill questions
How do I install the tinygrad skill in Claude Code?
Run npx degit av/skills/tinygrad ~/.claude/skills/tinygrad. Claude Code loads skills from ~/.claude/skills (all projects) or .claude/skills (one project) and uses a skill when its description matches the task.
Which clients can use the tinygrad skill?
Any client that reads the Agent Skills format: Claude Code, Codex, Gemini CLI and claude.ai (upload as a ZIP). Scripts in the skill run only where the client allows code execution.
How do I define a model in tinygrad?
Models are plain Python classes that implement the __call__ method; they do not require a specific base class.
How can I speed up execution using JIT?
You can use the TinyJit decorator to capture and replay kernel graphs, though input shapes must remain fixed.
How do I manage different hardware devices?
Tinygrad auto-detects devices like METAL, CUDA, AMD, or CPU, but you can manually force a device using the device argument in Tensor creation or the .to() method.
How can I visualize the computation graph?
You can visualize the graph by setting the VIZ environment variable to 1 before running your script.