Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

tinygrad

/tinygrad

Pomaga pisać sieci neuronowe, trenować modele i pracować nad wnętrzem tinygrad, minimalnej biblioteki tensorów z autograd i kompilacją JIT.

Autor
av ↗
Repozytorium
skills ↗
Licencja
MIT
Ostatnia zmiana repozytorium
21.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
2
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 21.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pomaga pisać sieci neuronowe, trenować modele i pracować nad wnętrzem tinygrad, minimalnej biblioteki tensorów z autograd i kompilacją JIT.

Oryginalny opis (EN)

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.

Jak działa

  1. Quick Reference
  2. Architecture Pipeline
  3. Training Loop Pattern
  4. Model Definition
  5. State Dict / Weights
  6. JIT Compilation
  7. Device Management
  8. Environment Variables
  9. Debugging
  10. UOp and PatternMatcher (Internals)
Sekcje z nagłówków SKILL.md, w oryginale · 166 linii, 517 słów
Podgląd SKILL.md
---
name: tinygrad
description: 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.
---

# 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 Python classes with `__call__`. No base class required.

```python
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

```python
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.

```python
@TinyJit
def forward(x):
  return model(x).realize()

# First call captures, subsequent calls replay
out = forward(batch)
```

## Device Management

```python
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

```bash
# 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:

```python
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-files` before commits

## Testing

```bash
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
```
Pliki w paczce (2)
  • README.md 1 KB
  • SKILL.md 5 KB

Wersje

W bazie nie ma innych skilli o nazwie tinygrad.

Identyczna treść występuje jeszcze w 1 innych folderach na GitHubie. Tu pokazujemy jedną, najlepiej ocenioną kopię.

Migawka bazy z 13.11.2026 · wersja paczki 969a46872895 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100jax
    Wspiera pracę z JAX: Autograd, kompilacja XLA (jit), wektoryzacja (vmap) i paralelizacja (pmap) w wydajnych obliczeniach numerycznych i badaniach nad głębokim uczeniem.
  • 100pytorch-deep-learning-fundamentals
    Buduje i trenuje własne sieci neuronowe w PyTorch z tensorami, autogradem i modułami DataLoader.
  • 100jit-compilation
    Wspiera kompilację JIT i generowanie kodu w czasie działania: LLVM ORC JIT, LLJIT, Cranelift, inline caches, trampoliny oraz generowanie kodu przez dynasm w Rust.
  • 96cuda-streams
    Zarządza czasem życia tensorów na strumieniach CUDA i pomaga ocenić, czy record_stream da się uniknąć, w tym wait_stream, zdarzenia CUDA i API przekazujące tensory ze strumieni bocznych.
  • 100jit-regression-test
    Wyodrębnia samodzielny test regresji JIT ze zgłoszenia GitHub dotnet/runtime i zapisuje go w folderze runnera testów regresji JIT.
  • 100pytorch
    Wspiera uczenie głębokie w PyTorch: tensory dynamiczne, autograd, torch.compile, trening rozproszony DDP i akceleracja GPU przy trenowaniu sieci neuronowych.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.