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/test_symbolic_jit.py
test/test_symbolic_jit.py
import unittest from test.helpers import assert_jit_cache_len from tinygrad import Variable, Tensor, TinyJit import numpy as np class TestSymbolicJit(unittest.TestCase): def test_plus1(self): def f(a): return (a+1).realize() jf = TinyJit(f) a = Tensor.rand(3, 10) for i in range(1, 5): vi = Var...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_randomness.py
test/test_randomness.py
import unittest, math from functools import partial from tinygrad import nn, dtypes, Tensor, Device, TinyJit, Variable from tinygrad.helpers import getenv, CI, OSX from tinygrad.device import is_dtype_supported from tinygrad.engine.realize import CompiledRunner from tinygrad.renderer.ptx import PTXRenderer from tinygr...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_to_numpy.py
test/test_to_numpy.py
from tinygrad.tensor import Tensor import numpy as np import pickle import unittest class TestToNumpy(unittest.TestCase): def test_numpy_is_numpy(self): output = Tensor.ones((1, 3, 4096)).realize().numpy() new = np.copy(output) print(type(new)) serialized = pickle.dumps(new) out = pickle.loads(se...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_jit.py
test/test_jit.py
#!/usr/bin/env python import unittest, functools import numpy as np from hypothesis import given, settings, strategies as strat from test.helpers import assert_jit_cache_len, not_support_multi_device, REAL_DEV, needs_second_gpu from tinygrad.tensor import Tensor from tinygrad.engine.jit import TinyJit, GraphRunner, Mu...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_renderer_failures.py
test/test_renderer_failures.py
import unittest import numpy as np from dataclasses import replace from tinygrad.device import Buffer, Device, is_dtype_supported from tinygrad.dtype import dtypes, ConstType from tinygrad.engine.realize import CompiledRunner, get_program from tinygrad.helpers import prod from tinygrad.renderer.cstyle import CStyleLang...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_graph.py
test/test_graph.py
import numpy as np import functools, unittest, ctypes from tinygrad.device import Device, Buffer from tinygrad.tensor import Tensor, _to_np_dtype from tinygrad.helpers import Context, dedup, from_mv from tinygrad.dtype import dtypes from tinygrad.engine.jit import MultiGraphRunner from tinygrad.engine.realize import B...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/helpers.py
test/helpers.py
import os, time, struct, functools, unittest from typing import Any, Callable import numpy as np from tinygrad import Tensor, dtypes, Device from tinygrad.uop.ops import UOp, Ops, KernelInfo from tinygrad.tensor import _to_np_dtype from tinygrad.engine.realize import Runner, get_program from tinygrad.dtype import DType...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_opts.py
test/test_opts.py
import unittest from tinygrad import Tensor, Device from tinygrad.helpers import CPU_LLVM, CPU_LVP from tinygrad.codegen.opt import Opt, OptOps from tinygrad.engine.realize import get_program class TestOpts(unittest.TestCase): def test_opt_upcast(self): opts = (Opt(OptOps.UPCAST, 0, 4),) a = Tensor.empty(16)...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_kernel_cache.py
test/test_kernel_cache.py
#!/usr/bin/env python import unittest from tinygrad.tensor import Tensor from tinygrad import Device class TestKernelCache(unittest.TestCase): def test_kernel_cache_in_action(self): if Device.DEFAULT not in ["CPU"]: self.skipTest("No custom kernel cache is implemented") unique_const = 0.6765677269 ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_ops.py
test/test_ops.py
import time, math, unittest, functools, platform, warnings import numpy as np from typing import List, Callable import torch from tinygrad.helpers import getenv, IMAGE, DEBUG, CI, Context, CPU_LLVM, CPU_LVP, AMD_LLVM, EMULATE from tinygrad import Tensor, Device, dtypes from tinygrad.tensor import _to_np_dtype from tiny...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_compile_failures.py
test/test_compile_failures.py
import unittest, io from contextlib import redirect_stdout from tinygrad import Tensor, dtypes, Device from tinygrad.helpers import OSX, CPU_LLVM, CPU_LVP from tinygrad.device import is_dtype_supported from tinygrad.engine.realize import get_program class TestCompileFailures(unittest.TestCase): def compile(self, out...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_method_cache.py
test/test_method_cache.py
import unittest from tinygrad import Tensor, Device, Variable from examples.gpt2 import Transformer from tinygrad.nn.state import get_state_dict class TestMethodCache(unittest.TestCase): def setUp(self): self.backup_compiler = Device[Device.DEFAULT].compiler.compile_cached def tearDown(self): Device[Device...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/__init__.py
test/__init__.py
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_linearizer_dumb.py
test/test_linearizer_dumb.py
# ruff: noqa: E501 # tests where the Linearizer is doing something dumb # like test_linearizer_failures, but they don't have to fail import unittest from tinygrad import Device, dtypes from tinygrad.uop.ops import UOp, Ops, AxisType, KernelInfo from tinygrad.codegen.opt.search import Opt, OptOps from tinygrad.engine.r...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_fusion_op.py
test/test_fusion_op.py
import unittest import time import numpy as np from tinygrad import Tensor, dtypes from tinygrad.engine.realize import run_schedule class TestFusionOp(unittest.TestCase): def test_contiguous_add(self): def test(contig=False): bt = Tensor(np.arange(16), dtype=dtypes.float32).reshape(4,4) x = bt.permut...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_schedule.py
test/test_schedule.py
# this will be the new test_ops for the next level # schedule confirms the right things are capable of fusing # NOTE: this has overlap with external_test_opt.py import unittest, functools import numpy as np from typing import cast from hypothesis import assume, given, settings, strategies as strat from tinygrad impor...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_symbolic_ops.py
test/test_symbolic_ops.py
import unittest from tinygrad import Tensor, Variable, GlobalCounters from tinygrad.uop.ops import sym_infer from tinygrad.dtype import dtypes from tinygrad.device import is_dtype_supported from examples.gpt2 import Attention import numpy as np class TestSymbolicOps(unittest.TestCase): def test_plus1(self): def ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_nn.py
test/test_nn.py
#!/usr/bin/env python import unittest import numpy as np import torch from tinygrad import Tensor, Device, TinyJit, dtypes from tinygrad.uop.ops import Ops from tinygrad.helpers import GlobalCounters, Context from tinygrad.nn import Conv1d, ConvTranspose1d, Conv2d, ConvTranspose2d, Linear, Embedding from tinygrad.nn im...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_jit_cases.py
test/test_jit_cases.py
import unittest from tinygrad import TinyJit, Tensor # The JIT functions as a "capturing" JIT. # Whatever kernels ran in the JIT the second run through the function will be the kernels that will run from then on. # Explicit inputs to the function are updated in the JIT graph to the new inputs. # JITs have four tensor...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_pickle.py
test/test_pickle.py
import unittest, pickle, types import numpy as np from tinygrad import Tensor, TinyJit, Variable, dtypes from tinygrad.helpers import GlobalCounters, ContextVar, Context from tinygrad.uop.ops import PatternMatcher, UPat, UOp class TestPickle(unittest.TestCase): def test_pickle_code_object(self): y = lambda x: x*...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_edgecases.py
test/test_edgecases.py
# end to end tests of tinygrad that you think might be edge cases. # using the documentation, write code you think should work. # you can compare the outputs to torch or numpy, or just tinygrad assert/raise while doing things that should be valid # i'm not interested in tests that currently pass, i'm only interested i...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_jit_footguns.py
test/test_jit_footguns.py
#!/usr/bin/env python """ JIT Footguns: Documenting unexpected behavior changes when using @TinyJit Each test shows behavior that works without JIT but changes with JIT. Comments marked "should be X!" indicate the intuitively expected value. SILENT MISMATCHES (highest priority - wrong results, no error): tensors_in...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_uop_graph.py
test/test_uop_graph.py
import unittest, pytest from tinygrad import dtypes, Variable from tinygrad.dtype import AddrSpace from tinygrad.helpers import DEBUG, Context from tinygrad.uop.ops import Ops, UOp, UPat, PatternMatcher, track_rewrites, graph_rewrite, GroupOp, AxisType from tinygrad.uop.symbolic import sym from tinygrad.codegen.late.ex...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_setitem.py
test/test_setitem.py
import unittest import random from os import getenv from tinygrad import Tensor, TinyJit, Variable, dtypes from tinygrad.helpers import Context import numpy as np class TestSetitem(unittest.TestCase): def test_simple_setitem(self): cases = ( ((6,6), (slice(2,4), slice(3,5)), Tensor.ones(2,2)), ((6,6)...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_profiler.py
test/test_profiler.py
import unittest, struct, contextlib, statistics, time, gc from tinygrad import Device, Tensor, dtypes, TinyJit from tinygrad.helpers import CI, getenv, Context, ProfileRangeEvent, cpu_profile, cpu_events, ProfilePointEvent, dedup from tinygrad.device import Buffer, BufferSpec, Compiled, ProfileDeviceEvent, ProfileGraph...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_softmax_fusion.py
test/test_softmax_fusion.py
import unittest import numpy as np from tinygrad import Tensor, GlobalCounters, Context, Device from tinygrad.dtype import DTypeLike, dtypes from tinygrad.helpers import DEBUG, get_single_element from tinygrad.device import is_dtype_supported def single_kernel_softmax(x_in:Tensor, axis=-1, dtype:DTypeLike|None=None) -...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_linearizer.py
test/test_linearizer.py
import numpy as np import unittest from dataclasses import replace from tinygrad.codegen.opt import Opt, OptOps from tinygrad.codegen.gpudims import get_grouped_dims from tinygrad.uop.ops import UOp, Ops, GroupOp, AxisType, PatternMatcher, graph_rewrite, UPat from tinygrad.device import Device, Buffer, is_dtype_suppor...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_arange.py
test/test_arange.py
import unittest import numpy as np from tinygrad import Tensor, GlobalCounters, dtypes, nn, Device, Variable from tinygrad.helpers import Context, getenv from tinygrad.engine.realize import run_schedule from tinygrad.engine.realize import CompiledRunner, get_program from tinygrad.engine.schedule import ExecItem from ti...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_outerworld.py
test/test_outerworld.py
import unittest import numpy as np from tinygrad import Tensor, UOp, nn from tinygrad.uop.ops import AxisType, Ops class TestOuterworldReduce(unittest.TestCase): def test_reduce(self): x = Tensor.ones(5, 5).contiguous() a = UOp.range(5, -1, AxisType.REDUCE) out = x[a] # TODO: syntax for this t = ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_image_dtype.py
test/test_image_dtype.py
import unittest import numpy as np from tinygrad import Device, dtypes, Tensor, Context from tinygrad.device import LRUAllocator, is_dtype_supported from tinygrad.dtype import ImageDType from tinygrad.helpers import prod, unwrap from test.helpers import REAL_DEV IMAGE_SUPPORTED_DEVICES = ("QCOM", "CL") @unittest.skip...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_uops_stats.py
test/test_uops_stats.py
import unittest from tinygrad import Tensor from tinygrad.helpers import getenv, GlobalCounters, EMULATE from tinygrad.engine.realize import get_program from tinygrad.renderer import ProgramSpec from tinygrad.renderer import Estimates from tinygrad.uop.ops import Ops, UOp from tinygrad.dtype import dtypes from tinygrad...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_gc.py
test/test_gc.py
#!/usr/bin/env python import gc, inspect import unittest import numpy as np from tinygrad.device import Buffer from tinygrad.engine.realize import run_schedule from tinygrad.uop.ops import UOp from tinygrad.tensor import Tensor def _allocations_of_type(t): ret = 0 for x in gc.get_objects(): try: if isins...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/test_linearizer_failures.py
test/test_linearizer_failures.py
# ruff: noqa: E501 import unittest from tinygrad.uop.ops import UOp, Ops, AxisType from tinygrad.dtype import dtypes from tinygrad.engine.realize import get_program from tinygrad.device import Device class TestLinearizerFailures(unittest.TestCase): def test_fail_1(self): c0 = UOp(Ops.DEFINE_GLOBAL, dtypes.float....
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/speed/external_test_speed_v_torch.py
test/speed/external_test_speed_v_torch.py
import os os.environ["NVIDIA_TF32_OVERRIDE"] = "0" os.environ["MKL_NUM_THREADS"] = "1" os.environ["NUMEXPR_NUM_THREADS"] = "1" os.environ["OMP_NUM_THREADS"] = "1" os.environ["VECLIB_MAXIMUM_THREADS"] = "1" import unittest import torch torch.set_num_threads(1) import time import numpy as np np.set_printoptions(linewidth...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/speed/external_test_specific_conv.py
test/speed/external_test_specific_conv.py
import unittest from tinygrad.helpers import CI from tinygrad import Tensor, Device, dtypes from tinygrad.device import is_dtype_supported # similar to test/external/external_test_gpu_ast.py, but universal @unittest.skipIf(Device.DEFAULT in {"CUDA", "NV"} and CI, "slow on CUDA CI") class TestSpecific(unittest.TestCase...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/speed/external_test_copy_speed.py
test/speed/external_test_copy_speed.py
import unittest, numpy as np from tinygrad import Tensor, Device, TinyJit from tinygrad.helpers import Timing, CI, OSX, getenv import multiprocessing.shared_memory as shared_memory N = getenv("NSZ", 256) class TestCopySpeed(unittest.TestCase): @classmethod def setUpClass(cls): Device[Device.DEFAULT].synchronize() ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/speed/external_test_device_speed.py
test/speed/external_test_device_speed.py
import unittest from tinygrad import Device from tinygrad.helpers import Timing, Profiling class TestDeviceSpeed(unittest.TestCase): @classmethod def setUpClass(cls): cls.dev = Device[Device.DEFAULT] cls.empty = Device[Device.DEFAULT].renderer.render([]) def test_empty_compile(self): with Timing("co...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/device/test_hcq_iface.py
test/device/test_hcq_iface.py
import unittest, array, time from tinygrad.helpers import mv_address from tinygrad.runtime.support.hcq import MMIOInterface from tinygrad.runtime.support.usb import USBMMIOInterface from test.mockgpu.usb import MockUSB class TestHCQIface(unittest.TestCase): def setUp(self): self.size = 4 << 10 self.buffer = ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/device/test_null.py
test/device/test_null.py
import unittest from tinygrad import dtypes, Device from tinygrad.device import is_dtype_supported @unittest.skipUnless(Device.DEFAULT=="NULL", "Don't run when testing non-NULL backends") class TestNULLSupportsDTypes(unittest.TestCase): def test_null_supports_ints_floats_bool(self): dts = dtypes.ints + dtypes.fl...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/device/test_hcq.py
test/device/test_hcq.py
import unittest, ctypes, struct, os, random, numpy as np from tinygrad import Device, Tensor, dtypes from tinygrad.helpers import getenv, mv_address, DEBUG from test.helpers import slow from tinygrad.device import Buffer, BufferSpec from tinygrad.runtime.support.hcq import HCQCompiled, HCQBuffer from tinygrad.runtime.a...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/device/test_amd_llvm.py
test/device/test_amd_llvm.py
import unittest from tinygrad import Device from tinygrad.device import CompileError if Device.DEFAULT == "AMD": # NOTE: if you don't gate this, LVP fails on Mac from tinygrad.runtime.support.compiler_amd import AMDLLVMCompiler @unittest.skipUnless(Device.DEFAULT == "AMD", "Runs only on AMD") class TestAMDLLVM(uni...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/device/__init__.py
test/device/__init__.py
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/device/test_ocl.py
test/device/test_ocl.py
import unittest from tinygrad import Device from tinygrad.device import Buffer from tinygrad.dtype import dtypes from tinygrad.runtime.ops_cl import CLDevice, CLAllocator, CLCompiler, CLProgram @unittest.skipUnless(Device.DEFAULT == "CL", "Runs only on OpenCL") class TestCLError(unittest.TestCase): @unittest.skip("a...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/device/test_metal.py
test/device/test_metal.py
import unittest from tinygrad.device import CompileError, Device, Compiler if Device.DEFAULT=="METAL": from tinygrad.runtime.ops_metal import MetalDevice, MetalCompiler, MetalProgram @unittest.skipIf(Device.DEFAULT!="METAL", "Metal support required") class TestMetal(unittest.TestCase): def test_alloc_oom(self): ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/testextra/test_export_model.py
test/testextra/test_export_model.py
import unittest from extra.export_model import export_model, EXPORT_SUPPORTED_DEVICE from tinygrad.tensor import Tensor, Device from tinygrad import dtypes import json class MockMultiInputModel: def forward(self, x1, x2, x3): return x1 + x2 + x3 class MockMultiOutputModel: def __call__(self, x1): return x...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/testextra/test_mockgpu.py
test/testextra/test_mockgpu.py
from tinygrad.helpers import getenv import unittest, importlib @unittest.skipUnless(getenv("MOCKGPU"), 'Testing mockgpu') class TestMockGPU(unittest.TestCase): # https://github.com/tinygrad/tinygrad/pull/7627 def test_import_typing_extensions(self): import test.mockgpu.mockgpu # noqa: F401 # pylint: disable=u...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/testextra/test_cfg_viz.py
test/testextra/test_cfg_viz.py
# ruff: noqa: F405, F403 # allow define from star imports import unittest import textwrap, functools from tinygrad import Device, Tensor from tinygrad.uop.ops import UOp, Ops, KernelInfo from tinygrad.helpers import getenv from extra.assembly.amd.autogen.rdna3.ins import * from extra.assembly.amd.dsl import Inst te...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/testextra/test_hevc.py
test/testextra/test_hevc.py
import unittest from tinygrad import Device from tinygrad.helpers import fetch from extra.hevc.hevc import parse_hevc_file_headers, nv_gpu class TestHevc(unittest.TestCase): def test_hevc_parser(self): url = "https://github.com/haraschax/filedump/raw/09a497959f7fa6fd8dba501a25f2cdb3a41ecb12/comma_video.hevc" ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/testextra/test_bench_log.py
test/testextra/test_bench_log.py
import unittest, time from unittest.case import skipIf from extra.bench_log import BenchEvent, InstantBenchEvent, WallTimeEvent, KernelTimeEvent, log_event_instant, _events, clear_events from tinygrad.helpers import Context, CI from tinygrad.tensor import Tensor from tinygrad.device import Device class TestBenchLog(u...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/testextra/test_lr_scheduler.py
test/testextra/test_lr_scheduler.py
import numpy as np import torch import unittest from tinygrad.tensor import Tensor from tinygrad.nn.state import get_parameters from tinygrad.nn.optim import Adam, SGD from tinygrad.helpers import DEBUG from extra.lr_scheduler import MultiStepLR, ReduceLROnPlateau, CosineAnnealingLR, OneCycleLR from extra.training impo...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/testextra/test_f16_decompress.py
test/testextra/test_f16_decompress.py
import unittest from extra.f16_decompress import u32_to_f16 from tinygrad.tensor import Tensor from tinygrad.device import is_dtype_supported from tinygrad import dtypes import numpy as np class TestF16Decompression(unittest.TestCase): @unittest.skipUnless(is_dtype_supported(dtypes.float16), "need float16") def te...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/testextra/__init__.py
test/testextra/__init__.py
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/testextra/test_tk.py
test/testextra/test_tk.py
import unittest, math, time from tinygrad import Tensor, Device, dtypes, Context from tinygrad.uop.ops import UOp, Ops from tinygrad.engine.realize import get_runner from tinygrad.engine.schedule import ExecItem from tinygrad.engine.jit import TinyJit from tinygrad.helpers import CI import numpy as np from extra.thun...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/opt/test_gen_float4.py
test/opt/test_gen_float4.py
import unittest from tinygrad import Device, Tensor, dtypes from tinygrad.uop.ops import UOp, Ops from tinygrad.codegen.opt import Opt, OptOps from tinygrad.engine.realize import get_program from tinygrad.helpers import AMX @unittest.skipUnless(Device[Device.DEFAULT].renderer.supports_float4, "need backends that suppo...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/opt/test_tensor_cores.py
test/opt/test_tensor_cores.py
import numpy as np import unittest from dataclasses import replace from tinygrad import Device, Tensor, dtypes from tinygrad.tensor import _to_np_dtype from tinygrad.uop.ops import Ops from tinygrad.dtype import DType from tinygrad.device import is_dtype_supported from tinygrad.helpers import AMX, AMD_LLVM, CPU_LLVM, ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/opt/test_kernel_opts.py
test/opt/test_kernel_opts.py
import unittest from tinygrad import Device, Tensor, dtypes from tinygrad.codegen.opt import Opt, OptOps, KernelOptError # TODO: write a clean version of this from test.test_linearizer import helper_linearizer_opt class TestKernelOpts(unittest.TestCase): @unittest.skipUnless(Device[Device.DEFAULT].renderer.has_loca...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/models/test_waifu2x.py
test/models/test_waifu2x.py
#!/usr/bin/env python import pathlib import unittest import numpy as np from tinygrad.tensor import Tensor class TestVGG7(unittest.TestCase): def test_vgg7(self): from examples.vgg7_helpers.waifu2x import Vgg7, image_load # Create in tinygrad Tensor.manual_seed(1337) mdl = Vgg7() mdl.load_from_p...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/models/test_end2end.py
test/models/test_end2end.py
import torch from torch import nn import unittest import numpy as np from tinygrad.nn.state import get_parameters, get_state_dict from tinygrad.nn import optim, Linear, Conv2d, BatchNorm2d from tinygrad.tensor import Tensor from extra.datasets import fetch_mnist from tinygrad.helpers import CI def compare_tiny_torch(m...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/models/test_rnnt.py
test/models/test_rnnt.py
#!/usr/bin/env python import unittest from tinygrad import Tensor from extra.models.rnnt import LSTM import numpy as np import torch class TestRNNT(unittest.TestCase): def test_lstm(self): BS, SQ, IS, HS, L = 2, 20, 40, 128, 2 # create in torch with torch.no_grad(): torch_layer = torch.nn.LSTM(IS,...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/models/test_mnist.py
test/models/test_mnist.py
#!/usr/bin/env python import unittest import numpy as np from tinygrad import Tensor from test.helpers import slow from tinygrad.nn.state import get_parameters from tinygrad.nn import optim, BatchNorm2d from extra.training import train, evaluate from extra.datasets import fetch_mnist # load the mnist dataset X_train, ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/models/test_real_world.py
test/models/test_real_world.py
import unittest, time, gc import numpy as np from tinygrad.device import is_dtype_supported from tinygrad.nn import optim from tinygrad.nn.state import get_parameters from tinygrad.engine.jit import TinyJit from tinygrad import Tensor, Device, GlobalCounters, dtypes, Variable from tinygrad.helpers import Context from t...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/models/test_onnx.py
test/models/test_onnx.py
#!/usr/bin/env python import unittest import numpy as np from tinygrad.nn.onnx import OnnxRunner from tinygrad.device import Device from tinygrad.helpers import fetch, Context from extra.onnx_helpers import validate from extra.huggingface_onnx.huggingface_manager import DOWNLOADS_DIR, snapshot_download_with_retry def...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/models/test_whisper.py
test/models/test_whisper.py
import unittest import pathlib from examples.whisper import init_whisper, load_file_waveform, transcribe_file, transcribe_waveform import examples.mlperf.metrics as metrics from tinygrad.helpers import fetch from test.helpers import slow from tinygrad import Device, dtypes from tinygrad.device import is_dtype_supported...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/models/__init__.py
test/models/__init__.py
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/models/test_bert.py
test/models/test_bert.py
#!/usr/bin/env python import os os.environ['USE_TF'] = '0' # prevent transformers from importing tensorflow import unittest from tinygrad import Tensor import numpy as np import torch def get_question_samp(bsz, seq_len, vocab_size, seed): np.random.seed(seed) in_ids= np.random.randint(vocab_size, size=(bsz, seq_l...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/models/test_resnet.py
test/models/test_resnet.py
import unittest from extra.models import resnet class TestResnet(unittest.TestCase): def test_model_load(self): model = resnet.ResNet18() model.load_from_pretrained() model = resnet.ResNeXt50_32X4D() model.load_from_pretrained() def test_model_load_no_fc_layer(self): model = resnet.ResNet18(n...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/models/test_train.py
test/models/test_train.py
import unittest, time import numpy as np from tinygrad import Device from tinygrad.nn.state import get_parameters from tinygrad.nn import optim from tinygrad.helpers import getenv from test.helpers import slow from extra.training import train from extra.models.convnext import ConvNeXt from extra.models.efficientnet imp...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/models/test_efficientnet.py
test/models/test_efficientnet.py
import ast, pathlib, unittest import numpy as np from PIL import Image from tinygrad import Tensor from tinygrad.helpers import getenv from test.helpers import slow from extra.models.efficientnet import EfficientNet from extra.models.vit import ViT from extra.models.resnet import ResNet50 def _load_labels(): label...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_cl_half_max.py
test/external/external_cl_half_max.py
from tinygrad.runtime.ops_cl import CLDevice, CLProgram, compile_cl if __name__ == "__main__": dev = CLDevice() lib = compile_cl(""" #pragma OPENCL EXTENSION cl_khr_fp16 : enable __kernel void test(__global half *out, __global half *a, __global half *b) { int gid = get_global_id(0); out[gid] = max(a[gid], b[gi...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_amd.py
test/external/external_test_amd.py
import unittest from tinygrad import Device, Tensor from tinygrad.engine.schedule import create_schedule from tinygrad.runtime.ops_amd import AMDDevice class TestAMD(unittest.TestCase): @classmethod def setUpClass(self): TestAMD.d0: AMDDevice = Device["AMD"] TestAMD.a = Tensor([0.,1.], device="AMD").realiz...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_fuzz_hcq_mp.py
test/external/external_fuzz_hcq_mp.py
import subprocess import random import time from concurrent.futures import ProcessPoolExecutor, as_completed from tinygrad.helpers import getenv # checks that HCQ drivers can be killed during operation without causing issues def run_test(i, full_run=False, force_ok=False): print(f"\rRunning iteration {i}...", end="...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_hcopt.py
test/external/external_benchmark_hcopt.py
import random from tinygrad.helpers import getenv from tinygrad.codegen.opt.search import beam_search, bufs_from_lin from tinygrad.codegen.opt.heuristic import hand_coded_optimizations from extra.optimization.helpers import load_worlds, ast_str_to_lin, time_linearizer def optimize_kernel(k): # TODO: update this re...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_llm_eval.py
test/external/external_llm_eval.py
# eval for tinygrad.apps.llm import pyarrow.parquet as pq from tinygrad.helpers import fetch, colored from tinygrad.apps.llm import Transformer, SimpleTokenizer, models from tinygrad import Tensor if __name__ == "__main__": dat = fetch("https://huggingface.co/datasets/allenai/ai2_arc/resolve/main/ARC-Challenge/test-...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_osx_profiling.py
test/external/external_osx_profiling.py
from tinygrad.runtime.ops_cl import CLProgram, CL, CLBuffer from tinygrad import dtypes import time N = 1000000 a = CLBuffer(N, dtypes.float32) b = CLBuffer(N, dtypes.float32) c = CLBuffer(N, dtypes.float32) prg = CLProgram("test", """__kernel void test(__global float *a, __global float *b, __global float *c) { int...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_op_conv.py
test/external/external_benchmark_op_conv.py
# ruff: noqa: E501 E712 F401 from dataclasses import replace from tinygrad import dtypes, Device from tinygrad.uop.ops import UOp, AxisType, Ops, KernelInfo from tinygrad.codegen.opt import Opt, OptOps # pylint: disable=unused-import from tinygrad.engine.realize import CompiledRunner, get_program from tinygrad.helpers ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_nhwc_conv.py
test/external/external_nhwc_conv.py
from tinygrad import Tensor, nn, Context, GlobalCounters if __name__ == "__main__": conv = nn.Conv2d(64, 128, 3) img = Tensor.randn((1,64,128,128)) with Context(DEBUG=0, BEAM=0): Tensor.realize(img, conv.weight, conv.bias) tst = conv(img).permute(0,2,3,1).realize() print(tst.shape) print("NEW") img...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/speed_compare_amd_am.py
test/external/speed_compare_amd_am.py
from tinygrad import Device, dtypes from tinygrad.helpers import getenv, colorize_float, DEBUG from extra.optimization.helpers import load_worlds, ast_str_to_lin from test.external.fuzz_linearizer import get_fuzz_rawbufs from tinygrad.codegen.opt.heuristic import hand_coded_optimizations from tinygrad.codegen.opt.searc...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_optim.py
test/external/external_test_optim.py
#!/usr/bin/env python import unittest, math import numpy as np import tensorflow as tf from tensorflow.keras.optimizers import Lamb from tensorflow.python.ops import math_ops from extra.lr_scheduler import LRSchedulerGroup from tinygrad.tensor import Tensor from tinygrad.nn.optim import LAMB, LARS, SGD, OptimizerGroup...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_openpilot_image_warp.py
test/external/external_openpilot_image_warp.py
import time from tinygrad.tensor import Tensor, Device MODEL_WIDTH = 512 MODEL_HEIGHT = 256 MODEL_FRAME_SIZE = MODEL_WIDTH * MODEL_HEIGHT * 3 // 2 IMG_INPUT_SHAPE = (1, 12, 128, 256) def tensor_arange(end): return Tensor([float(i) for i in range(end)]) def tensor_round(tensor:Tensor): return (tensor + 0.5).floor() h...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_onnx_runner.py
test/external/external_test_onnx_runner.py
import unittest, onnx, tempfile, pathlib import numpy as np from tinygrad import dtypes, Tensor from tinygrad.uop.ops import Ops from tinygrad.device import is_dtype_supported from tinygrad.nn.onnx import OnnxRunner, OnnxDataType from hypothesis import given, strategies as st # copied from test_const_folding.py def _c...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/fuzz_symbolic_symbolic_div.py
test/external/fuzz_symbolic_symbolic_div.py
import random import z3 from tinygrad.uop.ops import UOp, Ops from tinygrad.uop.validate import uops_to_z3 from tinygrad.helpers import DEBUG, Context, colored seed = random.randint(0, 100) print(f"Seed: {seed}") random.seed(seed) def get_random_term(ranges, factors): # 10% chance of nesting if random.randint(0,9...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_gpu_fail_osx.py
test/external/external_gpu_fail_osx.py
# ugh, OS X OpenCL doesn't support half from tinygrad.runtime.ops_cl import CLDevice, CLProgram, CLCompiler src = """#pragma OPENCL EXTENSION cl_khr_fp16 : enable __kernel void max_half(__global half* data0, const __global half* data1) { int gidx0 = get_group_id(0); data0[gidx0] = max(data1[gidx0], (half)0.0); }""...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_mamba.py
test/external/external_test_mamba.py
import unittest from test.helpers import slow from examples.mamba import Mamba, generate from transformers import AutoTokenizer PROMPT = 'Why is gravity ' TOKENIZER = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b") @slow class TestMamba(unittest.TestCase): def test_mamba_130M(self): OUT_130M = '''Why i...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/verify_kernel.py
test/external/verify_kernel.py
import argparse from collections import defaultdict from extra.optimization.helpers import kern_str_to_lin, time_linearizer from test.external.fuzz_linearizer import compare_linearizer from tinygrad.helpers import colored from tinygrad.codegen.opt.kernel import Kernel # Use this with the LOGKERNS options to verify tha...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/speed_v_theoretical.py
test/external/speed_v_theoretical.py
import unittest from tinygrad import Tensor, TinyJit, Device from tinygrad.helpers import Context, DEBUG, GlobalCounters from tinygrad.nn import Conv2d from tinygrad.nn.state import get_parameters class TestKernelSpeed(unittest.TestCase): def _get_tensor(self, *shape:int): with Context(BEAM=0, DEBUG=0): # ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/fuzz_fast_idiv.py
test/external/fuzz_fast_idiv.py
import random import z3 from tinygrad import dtypes from tinygrad.uop.validate import uops_to_z3, z3_cdiv from tinygrad.uop.ops import UOp from tinygrad.uop.decompositions import fast_idiv random.seed(42) powers_of_two = [2**i for i in range(64)] if __name__ == "__main__": for i in range(10_000): if i % 1000 == ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_opt.py
test/external/external_test_opt.py
#!/usr/bin/env python import gc, unittest import numpy as np import torch from tinygrad import GlobalCounters, Tensor, Device from tinygrad.helpers import getenv from tinygrad.nn.state import get_parameters from tinygrad.engine.realize import capturing from tinygrad.tensor import _to_np_dtype class CLCache: def __i...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/speed_compare_cuda_nv.py
test/external/speed_compare_cuda_nv.py
from tinygrad import Device, dtypes from tinygrad.helpers import getenv, colorize_float from extra.optimization.helpers import load_worlds, ast_str_to_lin from test.external.fuzz_linearizer import get_fuzz_rawbufs from tinygrad.codegen.opt.heuristic import hand_coded_optimizations from tinygrad.codegen.opt.search impor...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_whisper_librispeech.py
test/external/external_test_whisper_librispeech.py
import unittest import torch import tqdm import torchaudio import pathlib import jiwer import os import numpy as np from whisper.normalizers import EnglishTextNormalizer from examples.whisper import init_whisper, transcribe_waveform class TestWhisperLibriSpeech(unittest.TestCase): # reference WERs determined by runn...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_onnx_ops.py
test/external/external_test_onnx_ops.py
# inputs, attributes, and outputs for tests are found here: # https://github.com/onnx/onnx/blob/main/docs/Operators.md # https://github.com/microsoft/onnxruntime/blob/main/docs/ContribOperators.md from typing import Any import unittest, onnx, tempfile from tinygrad import dtypes, Tensor from tinygrad.nn.onnx import On...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/fuzz_graph.py
test/external/fuzz_graph.py
import random, ctypes import numpy as np from tinygrad.device import Buffer, Device from tinygrad.helpers import Context, getenv, from_mv from tinygrad.dtype import dtypes from tinygrad.tensor import Tensor, _to_np_dtype from tinygrad.engine.realize import BufferXfer, get_runner from tinygrad.engine.schedule import Exe...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_am.py
test/external/external_test_am.py
import unittest from tinygrad.runtime.support.am.amdev import AMMemoryManager, AMPageTableEntry from tinygrad.runtime.support.am.ip import AM_GMC from tinygrad.runtime.support.hcq import MMIOInterface from tinygrad.runtime.support.memory import PageTableTraverseContext, AddrSpace from tinygrad.runtime.autogen.am import...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/speed_compare_cuda_ptx.py
test/external/speed_compare_cuda_ptx.py
import itertools from tinygrad import Device from tinygrad.engine.realize import CompiledRunner, get_program from tinygrad.codegen.opt.heuristic import hand_coded_optimizations from tinygrad.helpers import getenv, colorize_float from extra.optimization.helpers import load_worlds, ast_str_to_lin from tinygrad.codegen.op...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_uop_gc.py
test/external/external_uop_gc.py
import gc from tinygrad import Tensor, UOp, Device, nn from tinygrad.engine.schedule import schedule_cache from tinygrad.engine.realize import method_cache, get_program from tinygrad.schedule.indexing import apply_movement_op, _apply_reshape from tinygrad.uop.divandmod import fold_divmod_general from test.test_tiny imp...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_hip_compile.py
test/external/external_benchmark_hip_compile.py
import random, os from tinygrad.helpers import Timing from tinygrad.runtime.ops_hip import compile_hip, HIPDevice from tinygrad.runtime.ops_cl import compile_cl, CLDevice # OMP_NUM_THREADS=1 strace -tt -f -e trace=file python3 test/external/external_benchmark_hip_compile.py # AMD_COMGR_REDIRECT_LOGS=stdout AMD_COMGR_E...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/fuzz_linearizer.py
test/external/fuzz_linearizer.py
import random, traceback, ctypes, argparse, os from typing import Any import numpy as np from collections import defaultdict from extra.optimization.helpers import load_worlds, ast_str_to_lin, kern_str_to_lin from tinygrad.engine.realize import get_program # We need to insert ioctl before opening devices. if os.getenv...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_mnist_data_select.py
test/external/external_test_mnist_data_select.py
#!/bin/bash from tinygrad import Tensor from extra.datasets import fetch_mnist if __name__ == "__main__": X_train, Y_train, X_test, Y_test = fetch_mnist(tensors=True) samples = Tensor.randint(512, high=X_train.shape[0]) select = X_train[samples].realize()
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_example.py
test/external/external_test_example.py
import unittest from tinygrad import Device from tinygrad.tensor import Tensor from tinygrad.helpers import getenv, CI, OSX def multidevice_test(fxn): exclude_devices = getenv("EXCLUDE_DEVICES", "").split(",") def ret(self): for device in Device._devices: # broken on OSX USB AMD, why? if device in ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_benchmark_am.py
test/external/external_benchmark_am.py
from tinygrad.helpers import Profiling from tinygrad import Device if __name__ == "__main__": am = Device["AMD"] # kfd is 0.55ms! with Profiling("allocation 127.7mb"): am.allocator.alloc(int(127.7*1024*1024))
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/test/external/external_test_llama3_ff.py
test/external/external_test_llama3_ff.py
#!/usr/bin/env python3 from tinygrad import Tensor, TinyJit, nn from extra.models.llama import FeedForward if __name__ == "__main__": model = FeedForward(4096, 14336) for x in nn.state.get_parameters(model): x.replace(x.half()).realize() jrun = TinyJit(model) for i in range(5): print(f"*** run {i}") jr...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false