repo stringlengths 7 90 | file_url stringlengths 81 315 | file_path stringlengths 4 228 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 14:38:15 2026-01-05 02:33:18 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_shm_tensor.py | test/unit/test_shm_tensor.py | import unittest
import multiprocessing.shared_memory as shared_memory
from tinygrad.helpers import CI, WIN
from tinygrad.tensor import Tensor, Device
import numpy as np
class TestRawShmBuffer(unittest.TestCase):
@unittest.skipIf(WIN and CI, "only fails on CI windows instance")
def test_e2e(self):
t = Tensor.ra... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_dtype.py | test/unit/test_dtype.py | import unittest, pickle
from tinygrad.tensor import Tensor
from tinygrad.dtype import dtypes, DType, ImageDType, PtrDType, to_dtype, Invalid, InvalidType
class TestImageDType(unittest.TestCase):
def test_image_scalar(self):
assert dtypes.imagef((10,10)).base.scalar() == dtypes.float32
assert dtypes.imageh((1... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_tensor_io.py | test/unit/test_tensor_io.py | import unittest
from tinygrad import Tensor, dtypes
from tinygrad.nn.state import TensorIO
class TestTensorIO(unittest.TestCase):
def test_create(self):
with self.assertRaises(ValueError):
TensorIO(Tensor(b"Hello World").reshape(1, -1))
with self.assertRaises(ValueError):
TensorIO(Tensor([], dtyp... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_tinyfs.py | test/unit/test_tinyfs.py | import unittest
from tinygrad import Tensor
class TestLoadStore(unittest.TestCase):
def test_load_shape(self):
t = Tensor(bytes(16)).fs_load(1024)
assert t.shape == (1024,), t.shape
def test_store_shape(self):
t = Tensor.zeros(1024).fs_store()
assert t.shape == (16,), t.shape
def test_load_larg... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_hashing.py | test/unit/test_hashing.py | from typing_extensions import Callable
import hashlib, random, unittest
from tinygrad import Tensor, Device, getenv, dtypes
from test.helpers import slow
from tinygrad.device import is_dtype_supported
from tinygrad.uop.ops import UOp
from tinygrad.engine.jit import TinyJit
@unittest.skipUnless(is_dtype_supported(dtype... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_tensor_data.py | test/unit/test_tensor_data.py | import unittest, struct
from tinygrad import Tensor, dtypes
# format types: https://docs.python.org/3/library/struct.html
class TestTensorBytes(unittest.TestCase):
def test_bytes(self):
lst = Tensor(bytes(b"\xaa\xbb\xcc\xdd"))
assert lst.tolist() == [170, 187, 204, 221]
def test_float_bytes(self):
ls... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_rearrange_einops.py | test/unit/test_rearrange_einops.py | # modified from
# https://github.com/arogozhnikov/einops/blob/master/tests/test_examples.py
# https://github.com/arogozhnikov/einops/blob/master/tests/test_ops.py
# https://github.com/arogozhnikov/einops/blob/master/tests/test_parsing.py
import numpy as np
import unittest
from tinygrad import Tensor
class test_rearr... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_conv.py | test/unit/test_conv.py | import unittest
import numpy as np
from tinygrad.tensor import Tensor
from tinygrad.helpers import Context
class TestConv(unittest.TestCase):
def test_simple(self):
x = Tensor.ones(1,12,16,32).contiguous().realize()
w = Tensor.ones(32,12,3,3).contiguous().realize()
ret = x.conv2d(w, stride=(2,2), padding... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_uop_symbolic.py | test/unit/test_uop_symbolic.py | #!/usr/bin/env python
import unittest, pickle, functools, math
import z3
from tinygrad.dtype import dtypes, ConstType, DType, Invalid
from tinygrad.helpers import Context
from test.helpers import get_uops
from tinygrad.uop.ops import UOp, Ops, graph_rewrite, sym_infer
from tinygrad.uop.symbolic import sym, commutative... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | true |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_disk_tensor.py | test/unit/test_disk_tensor.py | import os, pathlib, tempfile, unittest
import numpy as np
from tinygrad import Tensor, Device, dtypes
from tinygrad.dtype import DType
from tinygrad.nn.state import safe_load, safe_save, get_state_dict, torch_load
from tinygrad.helpers import Timing, fetch, temp, OSX
from test.helpers import slow
from tinygrad.device i... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_symbolic_tensor.py | test/unit/test_symbolic_tensor.py | import unittest
from tinygrad import Variable
from tinygrad.tensor import Tensor
class TestSymbolic(unittest.TestCase):
def assert_tuple_equal(self, x, y):
for a,b in zip(x,y): self.assertFalse(a != b)
def test_cat_dim0_is_expanded(self):
i = Variable("i", 1, 5).bind(3)
j = Variable("j", 1, 5).bind(3)... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_disk_cache.py | test/unit/test_disk_cache.py | import unittest
import pickle
from tinygrad.helpers import diskcache_get, diskcache_put, diskcache, diskcache_clear
def remote_get(table,q,k): q.put(diskcache_get(table, k))
def remote_put(table,k,v): diskcache_put(table, k, v)
class DiskCache(unittest.TestCase):
def test_putget(self):
table = "test_putget"
... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_attention.py | test/unit/test_attention.py | import unittest
from tinygrad import Tensor, dtypes, TinyJit, UOp
from tinygrad.apps.llm import apply_rope as apply_rope_new, precompute_freqs_cis
#from tinygrad.engine.realize import run_schedule
def apply_rope(x:Tensor, start_pos:int):
B, H, T, Hd = x.shape
precompute_freqs_cis.cache_clear()
freqs_cis = precom... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_upat_compile.py | test/unit/test_upat_compile.py | import unittest
from tinygrad.helpers import DEBUG, Context
from tinygrad.dtype import dtypes
from tinygrad.uop.ops import UPat, track_rewrites, GroupOp, Ops
from tinygrad.uop.upat import _get_code, upat_compile
import dis
@track_rewrites()
def do_compile(up):
print("\n***** COMPILE", up)
match_code = _get_code(up... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_microbenchmarks.py | test/unit/test_microbenchmarks.py | import unittest, time
from tinygrad import dtypes, Tensor, UOp, getenv
from tinygrad.helpers import Profiling
PYPROFILE = getenv("PYPROFILE")
class TestBench(unittest.TestCase):
@staticmethod
def setUpClass():
# no fixed cost
Tensor.empty(10,10)
Tensor.randn(10,10)
def start_time(self): self.st = ti... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/__init__.py | test/unit/__init__.py | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false | |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_winograd.py | test/unit/test_winograd.py | import unittest, sys
import numpy as np
from tinygrad import Tensor, GlobalCounters, dtypes, Context, nn
from tinygrad.helpers import CI, Profiling, WINO
@unittest.skipIf(sys.platform.startswith("win"), "flaky on Windows")
class TestWinogradClose(unittest.TestCase):
def test_close(self):
inp = Tensor.rand(1, 16,... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_rewrite_bottom_up_gate.py | test/unit/test_rewrite_bottom_up_gate.py | import unittest
from tinygrad.uop.ops import PatternMatcher, UOp, graph_rewrite, Ops, UPat, BottomUpGate
def assert_not_reached(): assert False, "This function should not be reached"
def gate(): raise BottomUpGate
class TestBottomUpGate(unittest.TestCase):
def test_basic_bottom_up_gate(self):
"""Test that Botto... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_simplify_valid_idx.py | test/unit/test_simplify_valid_idx.py | import unittest, itertools
from tinygrad.codegen import full_rewrite_to_sink
from tinygrad.dtype import dtypes
from tinygrad.uop.ops import UOp, Ops
from tinygrad.uop.symbolic import simplify_valid
from tinygrad.helpers import Context
from test.unit.test_uop_symbolic import check_uop_against_string
def get_gated_load... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_validate_oob.py | test/unit/test_validate_oob.py | import unittest
from tinygrad import dtypes, Variable
from tinygrad.dtype import AddrSpace
from tinygrad.helpers import Context
from tinygrad.uop.ops import Ops, UOp, AxisType
from test.test_uops import to_uops_list
class TestValidateOOB(unittest.TestCase):
"""Test z3 validation of index bounds for different ALU ops... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_autogen.py | test/unit/test_autogen.py | import ctypes, subprocess, tempfile, unittest
from tinygrad.helpers import WIN
from tinygrad.runtime.support.c import Struct
class TestAutogen(unittest.TestCase):
def test_packed_struct_sizeof(self):
layout = [('a', ctypes.c_char), ('b', ctypes.c_int, 5), ('c', ctypes.c_char)]
class Y(ctypes.Structure): _fie... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_helpers.py | test/unit/test_helpers.py | import ctypes, gzip, unittest, timeit, pickle
from tinygrad import Variable
from tinygrad.helpers import Context, ContextVar, argfix, colored, word_wrap, is_numpy_ndarray, mv_address, get_contraction, count
from tinygrad.helpers import merge_dicts, strip_parens, prod, round_up, fetch, fully_flatten, from_mv, to_mv, pol... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_llm_server.py | test/unit/test_llm_server.py | import unittest, threading, time
from unittest.mock import Mock
class TestLLMServer(unittest.TestCase):
"""Integration tests using the real OpenAI client."""
@classmethod
def setUpClass(cls):
cls.mock_tok = Mock()
cls.mock_tok.role = Mock(return_value=[100, 101])
cls.mock_tok.encode = Mock(return_va... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/onnx_helpers.py | extra/onnx_helpers.py | from tinygrad import Tensor
from tinygrad.tensor import _to_np_dtype
from tinygrad.nn.onnx import OnnxRunner, OnnxValue
import numpy as np
import onnxruntime as ort
ort_options = ort.SessionOptions()
ort_options.log_severity_level = 3
def get_example_inputs(graph_inputs:dict[str, OnnxValue], config={}):
"""
Genera... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/training.py | extra/training.py | import numpy as np
from tinygrad.tensor import Tensor
from tinygrad.helpers import CI, trange
from tinygrad.engine.jit import TinyJit
def train(model, X_train, Y_train, optim, steps, BS=128, lossfn=lambda out,y: out.sparse_categorical_crossentropy(y),
transform=lambda x: x, target_transform=lambda x: x, nolos... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hip_large_kernel.py | extra/hip_large_kernel.py | from tinygrad.device import Device, Buffer
from tinygrad.dtype import dtypes, _to_np_dtype
dev = Device.default
mbin = dev.compiler.compile("""
typedef long unsigned int size_t;
extern "C" __attribute__((device, const)) size_t __ockl_get_group_id(unsigned int);
extern "C" __attribute__((global)) void __attribute__((am... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/archprobe.py | extra/archprobe.py | # copying the kernels from https://github.com/microsoft/ArchProbe into Python
import numpy as np
import pickle
from tinygrad.runtime.ops_cl import CLProgram, CLBuffer
from tinygrad import dtypes
from tqdm import trange, tqdm
from matplotlib import pyplot as plt
tests = {}
def register_test(fxn):
tests[fxn.__name__] ... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/multitensor.py | extra/multitensor.py | import numpy as np
from tinygrad import Tensor, Device, GlobalCounters
from tinygrad.helpers import Timing
d0, d1 = f"{Device.DEFAULT}:1", f"{Device.DEFAULT}:2"
N = 256
FLOPS = N*N*N*2
# LazyBuffer should make three fields lists: self.st (all must have the same shape), self.realized, and self.device
def explicit_sha... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/bench_log.py | extra/bench_log.py | import time, atexit, uuid
from enum import Enum
from tinygrad.device import Device
from tinygrad.helpers import DEBUG, ContextVar, getenv, GlobalCounters
BENCHMARK_LOG = ContextVar("BENCHMARK_LOG", "")
if BENCHMARK_LOG:
from influxdb_client_3 import InfluxDBClient3, Point, WriteOptions, write_client_options
from... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/export_model.py | extra/export_model.py | from typing import Tuple, Dict, List, Optional
from tinygrad.dtype import DType
from tinygrad.renderer import ProgramSpec
from tinygrad.tensor import Device, Tensor
from tinygrad.engine.jit import TinyJit
from tinygrad.nn.state import get_state_dict
from tinygrad.helpers import Context, to_mv
from tinygrad.dtype import... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/introspection.py | extra/introspection.py | import gc
from tinygrad.helpers import prod
from tinygrad.uop.ops import UOp
from tinygrad.device import Buffer
from tinygrad import Tensor, GlobalCounters
def print_objects():
#gc.collect()
tensors = [x for x in gc.get_objects() if isinstance(x, Tensor)]
tensor_ram_used = sum([prod(x.shape)*4 for x in tensors])... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/weekly_commits_table.py | extra/weekly_commits_table.py | # extra/weekly_commits_table.py
import os, subprocess, datetime as dt
NAMES = ["chenyu","George Hotz","nimlgen","qazal","wozeparrot","Christopher Milan"]
REPO = os.environ.get("REPO_PATH",".")
today = dt.date.today()
days = [(today - dt.timedelta(i)).strftime("%Y-%m-%d") for i in range(6,-1,-1)]
seen = {d:{n:False ... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/f16_decompress.py | extra/f16_decompress.py | from tinygrad import Tensor
def bit_extract(x: Tensor, e: int, s: int) -> Tensor:
mask = (1 << (e - s + 1)) - 1
return (x >> s) & mask
def u16_to_f16(x: Tensor) -> Tensor:
sign = bit_extract(x, 15, 15).float()
exponent = bit_extract(x, 14, 10).float()
fraction = bit_extract(x, 9, 0).float()
return sign.wh... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/gradcheck.py | extra/gradcheck.py | import numpy as np
from tinygrad.tensor import Tensor, _to_np_dtype
def mask_like(like, mask_inx, mask_value = 1.0):
mask = np.zeros(like.shape, dtype=_to_np_dtype(like.dtype)).reshape(-1)
mask[mask_inx] = mask_value
return mask.reshape(like.shape)
def jacobian(func, input):
output = func(input)
ji = input... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hook_cuda.py | extra/hook_cuda.py | import ctypes, struct, platform, pathlib, os, binascii
from hexdump import hexdump
from tinygrad.helpers import to_mv, DEBUG, getenv
from tinygrad.runtime.autogen import libc, cuda
from tinygrad.device import CPUProgram
from tinygrad.runtime.support.elf import elf_loader
from tinygrad.runtime.ops_cuda import cu_time_ex... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/thneed.py | extra/thneed.py | # this can be constructed from a cl_cache or loaded from a thneed file
import time
import struct
import json
import traceback
import numpy as np
from tinygrad.runtime.ops_cl import CLProgram, compile_gpu
from tinygrad.device import Device
from tinygrad.helpers import DEBUG, getenv
from collections import defaultdict
im... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/lr_scheduler.py | extra/lr_scheduler.py | import math
from typing import List
from tinygrad.nn.optim import Optimizer
from tinygrad.tensor import Tensor
class LR_Scheduler:
def __init__(self, optimizer: Optimizer):
self.optimizer = optimizer
self.epoch_counter = Tensor([0], requires_grad=False, device=self.optimizer.device)
def get_lr(self): pass... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/remu/test/hwtest.py | extra/remu/test/hwtest.py | # ruff: noqa: F405, F403
# allow define from star imports
import numpy as np
import unittest
import subprocess, struct, math, functools
from tinygrad import Tensor, dtypes, Device
from tinygrad.helpers import getenv
from extra.assembly.amd.autogen.rdna3.ins import *
from extra.assembly.amd.asm import waitcnt
from te... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hcq/hcq_smi.py | extra/hcq/hcq_smi.py | #!/usr/bin/env python3
import argparse, glob, os, time, subprocess, sys
def scan_devs_based_on_lock(prefix:str, args) -> list[str]:
target_dev = args.pci_bus if 'pci_bus' in args.__dir__() else ""
devs = []
for dev in glob.glob(f'/tmp/{prefix}_*.lock'):
dev_id = dev[8:-5]
if os.path.exists(f"/sys/bus/p... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hevc/decode.py | extra/hevc/decode.py | import argparse, os, hashlib
from tinygrad.helpers import getenv, DEBUG, round_up, Timing, tqdm, fetch
from extra.hevc.hevc import parse_hevc_file_headers, untile_nv12, to_bgr, nv_gpu
from tinygrad import Tensor, dtypes, Device, Variable, TinyJit
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hevc/hevc.py | extra/hevc/hevc.py | import dataclasses, enum, argparse, os, itertools, time, ctypes
from typing import Any
from tinygrad import Tensor, dtypes, Device, TinyJit
from tinygrad.helpers import DEBUG, round_up, ceildiv, Timing, prod
from tinygrad.runtime.autogen import avcodec, nv_570 as nv_gpu
class BitReader:
def __init__(self, data:bytes... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/huggingface_onnx/run_models.py | extra/huggingface_onnx/run_models.py | import onnx, yaml, tempfile, time, argparse, json
from pathlib import Path
from typing import Any
from tinygrad.nn.onnx import OnnxRunner
from extra.onnx_helpers import validate, get_example_inputs
from extra.huggingface_onnx.huggingface_manager import DOWNLOADS_DIR, snapshot_download_with_retry
def get_config(root_pa... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/huggingface_onnx/huggingface_manager.py | extra/huggingface_onnx/huggingface_manager.py | import yaml
import time
import requests
import argparse
from pathlib import Path
from huggingface_hub import list_models, HfApi, snapshot_download
from tinygrad.helpers import _ensure_downloads_dir
DOWNLOADS_DIR = _ensure_downloads_dir() / "models"
from tinygrad.helpers import tqdm
def snapshot_download_with_retry(*, ... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hip_gpu_driver/test_pm4.py | extra/hip_gpu_driver/test_pm4.py | import time
from hexdump import hexdump
from tinygrad import Tensor, Device
import tinygrad.runtime.autogen.amd_gpu as amd_gpu
import tinygrad.runtime.autogen.kfd as kfd
import tinygrad.runtime.autogen.hsa as hsa
from tinygrad.runtime.ops_amd import kio, AMDProgram
from tinygrad.helpers import to_mv
DISPATCH_INIT_VALU... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hip_gpu_driver/test_sdma_fun.py | extra/hip_gpu_driver/test_sdma_fun.py | import ctypes, mmap, time
from tinygrad.runtime.ops_amd import AMDDevice, kio, sdma_pkts, libc
import tinygrad.runtime.autogen.amd_sdma as amd_sdma
import tinygrad.runtime.autogen.kfd as kfd
from tinygrad.helpers import to_mv
if __name__ == "__main__":
dev = AMDDevice()
sdma_ring = dev._gpu_alloc(1 << 22, kfd.KFD... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hip_gpu_driver/test_kfd_2.py | extra/hip_gpu_driver/test_kfd_2.py | import os, ctypes, pathlib, re, fcntl, functools, mmap, time
import tinygrad.runtime.autogen.kfd as kfd
from tinygrad.helpers import to_mv, getenv
from extra.hip_gpu_driver import hip_ioctl
import tinygrad.runtime.autogen.hsa as hsa
from hexdump import hexdump
libc = ctypes.CDLL("libc.so.6")
libc.memset.argtypes = [ct... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hip_gpu_driver/hip_ioctl.py | extra/hip_gpu_driver/hip_ioctl.py | # type: ignore
import ctypes, ctypes.util, struct, platform, pathlib, re, time, os
start = time.perf_counter()
# *** ioctl lib ***
libc = ctypes.CDLL(ctypes.util.find_library("c"))
# platform.processor calls `uname -p` which can return `unknown` on some systems
processor = os.getenv("IOCTL_PROCESSOR") or platform.proc... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/perfetto/to_perfetto.py | extra/perfetto/to_perfetto.py | import sys, pickle, decimal, json
from tinygrad.device import ProfileDeviceEvent, ProfileGraphEvent
from tinygrad.helpers import tqdm, temp, ProfileEvent, ProfileRangeEvent, TracingKey
devices:dict[str, tuple[decimal.Decimal, decimal.Decimal, int]] = {}
def prep_ts(device:str, ts:decimal.Decimal, is_copy): return int(... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/dsp/opt.py | extra/dsp/opt.py | from tinygrad import Device
# PATH=/opt/homebrew/opt/llvm/bin:$PATH python3 extra/dsp/opt.py
if __name__ == "__main__":
compiler = Device["DSP"].compiler
lib = compiler.compile("""
typedef long HVX_Vector __attribute__((__vector_size__(128))) __attribute__ ((aligned(128)));
typedef long HVX_VectorPair __attribut... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/dsp/run.py | extra/dsp/run.py | # mypy: ignore-errors
#!/usr/bin/env python3
import os, ctypes, ctypes.util, struct, platform, time
from tinygrad.runtime.autogen import libc, qcom_dsp
def to_mv(ptr, sz) -> memoryview: return memoryview(ctypes.cast(ptr, ctypes.POINTER(ctypes.c_uint8 * sz)).contents).cast("B")
from hexdump import hexdump
def get_struc... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/dsp/run_3.py | extra/dsp/run_3.py | #!/usr/bin/env python3
import os, ctypes, ctypes.util, struct, platform, pathlib, contextlib, mmap, array
from threading import Thread
from tinygrad.runtime.autogen import qcom_dsp
from tinygrad.helpers import round_up, mv_address, to_mv
from hexdump import hexdump
def get_struct(argp, stype):
return ctypes.cast(cty... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/dsp/invoke_bug.py | extra/dsp/invoke_bug.py | from tinygrad.runtime.ops_dsp import DSPDevice
kernel = """__attribute__((noinline)) void r_6_10_13_4_4_29(float* restrict __attribute__((align_value(128))) data0, const float* restrict __attribute__((align_value(128))) data1, const float* restrict __attribute__((align_value(128))) data2, const float* restrict __attri... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/dsp/compile.py | extra/dsp/compile.py | #!/usr/bin/env python3
import os, ctypes, time, fcntl, mmap
import llvmlite.binding as llvm
from tinygrad.helpers import getenv, to_mv
from tinygrad.runtime.support.elf import elf_loader
from hexdump import hexdump
from tinygrad.runtime.autogen import libc
if getenv("IOCTL"): import run # noqa: F401 # pylint: disable=u... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/dsp/invoke_bug_2.py | extra/dsp/invoke_bug_2.py | from tinygrad.runtime.ops_dsp import DSPDevice
kernel = """__attribute__((noinline)) void r_64_4_4_64_4_4_4(float* restrict __attribute__((align_value(128))) data0, const float* restrict __attribute__((align_value(128))) data1, const float* restrict __attribute__((align_value(128))) data2, const float* restrict __attr... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/dsp/hook.py | extra/dsp/hook.py | import os
print("from import")
del os.environ["LD_PRELOAD"]
import ctypes, ctypes.util
from extra.dsp.run import install_hook, ioctl, libc, get_struct, qcom_dsp, format_struct, to_mv, hexdump
@ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_long)
d... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/dsp/snpe_logs/parse.py | extra/dsp/snpe_logs/parse.py | di = open("dlc_info_2").read().split("\n")
layers = {}
for l in di:
if not l.startswith("| "): continue
if l.startswith("| |"): continue
ll = [x.strip() for x in l.split("|")]
if ll[1] == "Id": continue
layers[int(ll[1])] = (ll[2], ll[6])
hp = open("high_perf_2").read().split("Layer Times:")[1].strip().sp... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/optimization/extract_dataset.py | extra/optimization/extract_dataset.py | #!/usr/bin/env python3
# extract asts from process replay artifacts
import os
from test.external.process_replay.process_replay import _pmap
LOGOPS = os.getenv("LOGOPS", "/tmp/sops")
def extract_ast(*args) -> None:
open(LOGOPS, "a").write(str(args[1]).replace("\n", "").replace(" ", "")+"\n")
return None
if __name... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/optimization/search.py | extra/optimization/search.py | import argparse
from extra.optimization.helpers import ast_str_to_lin, time_linearizer
from tinygrad import dtypes
from tinygrad.helpers import BEAM, getenv
from tinygrad.device import Device, Compiled
from tinygrad.codegen.opt.kernel import Kernel
from tinygrad.codegen.opt.search import beam_search, bufs_from_lin
i... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/optimization/test_beam_search.py | extra/optimization/test_beam_search.py | import unittest
import numpy as np
from tinygrad.helpers import BEAM, Timing, CI, prod
from tinygrad import Variable, Device, Tensor
from tinygrad.nn import Conv2d
from tinygrad.uop.ops import AxisType
from tinygrad.codegen.opt import Opt, OptOps
from tinygrad.codegen.opt.postrange import Scheduler
from tinygrad.codeg... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/optimization/test_time_linearizer.py | extra/optimization/test_time_linearizer.py | from extra.optimization.helpers import load_worlds, ast_str_to_lin, time_linearizer
from tinygrad.codegen.opt.search import bufs_from_lin, get_kernel_actions
if __name__ == "__main__":
ast_strs = load_worlds()
for i, ast_str in enumerate(ast_strs):
lin = ast_str_to_lin(ast_str)
rawbufs = bufs_from_lin(lin)... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/optimization/get_action_space.py | extra/optimization/get_action_space.py | import random
from extra.optimization.helpers import load_worlds, ast_str_to_lin
from tinygrad.codegen.opt.search import actions
from tinygrad.codegen.opt.kernel import Kernel
from tinygrad.codegen.opt.heuristic import hand_coded_optimizations
from tinygrad.helpers import tqdm
tactions = set()
def test_rebuild(lin):
... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/optimization/rl.py | extra/optimization/rl.py | import os
import numpy as np
import math, random
from tinygrad.tensor import Tensor
from tinygrad.nn.state import get_parameters, get_state_dict, safe_save, safe_load, load_state_dict
from tinygrad.codegen.opt.search import actions, bufs_from_lin, get_kernel_actions
from tinygrad.nn.optim import Adam
from extra.optimiz... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/optimization/test_net.py | extra/optimization/test_net.py | import numpy as np
import math
import random
np.set_printoptions(suppress=True)
from copy import deepcopy
from tinygrad.helpers import getenv, colored
from tinygrad.tensor import Tensor
from tinygrad.nn.state import get_parameters, get_state_dict, safe_save, safe_load, load_state_dict
from tinygrad.codegen.opt.search i... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/optimization/test_helpers.py | extra/optimization/test_helpers.py | import unittest
from extra.optimization.helpers import load_worlds
class TestKernelDataset(unittest.TestCase):
def test_load_worlds_filters(self):
all_kernels = load_worlds(filter_reduce=False, filter_noimage=False, filter_novariable=False)
reduce_kernels = load_worlds(filter_reduce=True, filter_noimage=Fa... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/optimization/run_qnet.py | extra/optimization/run_qnet.py | from typing import List, Tuple
from tinygrad.codegen.opt.kernel import Kernel
from tinygrad.codegen.opt.search import get_kernel_actions, actions
_net = None
def beam_q_estimate(beam:List[Tuple[Kernel, float]]) -> List[Tuple[Kernel, float]]:
global _net
if _net is None:
from tinygrad.nn.state import load_state... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/datasets/librispeech.py | extra/datasets/librispeech.py | import json
import pathlib
import numpy as np
import librosa
import soundfile
"""
The dataset has to be downloaded manually from https://www.openslr.org/12/ and put in `extra/datasets/librispeech`.
For mlperf validation the dev-clean dataset is used.
Then all the flacs have to be converted to wav using something like... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/datasets/wikipedia.py | extra/datasets/wikipedia.py | # Preprocessing of downloaded text from Wikipedia for MLPerf BERT training
# This is a modified version of the original script:
# https://github.com/mlcommons/training/blob/master/language_model/tensorflow/bert/cleanup_scripts/create_pretraining_data.py
# ENV VARS:
# MAX_SEQ_LENGTH - Maximum sequence length
# ... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/datasets/preprocess_imagenet.py | extra/datasets/preprocess_imagenet.py | from tinygrad import Tensor, dtypes
from extra.datasets.imagenet import iterate, get_val_files
if __name__ == "__main__":
#sz = len(get_val_files())
sz = 32*100
X,Y = None, None
idx = 0
for x,y in iterate(shuffle=False):
print(x.shape, y.shape, x.dtype, y.dtype)
assert x.shape[0] == y.shape[0]
b... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/datasets/imagenet_download.py | extra/datasets/imagenet_download.py | # Python version of https://gist.github.com/antoinebrl/7d00d5cb6c95ef194c737392ef7e476a
from tinygrad.helpers import fetch
from pathlib import Path
from tqdm import tqdm
import tarfile, os
def imagenet_extract(file, path, small=False):
with tarfile.open(name=file) as tar:
if small: # Show progressbar only for bi... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/datasets/fake_imagenet_from_mnist.py | extra/datasets/fake_imagenet_from_mnist.py | #!/usr/bin/env python3
import pathlib, json
from tinygrad.helpers import trange
from extra.datasets import fetch_mnist
from PIL import Image
import numpy as np
from multiprocessing import Pool
X_train, Y_train, X_test, Y_test = fetch_mnist()
def act(arg):
(basedir, i, train) = arg
if train:
img = np.uint8(X_t... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/datasets/wikipedia_download.py | extra/datasets/wikipedia_download.py | # pip install gdown
# Downloads the 2020 wikipedia dataset used for MLPerf BERT training
import os, hashlib
from pathlib import Path
import tarfile
import gdown
from tqdm import tqdm
from tinygrad.helpers import getenv
def gdrive_download(url:str, path:str):
if not os.path.exists(path): gdown.download(url, path)
de... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/datasets/squad.py | extra/datasets/squad.py | import json
import os
from pathlib import Path
from transformers import BertTokenizer
import numpy as np
from tinygrad.helpers import fetch
BASEDIR = Path(__file__).parent / "squad"
def init_dataset():
os.makedirs(BASEDIR, exist_ok=True)
fetch("https://rajpurkar.github.io/SQuAD-explorer/dataset/dev-v1.1.json", BAS... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/datasets/kits19.py | extra/datasets/kits19.py | import random
import functools
from pathlib import Path
import numpy as np
import nibabel as nib
from scipy import signal, ndimage
import os
import torch
import torch.nn.functional as F
from tqdm import tqdm
from tinygrad.tensor import Tensor
from tinygrad.helpers import fetch
BASEDIR = Path(__file__).parent / "kits19... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/datasets/openimages.py | extra/datasets/openimages.py | import glob
import sys
import json
import numpy as np
from PIL import Image
from pathlib import Path
import boto3, botocore
from tinygrad import Tensor, dtypes
from tinygrad.helpers import fetch, tqdm, getenv
import pandas as pd
import concurrent.futures
BASEDIR = Path(__file__).parent / "open-images-v6-mlperf"
BUCKET... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/datasets/__init__.py | extra/datasets/__init__.py | import os, gzip, tarfile, pickle
import numpy as np
from tinygrad import Tensor, dtypes
from tinygrad.helpers import fetch
def fetch_mnist(tensors=False):
parse = lambda file: np.frombuffer(gzip.open(file).read(), dtype=np.uint8).copy()
BASE_URL = "https://storage.googleapis.com/cvdf-datasets/mnist/" # http://ya... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/datasets/imagenet.py | extra/datasets/imagenet.py | # for imagenet download prepare.sh and run it
import glob, random, json, math
import numpy as np
from PIL import Image
import functools, pathlib
from tinygrad.helpers import diskcache, getenv
@functools.cache
def get_imagenet_categories():
ci = json.load(open(BASEDIR / "imagenet_class_index.json"))
return {v[0]: i... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/efficientnet.py | extra/models/efficientnet.py | import math
from tinygrad.tensor import Tensor
from tinygrad.nn import BatchNorm2d
from tinygrad.helpers import get_child, fetch
from tinygrad.nn.state import torch_load
class MBConvBlock:
def __init__(self, kernel_size, strides, expand_ratio, input_filters, output_filters, se_ratio, has_se, track_running_stats=True... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/unet.py | extra/models/unet.py | from tinygrad import Tensor, dtypes, nn
from tinygrad.device import is_dtype_supported
from typing import Optional, Union, List, Any, Tuple, Callable
import math
# allow for monkeypatching
Linear, Conv2d, GroupNorm, LayerNorm = nn.Linear, nn.Conv2d, nn.GroupNorm, nn.LayerNorm
attention, gelu, mixed_precision_dtype = T... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/mask_rcnn.py | extra/models/mask_rcnn.py | import re
import math
import os
import numpy as np
from pathlib import Path
from tinygrad import nn, Tensor, dtypes
from tinygrad.tensor import _to_np_dtype
from tinygrad.helpers import get_child, fetch
from tinygrad.nn.state import torch_load
from examples.mlperf.helpers import BoxCoder
from extra.models.resnet import... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | true |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/bert.py | extra/models/bert.py | import re, os
from pathlib import Path
from tinygrad.tensor import Tensor, cast
from tinygrad import nn, dtypes
from tinygrad.helpers import fetch, get_child
from tinygrad.nn.state import get_parameters
# allow for monkeypatching
Embedding = nn.Embedding
Linear = nn.Linear
LayerNorm = nn.LayerNorm
class BertForQuesti... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/t5.py | extra/models/t5.py | # pip3 install sentencepiece
# adapted from https://github.com/huggingface/transformers/blob/main/src/transformers/models/t5/modeling_t5.py
# coding=utf-8
# Copyright 2018 Mesh TensorFlow authors, T5 Authors and HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not u... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/llama.py | extra/models/llama.py | from typing import Union, Optional, Any
import collections, math
from tinygrad import Tensor, Variable, TinyJit, dtypes, nn, Device
from tinygrad.helpers import getenv, DEBUG
# https://github.com/facebookresearch/llama/blob/1076b9c51c77ad06e9d7ba8a4c6df775741732bd/llama/model.py#L47
def precompute_freqs_cis(dim: int, ... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/retinanet.py | extra/models/retinanet.py | import math
from tinygrad import Tensor, dtypes
from tinygrad.helpers import flatten, get_child
from examples.mlperf.helpers import generate_anchors, BoxCoder
from examples.mlperf.losses import sigmoid_focal_loss, l1_loss
from extra.models.resnet import ResNet
import tinygrad.nn as nn
import numpy as np
ConvFPN = Conv... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/vit.py | extra/models/vit.py | import numpy as np
from tinygrad.tensor import Tensor
from tinygrad.helpers import fetch
from extra.models.transformer import TransformerBlock
class ViT:
def __init__(self, layers=12, embed_dim=192, num_heads=3):
self.embedding = (Tensor.uniform(embed_dim, 3, 16, 16), Tensor.zeros(embed_dim))
self.embed_dim ... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/inception.py | extra/models/inception.py | from tinygrad import Tensor
from tinygrad.nn import Conv2d, BatchNorm2d, Linear
from tinygrad.nn.state import load_state_dict, torch_load
from tinygrad.helpers import fetch
from typing import Optional, Dict
import numpy as np
from scipy import linalg
# Base Inception Model
class BasicConv2d:
def __init__(self, in_... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/unet3d.py | extra/models/unet3d.py | from pathlib import Path
import torch
from tinygrad import nn
from tinygrad.tensor import Tensor
from tinygrad.helpers import fetch, get_child
class DownsampleBlock:
def __init__(self, c0, c1, stride=2):
self.conv1 = [nn.Conv2d(c0, c1, kernel_size=(3,3,3), stride=stride, padding=(1,1,1,1,1,1), bias=False), nn.In... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/resnet.py | extra/models/resnet.py | import tinygrad.nn as nn
from tinygrad import Tensor, dtypes
from tinygrad.nn.state import torch_load
from tinygrad.helpers import fetch, get_child
# allow monkeypatching in layer implementations
BatchNorm = nn.BatchNorm2d
Conv2d = nn.Conv2d
Linear = nn.Linear
class BasicBlock:
expansion = 1
def __init__(self, ... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/convnext.py | extra/models/convnext.py | from tinygrad.tensor import Tensor
from tinygrad.nn import Conv2d, LayerNorm, LayerNorm2d, Linear
from tinygrad.helpers import fetch, get_child
class Block:
def __init__(self, dim):
self.dwconv = Conv2d(dim, dim, kernel_size=7, padding=3, groups=dim)
self.norm = LayerNorm(dim, eps=1e-6)
self.pwconv1 = Li... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/transformer.py | extra/models/transformer.py | from tinygrad import Tensor
class TransformerBlock:
def __init__(self, embed_dim, num_heads, ff_dim, prenorm=False, act=lambda x: x.relu(), dropout=0.1):
assert embed_dim % num_heads == 0, "embed_dim must be divisible by num_heads"
self.num_heads = num_heads
self.head_size = embed_dim // num_heads
s... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/rnnt.py | extra/models/rnnt.py | from tinygrad.tensor import Tensor
from tinygrad.engine.jit import TinyJit
from tinygrad.nn import Linear, Embedding
from tinygrad.helpers import fetch
import numpy as np
from pathlib import Path
class RNNT:
def __init__(self, input_features=240, vocab_size=29, enc_hidden_size=1024, pred_hidden_size=320, joint_hidd... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/models/clip.py | extra/models/clip.py | from tinygrad import Tensor, dtypes
from tinygrad.helpers import fetch
from tinygrad.nn import Linear, LayerNorm, Embedding, Conv2d
from typing import List, Optional, Union, Tuple, Dict
from abc import ABC, abstractmethod
from functools import lru_cache
from PIL import Image
import numpy as np
import re, gzip
# Allow... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/sqtt/attempt_sqtt_parse.py | extra/sqtt/attempt_sqtt_parse.py | import pickle, sys
from tinygrad.helpers import getenv, Timing, colored
from extra.sqtt.roc import decode, ProfileSQTTEvent
# do these enums match fields in the packets?
#from tinygrad.runtime.support.amd import import_soc
#soc = import_soc([11])
#perf_sel = {getattr(soc, k):k for k in dir(soc) if k.startswith("SQ_PER... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/sqtt/test_pmc.py | extra/sqtt/test_pmc.py | import os
os.environ["PROFILE"] = "1"
os.environ["PMC"] = "1"
import unittest
import functools, contextlib
import numpy as np
from tinygrad import Tensor, Context, Device
from tinygrad.dtype import dtypes, AddrSpace
from tinygrad.uop.ops import UOp, Ops, KernelInfo, AxisType
from tinygrad.runtime.ops_amd import Profil... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/sqtt/rgptool.py | extra/sqtt/rgptool.py | #!/usr/bin/env python3
from __future__ import annotations
import argparse, ctypes, struct, hashlib, pickle, code, typing, functools
import tinygrad.runtime.autogen.sqtt as sqtt
from tinygrad.device import ProfileEvent, ProfileDeviceEvent, ProfileProgramEvent
from tinygrad.runtime.ops_amd import ProfileSQTTEvent
from ti... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/sqtt/test_timing.py | extra/sqtt/test_timing.py | import os
os.environ["PYTHONPATH"] = "."
os.environ["SQTT"] = "1"
if "DEV" not in os.environ: os.environ["DEV"] = "AMD"
os.environ["PROFILE"] = "1"
# VIZ=1 to launch server
# os.environ["VIZ"] = "1"
os.environ["AMD_LLVM"] = "0"
import unittest
import sys, contextlib
from tinygrad import Tensor, dtypes
from tinygrad.he... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/sqtt/active_sqtt_parse.py | extra/sqtt/active_sqtt_parse.py | import os
os.environ["PYTHONPATH"] = "."
os.environ["SQTT"] = "1"
if "DEV" not in os.environ: os.environ["DEV"] = "AMD"
os.environ["PROFILE"] = "1"
os.environ["AMD_LLVM"] = "0"
from dataclasses import replace
import atexit, contextlib
from tinygrad import Tensor
from tinygrad.helpers import system, OSX
from tinygrad.r... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/sqtt/roc.py | extra/sqtt/roc.py | #!/usr/bin/env python3
import ctypes, pathlib, argparse, pickle, dataclasses, threading
from typing import Generator
from tinygrad.helpers import temp, unwrap, DEBUG
from tinygrad.runtime.ops_amd import ProfileSQTTEvent
from tinygrad.runtime.autogen import rocprof
@dataclasses.dataclass(frozen=True)
class InstExec:
... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/sqtt/install_sqtt_decoder.py | extra/sqtt/install_sqtt_decoder.py | #!/usr/bin/env python3
import os, shutil
from pathlib import Path
from tinygrad.helpers import fetch, OSX
DEST = Path("/usr/local/lib")
DEST.mkdir(exist_ok=True)
if __name__ == "__main__":
if OSX:
fp = fetch("https://github.com/ROCm/rocprof-trace-decoder/releases/download/0.1.4/rocprof-trace-decoder-macos-arm64... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/torch_hook/hook_torch.py | extra/torch_hook/hook_torch.py | import ctypes, struct, platform, pathlib, os, binascii, itertools
from hexdump import hexdump
from tinygrad.device import Device
from tinygrad import Tensor
from tinygrad.dtype import _from_torch_dtype
from tinygrad.helpers import to_mv, DEBUG, getenv, colored, time_to_str
import extra.torch_hook.hook_cuda as hook_cud... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
tinygrad/tinygrad | https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/torch_hook/hook_cuda.py | extra/torch_hook/hook_cuda.py | import ctypes, struct, platform, pathlib, os, binascii, itertools
from hexdump import hexdump
from tinygrad.helpers import to_mv, DEBUG, getenv, colored, time_to_str
from tinygrad.runtime.autogen import libc, cuda
from tinygrad.device import CPUProgram, Device
from tinygrad.runtime.support.elf import elf_loader
from ti... | python | MIT | bf356ae99621f42ad218b902ae7afdcb1f4a2f03 | 2026-01-04T14:43:17.197982Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.