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/external/external_metal_compile_fail.py
test/external/external_metal_compile_fail.py
# AssertionError: Error Domain=AGXMetalG15X_B0 Code=3 "Compiler encountered an internal error" src = """ #include <metal_stdlib> using namespace metal; kernel void r_64_32_8_16_4_6_6_4(device float* data0, const device float* data1, uint3 gid [[threadgroup_position_in_grid]], uint3 lid...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_process_count.py
test/external/external_test_process_count.py
import os, sys, time, multiprocessing N = int(os.environ.get("NPROC", str(os.cpu_count()))) DEVICE = os.environ.get("DEV", "AMD") # this tests the total number of processes that can be running tinygrad at a time def proc(i, device, stop_evt): from tinygrad import Tensor try: a = Tensor.ones(2, device=device)...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_multi_gpu.py
test/external/external_multi_gpu.py
#!/usr/bin/env python3 # cd extra/disassemblers/ && git clone --recursive github.com:geohot/cuda_ioctl_sniffer.git # LD_PRELOAD=$PWD/extra/disassemblers/cuda_ioctl_sniffer/out/sniff.so CL=1 python3 test/external/external_multi_gpu.py import numpy as np from tinygrad.tensor import Tensor from tinygrad.helpers import col...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_jit_on_models.py
test/external/external_test_jit_on_models.py
#!/usr/bin/env python import unittest import numpy as np from tinygrad import Tensor, dtypes from tinygrad.engine.jit import TinyJit from tinygrad.helpers import CI from test.helpers import derandomize_model from examples.llama import Transformer def helper_test_jitted_correctness(gen, train, train_jit): nojit = tr...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_onnx_backend.py
test/external/external_test_onnx_backend.py
import unittest from typing import Any, Tuple from onnx.backend.base import Backend, BackendRep import onnx.backend.test import numpy as np from tinygrad import Tensor, Device, dtypes from tinygrad.helpers import getenv, OSX from tinygrad.device import is_dtype_supported from tinygrad.nn.onnx import OnnxRunner # pip3 ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_image.py
test/external/external_test_image.py
#!/usr/bin/env python import os import unittest import numpy as np if 'IMAGE' not in os.environ: os.environ['IMAGE'] = '2' os.environ['CL'] = '1' os.environ['OPT'] = '2' from tinygrad.tensor import Tensor from tinygrad.nn import Conv2d class TestImage(unittest.TestCase): def test_create_image(self): t = Tensor...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_disk_raw.py
test/external/external_benchmark_disk_raw.py
import pathlib from tinygrad import Tensor, Device, Context from tinygrad.helpers import getenv if __name__ == "__main__": with Context(DEBUG=2): disk_llama = Tensor(pathlib.Path(getenv("TESTFILE", "/raid/weights/LLaMA-3/8B/consolidated.00.pth"))) device_llama = disk_llama.to(Device.DEFAULT).realize()
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/fuzz_kfd.py
test/external/fuzz_kfd.py
#!/usr/bin/env python3 import random from tqdm import trange from typing import List from tinygrad import Device from tinygrad.runtime.ops_amd import AMDDevice, HWQueue if __name__ == "__main__": dev: List[AMDDevice] = [Device[f"KFD:{i}"] for i in range(6)] print(f"got {len(dev)} devices") buffers = [(rd:=rando...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_losses.py
test/external/external_test_losses.py
from tinygrad import Tensor from test.external.mlperf_retinanet.focal_loss import sigmoid_focal_loss as ref_sigmoid_focal_loss from test.external.mlperf_unet3d.dice import DiceCELoss from examples.mlperf.losses import dice_ce_loss, sigmoid_focal_loss, l1_loss import numpy as np import torch import unittest class Exte...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_bert_softmax.py
test/external/external_benchmark_bert_softmax.py
from tinygrad import Tensor, dtypes, GlobalCounters dtypes.default_float = dtypes.float16 from tinygrad.dtype import to_dtype from tinygrad.helpers import getenv from test.test_softmax_fusion import single_kernel_softmax if __name__ == "__main__": # softmax in bert layers BS = getenv("BS", 96//6) acc_dtype = to_...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_pyrender.py
test/external/external_benchmark_pyrender.py
# benchmark speed of pyrender for all created UOps saved with TRACK_MATCH_STATS=2 import functools, pickle from tinygrad.uop.ops import UOp, Ops from tinygrad.helpers import tqdm, temp, time_to_str, cpu_profile BENCHMARK_OPS = {Ops.INDEX, Ops.BUFFERIZE} @functools.cache def create_uop(a:int) -> UOp: op, dtype, src,...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/fuzz_shape_ops.py
test/external/fuzz_shape_ops.py
from __future__ import annotations import unittest from math import prod from hypothesis import assume, given, settings, strategies as st from hypothesis.extra import numpy as stn import numpy as np import torch from tinygrad import Tensor from tinygrad.helpers import getenv settings.register_profile(__file__, sett...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_hcq.py
test/external/external_test_hcq.py
import unittest, ctypes, struct, time, array from tinygrad import Device, Tensor, dtypes from tinygrad.helpers import to_mv, CI from tinygrad.device import Buffer, BufferSpec from tinygrad.engine.realize import get_runner def _time_queue(q, d): st = time.perf_counter() q.signal(d.timeline_signal, d.timeline_value)...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_bert_matmuls.py
test/external/external_benchmark_bert_matmuls.py
from tinygrad import Tensor, dtypes dtypes.default_float = dtypes.float16 from tinygrad.dtype import to_dtype from tinygrad.helpers import getenv if __name__ == "__main__": # matmuls in bert layers BS = getenv("BS", 96//6) acc_dtype = to_dtype(getenv("ACC_DTYPE", "half")) tensors = [ (Tensor.empty(BS, 512,...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_metrics.py
test/external/external_test_metrics.py
from tinygrad import Tensor from test.external.mlperf_unet3d.dice import DiceScore from examples.mlperf.metrics import dice_score, log_perplexity import numpy as np import torch import unittest, math class ExternalTestMetrics(unittest.TestCase): def _test_metrics(self, tinygrad_metrics, orig_metrics, pred, label, a...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_fuzz_hcq_signals.py
test/external/external_fuzz_hcq_signals.py
import random from tinygrad import Device from tinygrad.helpers import getenv, DEBUG def main(): seed = getenv("SEED", 1337) n_gpus = getenv("GPUS", 3) iters = getenv("ITERS", 10000000) only_compute = bool(getenv("ONLY_COMPUTE", 0)) print(f"{n_gpus} GPUs for {iters} iterations, {only_compute=}, seed {seed}"...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_schedule.py
test/external/external_benchmark_schedule.py
from extra.models.resnet import ResNet50 from tinygrad import Tensor, nn, Device from tinygrad.helpers import Profiling, Timing, getenv from tinygrad.uop.ops import Ops from tinygrad.codegen import full_rewrite_to_sink from tinygrad.codegen.late.linearizer import linearize from tinygrad.uop.spec import type_verify, pro...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_dev_var.py
test/external/external_test_dev_var.py
import subprocess, unittest, os, sys from tinygrad.device import Device class TestTinygradSlow(unittest.TestCase): def test_env_overwrite_default_device(self): subprocess.run([f'{Device.DEFAULT}=1 python3 -c "from tinygrad import Device; assert Device.DEFAULT == \\"{Device.DEFAULT}\\""'], she...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_lm_head.py
test/external/external_test_lm_head.py
from tinygrad import Tensor, nn if __name__ == "__main__": vocab_size = 50257 n_embd = 768 lm_head = nn.Linear(n_embd, vocab_size, bias=False) bs = 4 seq_len = 1024 x = Tensor.rand(bs, seq_len, n_embd) ret = lm_head(x).realize()
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_speed_llama.py
test/external/external_test_speed_llama.py
# NOTE: this only tests the speed of the LLaMA codegen, it doesn't actually run the net import unittest, time from examples.llama import Transformer, MODEL_PARAMS from tinygrad.tensor import Tensor from tinygrad import Device from tinygrad.nn.state import get_state_dict from tinygrad.device import Allocator, Compiled f...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_resnet.py
test/external/external_benchmark_resnet.py
import functools import time import unittest from tinygrad import Tensor, TinyJit, GlobalCounters, Device from tinygrad.helpers import getenv, Context from tinygrad.nn.optim import SGD from tinygrad.nn.state import get_parameters from tinygrad.engine.realize import run_schedule from extra.models import resnet from ex...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_hip_compile.py
test/external/external_test_hip_compile.py
import time, unittest from tinygrad.runtime.support.hip_comgr import compile_hip from tinygrad import Tensor from tinygrad.device import Device from tinygrad.engine.schedule import create_schedule from tinygrad.codegen.opt.kernel import Kernel class TestHIPCompileSpeed(unittest.TestCase): @unittest.skipIf(Device.DEF...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_keccak.py
test/external/external_test_keccak.py
import unittest, zipfile, re from tinygrad import Tensor from tinygrad.helpers import fetch, tqdm SHA3_URL = "https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/sha3/sha-3bytetestvectors.zip" SHAKE_URL = "https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Vali...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_yolov8.py
test/external/external_test_yolov8.py
import numpy as np from examples.yolov8 import YOLOv8, get_variant_multiples, preprocess, label_predictions, postprocess from tinygrad import Tensor import unittest import io, cv2 import onnxruntime as ort import ultralytics from tinygrad.nn.state import safe_load, load_state_dict from tinygrad.helpers import fetch cl...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_kernel_launch.py
test/external/external_benchmark_kernel_launch.py
import time from tinygrad import Tensor, TinyJit, Device, Context from tinygrad.helpers import Profiling, Timing, GlobalCounters # python3 test/speed/external_test_speed_v_torch.py TestSpeed.test_add_a @TinyJit def plus(a:Tensor, b:Tensor): return a+b if __name__ == "__main__": a = Tensor([1]).realize() b = Tens...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_speed_theoretical.py
test/external/external_test_speed_theoretical.py
import time, unittest from tinygrad import Tensor, TinyJit, Device, dtypes from tinygrad.helpers import getenv, GlobalCounters SZMAX = getenv("SZMAX", 10) SZMIN = min(SZMAX, getenv("SZMIN", 10)) def _test(tcount, fxn, dtype=dtypes.float): print(f"**** testing {fxn.__name__} {dtype}") allgbs = [] for sz in range(...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_fuzz_ampt.py
test/external/external_fuzz_ampt.py
import random from typing import Optional from tinygrad.helpers import round_up from tinygrad.runtime.support.am.amdev import AMPageTableTraverseContext from test.external.external_test_am import helper_read_entry_components, FakeAM class AMPTFuzzer: def __init__(self, total_size): self.total_size = total_size ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_llama_schedule.py
test/external/external_benchmark_llama_schedule.py
from tinygrad import nn, Tensor, Device, dtypes from tinygrad.helpers import Timing from extra.models.llama import Transformer from examples.llama3 import MODEL_PARAMS if __name__ == "__main__": Device.DEFAULT = "NULL" Tensor.training = True #model_size = "8B" model_size = "405B" with Timing("total "): ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_simple_tokenizer.py
test/external/external_test_simple_tokenizer.py
import functools, multiprocessing from transformers import AutoTokenizer from datasets import load_dataset from tinygrad.apps.llm import SimpleTokenizer from tinygrad.helpers import tqdm, getenv, partition @functools.cache def get_tokenizers(): print("getting tokenizers") base_tokenizer = AutoTokenizer.from_pretra...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_tlsf.py
test/external/external_test_tlsf.py
import unittest from tinygrad.runtime.support.memory import TLSFAllocator class TestTLSFAllocator(unittest.TestCase): def setUp(self): self.allocator = TLSFAllocator(1024, block_size=16) def test_basic_alloc_free(self): addr1 = self.allocator.alloc(32) self.assertEqual(addr1, 0) addr2 = self.allo...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_model_benchmark.py
test/external/external_model_benchmark.py
import csv, pathlib, time import numpy as np import torch torch.set_num_threads(1) import onnxruntime as ort from onnx2torch import convert from tinygrad.nn.onnx import OnnxRunner from tinygrad.helpers import OSX, DEBUG, fetch, getenv from tinygrad.dtype import _to_np_dtype from tinygrad import Tensor, Device, dtypes ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_fuzz_tlsf.py
test/external/external_fuzz_tlsf.py
import random from typing import Dict, Optional from tinygrad.helpers import getenv from tinygrad.runtime.support.memory import TLSFAllocator class AllocatorFuzzer: def __init__(self, total_size): self.total_size = total_size self.alloc_payload = 0 self.mv = memoryview(bytearray(total_size)) self.all...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_keccak.py
test/external/external_benchmark_keccak.py
from tinygrad import Tensor, dtypes from tinygrad.engine.jit import TinyJit from tinygrad.helpers import Timing, getenv if __name__ == "__main__": BS = getenv("BS", 2**14) BLOCKSIZE = getenv("BLOCKSIZE", 4096) HASHFN = getenv("HASHFN", "shake_128") NRUNS = getenv("NRUNS", 5) @TinyJit def hasher(data: Tens...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_hcq_open.py
test/external/external_test_hcq_open.py
import os if "DEV" not in os.environ: os.environ["DEV"] = "AMD" import unittest, time from tinygrad import Device class TestOpen(unittest.TestCase): def generate_test_open(n): def test(self): dev = Device[Device.DEFAULT] for i in range(10): dev.allocator.alloc(10 << 20) time.sleep(0....
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_usb_asm24.py
test/external/external_test_usb_asm24.py
import unittest, time from tinygrad.runtime.support.usb import ASM24Controller from tinygrad.helpers import Timing from tinygrad import Tensor, Device import numpy as np class TestASMController(unittest.TestCase): @classmethod def setUpClass(cls): cls.ctrl = ASM24Controller() def test_write_and_read(self): ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_jit_failure.py
test/external/external_jit_failure.py
from tinygrad import Tensor, TinyJit, Device import numpy as np GPUS = 4 N = 128 ds = tuple([Device.canonicalize(f"{Device.DEFAULT}:{i}") for i in range(GPUS)]) t = Tensor.rand(N, N, N).shard(ds, 0) n = t.numpy() @TinyJit def allreduce(t:Tensor) -> Tensor: return t.sum(0) #.realize() for i in range(10): print(i)...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_datasets.py
test/external/external_test_datasets.py
from extra.datasets.kits19 import iterate, preprocess from examples.mlperf.dataloader import batch_load_unet3d, batch_load_retinanet from test.external.mlperf_retinanet.coco_utils import get_openimages from test.external.mlperf_retinanet.openimages import postprocess_targets from test.external.mlperf_retinanet.presets ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_multitensor_allreduce.py
test/external/external_benchmark_multitensor_allreduce.py
from tinygrad import Tensor, Device, GlobalCounters, TinyJit, dtypes from tinygrad.helpers import getenv, Context, DEBUG def test(devs: list[str], N: int, iters:int = 10, name:str = "allreduce"): @TinyJit def f(t: Tensor) -> Tensor: t.sum(0).realize() secs, gflops, gbs = 0, 0, 0 for i in range(-3, iters): ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/fuzz_symbolic.py
test/external/fuzz_symbolic.py
import random, operator import z3 from tinygrad import Variable, dtypes from tinygrad.uop.ops import UOp from tinygrad.uop.validate import uops_to_z3 from tinygrad.helpers import DEBUG, Context seed = random.randint(0, 100) print(f"Seed: {seed}") random.seed(seed) unary_ops = [lambda a:a+random.randint(-4, 4), lambda...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_unet3d/dice.py
test/external/mlperf_unet3d/dice.py
# https://github.com/mlcommons/training/blob/master/image_segmentation/pytorch/model/losses.py import torch import torch.nn as nn import torch.nn.functional as F class Dice: def __init__(self, to_onehot_y: bool = True, to_onehot_x: bool = False, use_softmax: bool = True...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_unet3d/kits19.py
test/external/mlperf_unet3d/kits19.py
# copied from https://github.com/mlcommons/training/blob/5c08ce57e7f582cc4558035d8324a2bf4c8ca225/image_segmentation/pytorch/data_loading/pytorch_loader.py import random import numpy as np import scipy.ndimage from torch.utils.data import Dataset from torchvision import transforms def get_train_transforms(): ran...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_bert/external_benchmark_bert.py
test/external/mlperf_bert/external_benchmark_bert.py
import unittest, time from tinygrad import Tensor, TinyJit, GlobalCounters, Device from tinygrad.helpers import getenv, Context from tinygrad.nn.optim import LAMB from tinygrad.nn.state import get_parameters from tinygrad.engine.realize import run_schedule from extra.models import bert bs = getenv("BS", 16) seq_len ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_bert/external_test_checkpoint_loading.py
test/external/mlperf_bert/external_test_checkpoint_loading.py
# Test whether pretrained weights from first BERT pretraining phase have been loaded correctly # Usage: # 1. Download the BERT checkoints with `wikipedia_download.py` # Command: BASEDIR=/path/to/wiki python3 wikipedia_download.py # 2. Run this script. (Adjust EVAL_BS and GPUS as needed) # Command: EVAL_BEAM=4 DEF...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_bert/preprocessing/create_pretraining_data.py
test/external/mlperf_bert/preprocessing/create_pretraining_data.py
# https://github.com/mlcommons/training/blob/1c8a098ae3e70962a4f7422c0b0bd35ae639e357/language_model/tensorflow/bert/cleanup_scripts/create_pretraining_data.py # NOTE: This is a direct copy of the original script # NOTE: With python 3.7.12, pip install tensorflow=1.15.5 """Create masked LM/next sentence masked_lm TF ex...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_bert/preprocessing/tokenization.py
test/external/mlperf_bert/preprocessing/tokenization.py
# https://github.com/mlcommons/training/blob/1c8a098ae3e70962a4f7422c0b0bd35ae639e357/language_model/tensorflow/bert/cleanup_scripts/tokenization.py # NOTE: This is a direct copy of the original script """Tokenization classes.""" from __future__ import absolute_import from __future__ import division from __future__ im...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_bert/preprocessing/external_test_preprocessing_part.py
test/external/mlperf_bert/preprocessing/external_test_preprocessing_part.py
# USAGE: # 1. Download raw text data with `wikipedia_download.py` # 2. Install python==3.7.12 and tensorflow==1.15.5 # Run `create_pretraining_data.py` to create TFRecords on specific part (This will take some time) # Command: python3 create_pretraining_data.py --input_file=/path/to/part-00XXX-of-00500 --voc...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_bert/preprocessing/pick_eval_samples.py
test/external/mlperf_bert/preprocessing/pick_eval_samples.py
# https://github.com/mlcommons/training/blob/1c8a098ae3e70962a4f7422c0b0bd35ae639e357/language_model/tensorflow/bert/cleanup_scripts/pick_eval_samples.py # NOTE: This is a direct copy of the original script """Script for picking certain number of sampels. """ import argparse import time import logging import collectio...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/process_replay/reset.py
test/external/process_replay/reset.py
#!/usr/bin/env python3 from tinygrad.helpers import db_connection, VERSION cur = db_connection() cur.execute(f"drop table if exists process_replay_{VERSION}")
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/process_replay/process_replay.py
test/external/process_replay/process_replay.py
#!/usr/bin/env python3 # compare kernels created by HEAD against master import os, multiprocessing, logging, pickle, sqlite3, difflib, warnings, itertools, functools, base64, codecs from dataclasses import replace from typing import Callable, Any ASSERT_DIFF = int((flag:="[pr]") in os.getenv("COMMIT_MESSAGE", flag) or...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_resnet/lars_optimizer.py
test/external/mlperf_resnet/lars_optimizer.py
# https://github.com/mlcommons/training/blob/e3769c8dcf88cd21e1001dd2f894b40a1513ec5d/image_classification/tensorflow2/lars_optimizer.py # changes: don't call lr_t if it's not a schedule # Copyright 2018 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_resnet/lars_util.py
test/external/mlperf_resnet/lars_util.py
# https://github.com/mlcommons/training/blob/e237206991d10449d9675d95606459a3cb6c21ad/image_classification/tensorflow2/lars_util.py # changes: commented out logging # changes: convert_to_tensor_v2 -> convert_to_tensor # changes: extend from tf.python.keras.optimizer_v2.learning_rate_schedule.LearningRateScheduler # Co...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_retinanet/presets.py
test/external/mlperf_retinanet/presets.py
# Copied from https://github.com/mlcommons/training/blob/637c82f9e699cd6caf108f92efb2c1d446b630e0/single_stage_detector/ssd/presets.py from test.external.mlperf_retinanet import transforms as T class DetectionPresetTrain: def __init__(self, data_augmentation, hflip_prob=0.5, mean=(123., 117., 104.)): if d...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_retinanet/coco_utils.py
test/external/mlperf_retinanet/coco_utils.py
# Copied from https://github.com/mlcommons/training/blob/637c82f9e699cd6caf108f92efb2c1d446b630e0/single_stage_detector/ssd/coco_utils.py import os import torch import torchvision from test.external.mlperf_retinanet import transforms as T class ConvertCocoPolysToMask(object): def __init__(self, filter_iscrowd=Tr...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_retinanet/focal_loss.py
test/external/mlperf_retinanet/focal_loss.py
# Copied from https://github.com/mlcommons/training/blob/cdd928d4596c142c15a7d86b2eeadbac718c8da2/single_stage_detector/ssd/model/focal_loss.py import torch import torch.nn.functional as F def sigmoid_focal_loss( inputs: torch.Tensor, targets: torch.Tensor, alpha: float = 0.25, gamma: float = 2, ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_retinanet/openimages.py
test/external/mlperf_retinanet/openimages.py
from test.external.mlperf_retinanet.model.boxes import box_iou from test.external.mlperf_retinanet.model.utils import Matcher import torch # This applies the filtering in https://github.com/mlcommons/training/blob/cdd928d4596c142c15a7d86b2eeadbac718c8da2/single_stage_detector/ssd/model/retinanet.py#L117 # and https:/...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_retinanet/transforms.py
test/external/mlperf_retinanet/transforms.py
# Copied from https://github.com/mlcommons/training/blob/637c82f9e699cd6caf108f92efb2c1d446b630e0/single_stage_detector/ssd/transforms.py import torch import torchvision from torch import nn, Tensor from torchvision.transforms import functional as F from torchvision.transforms import transforms as T from typing impor...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_retinanet/model/transform.py
test/external/mlperf_retinanet/model/transform.py
# Copied from https://github.com/mlcommons/training/blob/637c82f9e699cd6caf108f92efb2c1d446b630e0/single_stage_detector/ssd/model/transform.py import torch from torch import nn, Tensor from typing import List, Tuple, Dict, Optional from test.external.mlperf_retinanet.model.image_list import ImageList @torch.jit.unu...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_retinanet/model/utils.py
test/external/mlperf_retinanet/model/utils.py
# Copied from https://github.com/mlcommons/training/blob/637c82f9e699cd6caf108f92efb2c1d446b630e0/single_stage_detector/ssd/model/utils.py import torch class Matcher(object): """ This class assigns to each predicted "element" (e.g., a box) a ground-truth element. Each predicted element will have exactly z...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_retinanet/model/boxes.py
test/external/mlperf_retinanet/model/boxes.py
# Copied from https://github.com/mlcommons/training/blob/637c82f9e699cd6caf108f92efb2c1d446b630e0/single_stage_detector/ssd/model/boxes.py import torch from torch import Tensor from typing import Tuple def _upcast(t: Tensor) -> Tensor: # Protects from numerical overflows in multiplications by upcasting to the equ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_retinanet/model/image_list.py
test/external/mlperf_retinanet/model/image_list.py
# Copied from https://github.com/mlcommons/training/blob/637c82f9e699cd6caf108f92efb2c1d446b630e0/single_stage_detector/ssd/model/image_list.py import torch from torch import Tensor from typing import List, Tuple class ImageList(object): """ Structure that holds a list of images (of possibly varying size...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/sglang_llama/external_llama_eval.py
test/external/sglang_llama/external_llama_eval.py
from lm_eval import simple_evaluate from lm_eval.api.instance import Instance from lm_eval.api.model import LM from lm_eval.tasks import TaskManager from pathlib import Path import json, argparse from examples.llama3 import build_transformer, Tokenizer, MODEL_PARAMS from tinygrad import Tensor, Device from tinygrad.he...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_stable_diffusion/external_test_train.py
test/external/mlperf_stable_diffusion/external_test_train.py
import unittest, os from tempfile import TemporaryDirectory from tinygrad import Tensor from tinygrad.helpers import getenv from examples.mlperf.model_train import train_stable_diffusion class TestTrain(unittest.TestCase): def test_train_to_ckpt(self): # train for num_steps, save checkpoint, and stop training ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_stable_diffusion/external_test_eval.py
test/external/mlperf_stable_diffusion/external_test_eval.py
import unittest, os import numpy as np from pathlib import Path from tempfile import TemporaryDirectory from tinygrad import Device, Tensor from tinygrad.helpers import getenv, Context from tinygrad.nn.state import safe_save, torch_load, get_parameters from examples.mlperf.model_eval import eval_stable_diffusion, vae_d...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/mlperf_stable_diffusion/external_test_models.py
test/external/mlperf_stable_diffusion/external_test_models.py
import unittest import numpy as np from pathlib import Path from tinygrad import Tensor, dtypes, Device from tinygrad.helpers import getenv from tinygrad.nn.state import get_parameters from extra.models import clip from examples.mlperf.initializers import gelu_erf, init_stable_diffusion, attn_f32_softmax from typing im...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/mockgpu/gpu.py
test/mockgpu/gpu.py
class VirtGPU: def __init__(self, gpuid): self.gpuid = gpuid def map_range(self, vaddr, size): raise NotImplementedError() def unmap_range(self, vaddr, size): raise NotImplementedError()
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/mockgpu/driver.py
test/mockgpu/driver.py
from typing import Any from dataclasses import dataclass class VirtFileDesc: def __init__(self, fd): self.fd, self.off = fd, 0 def ioctl(self, fd, req, argp): raise NotImplementedError() def mmap(self, st, sz, prot, flags, fd, off): raise NotImplementedError() def close(self, fd): return 0 class TextFileDesc(...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/mockgpu/helpers.py
test/mockgpu/helpers.py
import ctypes, ctypes.util from tinygrad.helpers import getenv def _try_dlopen_gpuocelot(): GPUOCELOT_PATHS = [ctypes.util.find_library("gpuocelot")] if ctypes.util.find_library("gpuocelot") is not None else [] GPUOCELOT_PATHS += ["libgpuocelot.so", "/usr/local/lib/libgpuocelot.so", "libgpuoc...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/mockgpu/usb.py
test/mockgpu/usb.py
class MockUSB: def __init__(self, mem): self.mem = mem def read(self, address, size): return bytes(self.mem[address:address+size]) def write(self, address, data, ignore_cache=False): self.mem[address:address+len(data)] = data def pcie_mem_req(self, address, value=None, size=1): if value is No...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/mockgpu/mockgpu.py
test/mockgpu/mockgpu.py
import ctypes, ctypes.util, time, os, builtins, fcntl from tinygrad.runtime.support.hcq import FileIOInterface from test.mockgpu.nv.nvdriver import NVDriver from test.mockgpu.amd.amddriver import AMDDriver start = time.perf_counter() # *** ioctl lib *** libc = ctypes.CDLL(ctypes.util.find_library("c")) libc.mmap.argty...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/mockgpu/amd/amdgpu.py
test/mockgpu/amd/amdgpu.py
import ctypes, time from test.mockgpu.gpu import VirtGPU from test.mockgpu.helpers import _try_dlopen_remu from tinygrad.helpers import getbits, to_mv, init_c_struct_t import tinygrad.runtime.autogen.amd_gpu as amd_gpu, tinygrad.runtime.autogen.am.pm4_nv as pm4 SDMA_MAX_COPY_SIZE = 0x400000 regCOMPUTE_PGM_LO = 0x1bac...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/mockgpu/amd/amddriver.py
test/mockgpu/amd/amddriver.py
import pathlib, re, ctypes, mmap, collections, functools, copy, os import tinygrad.runtime.autogen.kfd as kfd import tinygrad.runtime.autogen.am.am as am from tinygrad.helpers import from_mv from test.mockgpu.driver import VirtDriver, VirtFileDesc, TextFileDesc, DirFileDesc, VirtFile from test.mockgpu.amd.amdgpu import...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/mockgpu/nv/nvgpu.py
test/mockgpu/nv/nvgpu.py
import ctypes, time from tinygrad.runtime.autogen import nv_570 as nv_gpu from enum import Enum, auto from test.mockgpu.gpu import VirtGPU from test.mockgpu.helpers import _try_dlopen_gpuocelot from tinygrad.helpers import to_mv, init_c_struct_t def make_qmd_struct_type(): fields = [] bits = [(name,dt) for name,dt...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/mockgpu/nv/nvdriver.py
test/mockgpu/nv/nvdriver.py
import ctypes, mmap, collections, functools, os from tinygrad.runtime.autogen import nv_570 as nv_gpu from typing import Any from tinygrad.helpers import to_mv from test.mockgpu.driver import VirtDriver, VirtFileDesc, VirtFile from test.mockgpu.nv.nvgpu import NVGPU MAP_FIXED = 0x10 libc = ctypes.CDLL(ctypes.util.find...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/mockgpu/cuda/cuda.py
test/mockgpu/cuda/cuda.py
from __future__ import annotations from typing import Any import ctypes, time from tinygrad.runtime.autogen import cuda as orig_cuda from test.mockgpu.helpers import _try_dlopen_gpuocelot from tinygrad.helpers import mv_address for attr in dir(orig_cuda): if not attr.startswith('__'): globals()[attr] = getattr(o...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_dtype_spec.py
test/unit/test_dtype_spec.py
import unittest, math, operator, subprocess, struct from tinygrad.tensor import Tensor, dtypes, Device from tinygrad.dtype import DType, DTYPES_DICT, truncate, float_to_fp16, float_to_bf16, _to_np_dtype, least_upper_dtype, least_upper_float from tinygrad.device import is_dtype_supported from tinygrad.helpers import get...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_symbolic_failures.py
test/unit/test_symbolic_failures.py
import unittest from tinygrad import Variable from tinygrad.helpers import Context class TestFuzzFailure(unittest.TestCase): def setUp(self): self.context = Context(CORRECT_DIVMOD_FOLDING=1) self.context.__enter__() def tearDown(self): self.context.__exit__(None, None, None) def test_fuzz_failure1...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_tar.py
test/unit/test_tar.py
import unittest, tarfile, io, os, pathlib, tempfile import numpy as np from tinygrad import Tensor from tinygrad.nn.state import tar_extract class TestTarExtractFile(unittest.TestCase): def setUp(self): self.test_dir = tempfile.mkdtemp() self.test_files = { 'file1.txt': b'Hello, World!', 'file2.b...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_rewrite_map.py
test/unit/test_rewrite_map.py
import unittest from tinygrad import dtypes from tinygrad.uop.ops import UOp, graph_rewrite_map, _substitute from tinygrad.uop.symbolic import symbolic class TestRewriteMap(unittest.TestCase): def test_substitute(self): a = UOp.variable('a', 0, 10) b = UOp.variable('b', 0, 10) c = UOp.variable('c', 0, 10...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_viz.py
test/unit/test_viz.py
import unittest, decimal, json, struct from dataclasses import dataclass from typing import Generator from tinygrad.uop.ops import UOp, UPat, Ops, PatternMatcher, TrackedPatternMatcher, graph_rewrite, track_rewrites, TRACK_MATCH_STATS, profile_matches from tinygrad.uop.symbolic import sym from tinygrad.dtype import dt...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_tensor_uop_representation.py
test/unit/test_tensor_uop_representation.py
import unittest from tinygrad import Tensor from tinygrad.uop.ops import UPat, Ops, UOp # NOTE: unlike before base for a realized tensor is always a BUFFER realized_pattern = UPat(Ops.BUFFER) def is_pattern_uop(u:UOp, pat:UPat): assert pat.match(u, {}), f"{u}\nis not\n{pat}" def is_pattern(ten:Tensor, pat:UPat): is_pa...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_tqdm.py
test/unit/test_tqdm.py
import time, random, unittest, itertools from unittest.mock import patch from io import StringIO from collections import namedtuple from tqdm import tqdm from tinygrad.helpers import tqdm as tinytqdm, trange import numpy as np def _get_iter_per_second(raw:str) -> float: # raw might have unit scale if raw.endswith(...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_schedule_cache.py
test/unit/test_schedule_cache.py
import unittest from tinygrad import Tensor, Variable from tinygrad.engine.schedule import schedule_cache class TestScheduleCache(unittest.TestCase): def test_bound_variable_reuses_cache(self): schedule_cache.clear() v = Variable('v', 1, 100) x = Tensor.ones(10).contiguous().realize() # first run wi...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_pattern_matcher.py
test/unit/test_pattern_matcher.py
import unittest, itertools from tinygrad.dtype import dtypes from tinygrad.uop.ops import Ops, UOp, GroupOp # noqa: F401 from tinygrad.uop.ops import PatternMatcher, UPat class TestPatternMatcher(unittest.TestCase): def test_simple_match(self): matcher = PatternMatcher([(UPat(Ops.CONST, name="x", dtype=dtypes.fl...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_masked_tensor.py
test/unit/test_masked_tensor.py
import unittest from tinygrad.tensor import Tensor class TestMaskedTensor(unittest.TestCase): def test_mul_masked(self): a = Tensor([1,1,1,1,1]) b = Tensor([1,1]).pad(((0,3),)) c = a*b assert c.shape == a.shape ret = c.data() assert ret.tolist() == [1.0, 1.0, 0.0, 0.0, 0.0] def test_mul_bo...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_llm_moe.py
test/unit/test_llm_moe.py
import unittest import numpy as np from tinygrad import Tensor class TestMoEFeedForward(unittest.TestCase): def test_moe_feed_forward(self): from tinygrad.apps.llm import TransformerBlock dim, hidden, n_heads = 8, 16, 2 num_experts, k = 4, 2 block = TransformerBlock(dim, hidden, n_heads, n_heads, no...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_allreduce.py
test/unit/test_allreduce.py
import unittest from tinygrad import Tensor from tinygrad.helpers import Context from tinygrad.uop.ops import Ops class TestRingAllReduce(unittest.TestCase): def test_schedule_ring(self): with Context(RING=2): N = 4 ds = tuple(f"CPU:{i}" for i in range(N)) t = Tensor.empty(N, N*100).shard(ds, a...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_linearizer_rewrite.py
test/unit/test_linearizer_rewrite.py
import unittest from tinygrad import Tensor, Context, Device from tinygrad.engine.realize import get_program from tinygrad.codegen.opt import Opt, OptOps from tinygrad.uop.ops import KernelInfo class TestLinearizerRewrite(unittest.TestCase): def test_reduction(self): t = Tensor.ones((64,64), device="NULL").conti...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_indexing.py
test/unit/test_indexing.py
# test cases are modified from pytorch test_indexing.py https://github.com/pytorch/pytorch/blob/597d3fb86a2f3b8d6d8ee067e769624dcca31cdb/test/test_indexing.py import unittest, random, warnings import numpy as np from tinygrad import Tensor, dtypes, Device, TinyJit from tinygrad.device import is_dtype_supported from t...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_llm_tokenizer.py
test/unit/test_llm_tokenizer.py
import unittest, base64, functools, sys from tinygrad.apps.llm import SimpleTokenizer from tinygrad.helpers import fetch @unittest.skipIf(sys.platform == 'win32', "fetch race condition on Windows") class TestLLMTokenizer(unittest.TestCase): @functools.cached_property def llama_tok(self): # from https://github....
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_device.py
test/unit/test_device.py
#!/usr/bin/env python import unittest, os, subprocess from tinygrad import Tensor from tinygrad.device import Device, Compiler, enumerate_devices_str from tinygrad.helpers import diskcache_get, diskcache_put, getenv, Context, WIN, CI class TestDevice(unittest.TestCase): def test_canonicalize(self): self.assertEq...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_linalg.py
test/unit/test_linalg.py
import unittest, functools from tinygrad import Tensor, Context import numpy as np def orthogonality_helper(A:Tensor, tolerance=1e-5): b_shape,m = A.shape[0:-2],A.shape[-2] #outer dimension should be the dim along orthogonality A_identity = (Tensor.eye(m).reshape((1,)*len(b_shape)+(m,m)).expand(b_shape+(m,m))) ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_uop_vmin_vmax.py
test/unit/test_uop_vmin_vmax.py
import unittest, math from tinygrad.uop.ops import UOp, Ops from tinygrad.dtype import dtypes, Invalid class TestVminVmaxProperties(unittest.TestCase): def test_vmin_vmax_constant(self): # vmin and vmax for a constant uop = UOp.const(dtypes.int32, 42) self.assertEqual(uop.vmin, 42) self.assertEqual(u...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_transcendental_helpers.py
test/unit/test_transcendental_helpers.py
import unittest, math import numpy as np from tinygrad import dtypes from tinygrad.uop.ops import UOp, Ops from tinygrad.uop.decompositions import TRANSCENDENTAL_DTYPES, payne_hanek_reduction, cody_waite_reduction from tinygrad.uop.decompositions import frexp, rintk, xpow, xexp2, xlog2, trig_poly, pow2if from test.help...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_uop_repr.py
test/unit/test_uop_repr.py
import unittest from tinygrad import UOp, dtypes class TestUOpRepr(unittest.TestCase): def test_simple_const(self): a = UOp.const(dtypes.int, 42) self.assertEqual(repr(a), "UOp(Ops.CONST, dtypes.int, arg=42, src=())") def test_different_consts(self): a, b = UOp.const(dtypes.int, 42), UOp.const(dtypes.i...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_mnist_dataset.py
test/unit/test_mnist_dataset.py
import unittest from tinygrad.helpers import GlobalCounters from tinygrad.nn.datasets import mnist class TestDataset(unittest.TestCase): def test_dataset_is_realized(self): X_train, _, _, _ = mnist() X_train[0].contiguous().realize() start = GlobalCounters.kernel_count X_train[0].contiguous().realize...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_elf.py
test/unit/test_elf.py
import unittest, subprocess, platform from tinygrad.runtime.support.compiler_cpu import ClangJITCompiler from tinygrad.runtime.support.elf import elf_loader class TestElfLoader(unittest.TestCase): def test_load_clang_jit_strtab(self): src = ''' int something; // will be a load from a relocation (needed for...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_uop_resolve.py
test/unit/test_uop_resolve.py
import unittest from tinygrad.dtype import dtypes from tinygrad.uop.ops import UOp, resolve class TestUOpResolve(unittest.TestCase): def test_simple_int(self): u = UOp.const(dtypes.int, 4) self.assertEqual(int(u), 4) def test_int_add(self): u = UOp.const(dtypes.int, 4) + 7 self.assertEqual(int(u),...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_graph_rewrite.py
test/unit/test_graph_rewrite.py
import unittest, math from tinygrad import dtypes from tinygrad.helpers import all_same, Context from tinygrad.uop.ops import GroupOp, UOp, Ops, exec_alu, PatternMatcher, TrackedPatternMatcher, UPat from tinygrad.codegen import full_rewrite_to_sink from hypothesis import given, strategies as strat # Helper function to...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_gguf.py
test/unit/test_gguf.py
import os, unittest, ctypes from tinygrad import dtypes, Tensor, fetch, Device import numpy as np from tinygrad.nn.state import ggml_data_to_tensor, gguf_load from tinygrad.device import is_dtype_supported try: import ggml except ModuleNotFoundError: raise unittest.SkipTest("ggml not installed, skipping gguf test")...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/unit/test_gradient.py
test/unit/test_gradient.py
from typing import Callable import unittest, math import torch import numpy as np from tinygrad import Tensor from tinygrad.dtype import dtypes from tinygrad.uop.ops import UOp from tinygrad.gradient import compute_gradient class TestGradient(unittest.TestCase): def _cmp_nan_okay(self, x, y): if math.isnan(x) an...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false