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
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_symbolic_failures.py
tinygrad_repo/test/unit/test_symbolic_failures.py
import unittest from tinygrad import Variable, dtypes from tinygrad.helpers import Context from tinygrad.uop.ops import Ops, UOp class TestFuzzFailure(unittest.TestCase): def setUp(self): self.context = Context(CORRECT_DIVMOD_FOLDING=1) self.context.__enter__() def tearDown(self): self.context.__exit...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_tar.py
tinygrad_repo/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
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_rewrite_map.py
tinygrad_repo/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
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_viz.py
tinygrad_repo/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 from tinygrad.uop.ops import graph_rewrite, track_rewrites, TRACK_MATCH_STATS from tinygrad.uop.symbolic import sym from tinygrad.dtyp...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_tensor_uop_representation.py
tinygrad_repo/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) # after realization, base tensor uops become RESHAPE(BUFFER) buffer_view_pattern = UPat(Ops.RESHAPE, src=(UPat(Ops.BUFFER),)) c...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_tqdm.py
tinygrad_repo/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 as tinytrange import numpy as np def _get_iter_per_second(raw:str) -> float: # raw might have unit scale if...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_pattern_matcher.py
tinygrad_repo/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
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_symbolic_shapetracker.py
tinygrad_repo/test/unit/test_symbolic_shapetracker.py
import unittest from tinygrad.shape.shapetracker import ShapeTracker, View from tinygrad import Variable from tinygrad.tensor import Tensor class TestSymbolic(unittest.TestCase): def assert_tuple_equal(self, x, y): for a,b in zip(x,y): self.assertFalse(a != b) def test_symbolic_st(self): x = Variable("x",...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_allreduce.py
tinygrad_repo/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
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_linearizer_rewrite.py
tinygrad_repo/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
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_kernelize.py
tinygrad_repo/test/unit/test_kernelize.py
import unittest from tinygrad import Tensor from tinygrad.uop import Ops class TestKernelize(unittest.TestCase): def test_add_reshaped(self): a = Tensor.ones(16,16).contiguous() b = Tensor.zeros(16,16).contiguous() ret = (a+b).sum(axis=1) ret_reshaped_1 = ret.reshape(4,4) ret_reshaped_2 = ret.res...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_masked_st.py
tinygrad_repo/test/unit/test_masked_st.py
import unittest from tinygrad.tensor import Tensor class TestMaskedShapeTracker(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 #assert c.uop.st.views[0].mask is not None ret = c.data() assert ret.tol...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_indexing.py
tinygrad_repo/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
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
true
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_llm_tokenizer.py
tinygrad_repo/test/unit/test_llm_tokenizer.py
import unittest, base64, functools, sys from tinygrad.apps.llm import SimpleTokenizer, get_llama_re from tinygrad.helpers import fetch @unittest.skipIf(sys.platform == 'win32', "fetch race condition on Windows") class TestLLMTokenizer(unittest.TestCase): @functools.cached_property def basic_tok(self): return Simpl...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_device.py
tinygrad_repo/test/unit/test_device.py
#!/usr/bin/env python import unittest, os, subprocess, sys from tinygrad import Tensor from tinygrad.device import Device, Compiler from tinygrad.helpers import diskcache_get, diskcache_put, getenv, Context, WIN, CI class TestDevice(unittest.TestCase): def test_canonicalize(self): self.assertEqual(Device.canonic...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_linalg.py
tinygrad_repo/test/unit/test_linalg.py
import numpy as np import unittest from tinygrad import Tensor from typing import List import functools def orthogonality_helper(A:Tensor,tolerance=1.0e-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)).e...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_uop_vmin_vmax.py
tinygrad_repo/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
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_transcendental_helpers.py
tinygrad_repo/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
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_simple_schedule.py
tinygrad_repo/test/unit/test_simple_schedule.py
import unittest from tinygrad import Tensor from tinygrad.uop.ops import Ops class TestSimpleSchedule(unittest.TestCase): def test_reduce_doesnt_split(self): a = Tensor.empty(16,16).sum(axis=1) a1 = a.reshape(4,4) a2 = a.reshape(16,1,1) Tensor.kernelize(a1, a2) kernels = [x for x in a1.uop.sink(a...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_mnist_dataset.py
tinygrad_repo/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
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_block_reorder.py
tinygrad_repo/test/unit/test_block_reorder.py
import unittest, random from tinygrad.dtype import dtypes from tinygrad.uop.ops import print_uops, UOp, Ops from tinygrad.codegen.late.linearize import block_reorder from tinygrad.renderer.cstyle import OpenCLRenderer def is_toposorted(lst:list[UOp]): seen = set() for u in lst: if any(p not in seen for p in u....
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_elf.py
tinygrad_repo/test/unit/test_elf.py
import unittest, subprocess, platform from tinygrad.runtime.ops_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 .rela.text t...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_view.py
tinygrad_repo/test/unit/test_view.py
#!/usr/bin/env python import unittest from tinygrad.shape.view import View, merge_dims # from tinygrad.shape.shapetracker import ShapeTracker class TestView(unittest.TestCase): def test_canonicalize_empty_mask(self): v = View.create(shape=(2,2,2), strides=(4,2,1), mask=((0,2),(0,2),(0,2))) self.assertIsNone(...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_uop_resolve.py
tinygrad_repo/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
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_shapetracker_math.py
tinygrad_repo/test/unit/test_shapetracker_math.py
import unittest from tinygrad.helpers import prod from tinygrad.shape.view import View from tinygrad.shape.shapetracker import ShapeTracker from tinygrad import Variable from test.unit.test_shapetracker import shapetracker_getitem class MultiShapeTracker: def __init__(self, sts:list[ShapeTracker]): self.sts = sts ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_graph_rewrite.py
tinygrad_repo/test/unit/test_graph_rewrite.py
import unittest, math from tinygrad import dtypes from tinygrad.helpers import all_same 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 apply th...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_gguf.py
tinygrad_repo/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
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_gradient.py
tinygrad_repo/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
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_shm_tensor.py
tinygrad_repo/test/unit/test_shm_tensor.py
import unittest import multiprocessing.shared_memory as shared_memory from tinygrad.helpers import CI from tinygrad.tensor import Tensor, Device import numpy as np class TestRawShmBuffer(unittest.TestCase): def test_e2e(self): t = Tensor.randn(2, 2, 2).realize() # copy to shm shm_name = (s := shared_mem...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_dtype.py
tinygrad_repo/test/unit/test_dtype.py
import unittest from tinygrad.tensor import Tensor from tinygrad.dtype import dtypes, DType, ImageDType, PtrDType, to_dtype class TestImageDType(unittest.TestCase): def test_image_scalar(self): assert dtypes.imagef((10,10)).base.scalar() == dtypes.float32 assert dtypes.imageh((10,10)).base.scalar() == dtypes...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_tensor_io.py
tinygrad_repo/test/unit/test_tensor_io.py
import unittest from tinygrad import Tensor, dtypes from tinygrad.nn.state import TensorIO class TestTensorIO(unittest.TestCase): def test_create(self): with self.assertRaises(ValueError): TensorIO(Tensor(b"Hello World").reshape(1, -1)) with self.assertRaises(ValueError): TensorIO(Tensor([], dtyp...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_uop_spec.py
tinygrad_repo/test/unit/test_uop_spec.py
from __future__ import annotations import unittest from tinygrad import Tensor from tinygrad.helpers import DEBUG from tinygrad.uop.ops import UOp, Ops, print_uops from tinygrad.uop.spec import type_verify, ast_spec, tensor_uop_spec from tinygrad.shape.shapetracker import ShapeTracker from tinygrad import dtypes from ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_hashing.py
tinygrad_repo/test/unit/test_hashing.py
from typing_extensions import Callable import hashlib, random, unittest from tinygrad import Tensor, Device, getenv, dtypes from tinygrad.device import is_dtype_supported @unittest.skipUnless(is_dtype_supported(dtypes.uint8) and is_dtype_supported(dtypes.uint64), "Device must support uint8 and uint64") @unittest.skipI...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_tensor_data.py
tinygrad_repo/test/unit/test_tensor_data.py
import unittest, struct from tinygrad import Tensor, dtypes # format types: https://docs.python.org/3/library/struct.html class TestTensorBytes(unittest.TestCase): def test_bytes(self): lst = Tensor(bytes(b"\xaa\xbb\xcc\xdd")) assert lst.tolist() == [170, 187, 204, 221] def test_float_bytes(self): ls...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_rearrange_einops.py
tinygrad_repo/test/unit/test_rearrange_einops.py
# modified from # https://github.com/arogozhnikov/einops/blob/master/tests/test_examples.py # https://github.com/arogozhnikov/einops/blob/master/tests/test_ops.py # https://github.com/arogozhnikov/einops/blob/master/tests/test_parsing.py import numpy as np import unittest from tinygrad import Tensor class test_rearr...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_conv.py
tinygrad_repo/test/unit/test_conv.py
import unittest import numpy as np from tinygrad.tensor import Tensor from tinygrad.helpers import Context class TestConv(unittest.TestCase): def test_simple(self): x = Tensor.ones(1,12,16,32).contiguous().realize() w = Tensor.ones(32,12,3,3).contiguous().realize() ret = x.conv2d(w, stride=(2,2), padding...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_shapetracker.py
tinygrad_repo/test/unit/test_shapetracker.py
#!/usr/bin/env python import unittest import numpy as np from tinygrad.dtype import dtypes, Invalid from tinygrad.helpers import prod from tinygrad.shape.shapetracker import ShapeTracker, View from tinygrad import Variable from tinygrad.uop.ops import UOp, Ops, graph_rewrite from tinygrad.codegen.late.devectorizer impo...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_rewrite_tracked_childen.py
tinygrad_repo/test/unit/test_rewrite_tracked_childen.py
import unittest from tinygrad import Tensor from tinygrad.uop.ops import PatternMatcher, Ops, UPat, graph_rewrite, RewriteContext, UOp from tinygrad.schedule.kernelize import kernelize_sym, merge_views class TestRewriteTrackedChildren(unittest.TestCase): @unittest.skip("track_children no longer supported") def tes...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_uop_symbolic.py
tinygrad_repo/test/unit/test_uop_symbolic.py
#!/usr/bin/env python import unittest, pickle, functools, math import z3 from tinygrad.dtype import dtypes, ConstType, DType, Invalid from tinygrad.codegen import full_rewrite from tinygrad.helpers import Context from tinygrad.uop.ops import UOp, Ops, graph_rewrite, sym_infer, track_rewrites from tinygrad.uop.symbolic...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
true
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_disk_tensor.py
tinygrad_repo/test/unit/test_disk_tensor.py
import os, pathlib, tempfile, unittest import numpy as np from tinygrad import Tensor, Device, dtypes from tinygrad.dtype import DType from tinygrad.nn.state import safe_load, safe_save, get_state_dict, torch_load from tinygrad.helpers import Timing, fetch, temp, CI, OSX from tinygrad.device import is_dtype_supported ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_disk_cache.py
tinygrad_repo/test/unit/test_disk_cache.py
import unittest import pickle from tinygrad.helpers import diskcache_get, diskcache_put, diskcache, diskcache_clear def remote_get(table,q,k): q.put(diskcache_get(table, k)) def remote_put(table,k,v): diskcache_put(table, k, v) class DiskCache(unittest.TestCase): def test_putget(self): table = "test_putget" ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_attention.py
tinygrad_repo/test/unit/test_attention.py
import unittest from tinygrad import Tensor, dtypes, TinyJit, UOp from tinygrad.apps.llm import apply_rope # TODO: test_scheduler, but just in uint class TestAttention(unittest.TestCase): def test_half_qkv_buffers(self): BS, seqlen, dim = 10, 4, 100 q = Tensor.ones(BS, seqlen, dim, dtype=dtypes.half).contigu...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_upat_compile.py
tinygrad_repo/test/unit/test_upat_compile.py
import unittest from tinygrad.helpers import DEBUG from tinygrad.dtype import dtypes from tinygrad.uop.ops import UPat, track_rewrites, GroupOp, Ops from tinygrad.uop.upat import _get_code, upat_compile import dis @track_rewrites() def do_compile(up): print("\n***** COMPILE", up) match_code = _get_code(up, False) ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_microbenchmarks.py
tinygrad_repo/test/unit/test_microbenchmarks.py
import unittest, time from tinygrad.uop.ops import UOp from tinygrad.dtype import dtypes # it's about 1 ms per 1k UOps on M3 N = 10000 class TestMicrobenchmarks(unittest.TestCase): def setUp(self): self.st = time.perf_counter() def tearDown(self): et = (time.perf_counter() - self.st) print(f"{self._te...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/__init__.py
tinygrad_repo/test/unit/__init__.py
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_rewrite_not_ready.py
tinygrad_repo/test/unit/test_rewrite_not_ready.py
import unittest from dataclasses import dataclass, field from tinygrad.uop.ops import PatternMatcher, UOp, graph_rewrite, Ops, UPat, GroupOp, RewriteNotReady # we could insert CHILDREN node @dataclass class ChildrenContext: children: dict[UOp, list[UOp]]|None = None # this is a generic child labeller def extract_c...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_winograd.py
tinygrad_repo/test/unit/test_winograd.py
import unittest, sys import numpy as np from tinygrad import Tensor, GlobalCounters, dtypes, Context, nn from tinygrad.helpers import CI, Profiling, WINO @unittest.skipIf(sys.platform.startswith("win"), "flaky on Windows") class TestWinogradClose(unittest.TestCase): def test_close(self): inp = Tensor.rand(1, 16,...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_qcom.py
tinygrad_repo/test/unit/test_qcom.py
#!/usr/bin/env python import unittest from tinygrad.device import Device, BufferSpec from tinygrad.dtype import dtypes @unittest.skipUnless(Device.DEFAULT == "QCOM", "QCOM device required to run") class TestQcom(unittest.TestCase): def test_image_pitch(self): dev = Device["QCOM"] def __validate(imgdt, expec...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_rewrite_bottom_up_gate.py
tinygrad_repo/test/unit/test_rewrite_bottom_up_gate.py
import unittest from tinygrad.uop.ops import PatternMatcher, UOp, graph_rewrite, Ops, UPat, BottomUpGate def assert_not_reached(): assert False, "This function should not be reached" def gate(): raise BottomUpGate class TestBottomUpGate(unittest.TestCase): def test_basic_bottom_up_gate(self): """Test that Botto...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_simplify_valid_idx.py
tinygrad_repo/test/unit/test_simplify_valid_idx.py
import unittest, itertools from tinygrad.codegen import full_rewrite_to_sink from tinygrad.dtype import dtypes from tinygrad.uop.ops import UOp, Ops from tinygrad.uop.symbolic import simplify_valid from tinygrad.helpers import Context def get_gated_load_uop(valid:UOp, idx:UOp): return UOp(Ops.LOAD, dtypes.float, ( ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/test/unit/test_helpers.py
tinygrad_repo/test/unit/test_helpers.py
import ctypes, gzip, unittest, timeit from tinygrad import Variable from tinygrad.helpers import Context, ContextVar, argfix, colored, word_wrap, is_numpy_ndarray, CI, mv_address from tinygrad.helpers import merge_dicts, strip_parens, prod, round_up, fetch, fully_flatten, from_mv, to_mv, polyN, time_to_str, cdiv, cmod,...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/onnx_helpers.py
tinygrad_repo/extra/onnx_helpers.py
from tinygrad import Tensor from tinygrad.tensor import _to_np_dtype from tinygrad.frontend.onnx import OnnxRunner, OnnxValue import numpy as np import onnxruntime as ort def get_example_inputs(graph_inputs:dict[str, OnnxValue], config={}): def _get_shape(onnx_shape: tuple[str|int]): shape = [] for onnx_dim ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/test_hcopt.py
tinygrad_repo/extra/test_hcopt.py
import time from extra.optimization.helpers import load_worlds, ast_str_to_ast from tinygrad import Device from tinygrad.codegen.lowerer import pm_lowerer, get_index from tinygrad.uop.ops import graph_rewrite from tinygrad.codegen.opt.kernel import Kernel from tinygrad.codegen.opt.postrange import Scheduler from tinygr...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/ring_copy.py
tinygrad_repo/extra/ring_copy.py
from tinygrad import Tensor, Device, GlobalCounters from tinygrad.helpers import Timing N = 512 GPUS = 5 ds = tuple([f"{Device.DEFAULT}:{i+1}" for i in range(GPUS)]) t = [Tensor.ones(N, N, N, device=d).contiguous().realize() for d in ds] for _ in range(10): GlobalCounters.reset() with Timing(): for ti in t: ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/training.py
tinygrad_repo/extra/training.py
import numpy as np from tinygrad.tensor import Tensor from tinygrad.helpers import CI, trange from tinygrad.engine.jit import TinyJit def train(model, X_train, Y_train, optim, steps, BS=128, lossfn=lambda out,y: out.sparse_categorical_crossentropy(y), transform=lambda x: x, target_transform=lambda x: x, nolos...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/hip_events.py
tinygrad_repo/extra/hip_events.py
import ctypes import tinygrad.runtime.autogen.hip as hip from tinygrad.runtime.ops_hip import check from tinygrad.helpers import init_c_var if __name__ == "__main__": check(hip.hipSetDevice(0)) evt = init_c_var(hip.hipEvent_t(), lambda x: check(hip.hipEventCreate(ctypes.byref(x)))) check(hip.hipSetDevice(1)) c...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/hip_large_kernel.py
tinygrad_repo/extra/hip_large_kernel.py
from tinygrad.device import Device, Buffer from tinygrad.dtype import dtypes, _to_np_dtype dev = Device.default mbin = dev.compiler.compile(""" typedef long unsigned int size_t; extern "C" __attribute__((device, const)) size_t __ockl_get_group_id(unsigned int); extern "C" __attribute__((global)) void __attribute__((am...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/archprobe.py
tinygrad_repo/extra/archprobe.py
# copying the kernels from https://github.com/microsoft/ArchProbe into Python import numpy as np import pickle from tinygrad.runtime.ops_cl import CLProgram, CLBuffer from tinygrad import dtypes from tqdm import trange, tqdm from matplotlib import pyplot as plt tests = {} def register_test(fxn): tests[fxn.__name__] ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/multitensor.py
tinygrad_repo/extra/multitensor.py
import numpy as np from tinygrad import Tensor, Device, GlobalCounters from tinygrad.helpers import Timing d0, d1 = f"{Device.DEFAULT}:1", f"{Device.DEFAULT}:2" N = 256 FLOPS = N*N*N*2 # LazyBuffer should make three fields lists: self.st (all must have the same shape), self.realized, and self.device def explicit_sha...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/to_movement_ops.py
tinygrad_repo/extra/to_movement_ops.py
import itertools from enum import Enum, auto from collections import defaultdict from typing import List, Tuple, DefaultDict from tinygrad.helpers import prod, tqdm from tinygrad.uop.ops import UOp, Ops from tinygrad.shape.shapetracker import ShapeTracker from tinygrad.uop.ops import sym_infer from tinygrad.tensor impo...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/bench_log.py
tinygrad_repo/extra/bench_log.py
import time, atexit, uuid from enum import Enum from tinygrad.device import Device from tinygrad.helpers import DEBUG, ContextVar, getenv, GlobalCounters BENCHMARK_LOG = ContextVar("BENCHMARK_LOG", "") if BENCHMARK_LOG: from influxdb_client_3 import InfluxDBClient3, Point, WriteOptions, write_client_options from...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/export_model.py
tinygrad_repo/extra/export_model.py
from typing import Tuple, Dict, List, Optional from tinygrad.dtype import DType from tinygrad.renderer import ProgramSpec from tinygrad.tensor import Device, Tensor from tinygrad.engine.jit import TinyJit from tinygrad.nn.state import get_state_dict from tinygrad.helpers import Context, to_mv from tinygrad.dtype import...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/transfer_speed.py
tinygrad_repo/extra/transfer_speed.py
from tinygrad import Tensor, Device #N = 1024 N = 32 t = Tensor.rand(N, N, N, device="CPU").realize() d1 = Device.DEFAULT + ":1" d2 = Device.DEFAULT + ":2" d3 = Device.DEFAULT + ":3" for i in range(3): t.to_(d1) t.realize() # t.to_("CPU") # t.realize() t.to_(d2) t.realize() t.to_(d3) t.realize()
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/replay_pkl.py
tinygrad_repo/extra/replay_pkl.py
import pickle, sys from dataclasses import replace from tinygrad import Device, Context, Tensor, GlobalCounters from tinygrad.device import Buffer from tinygrad.helpers import getenv, BEAM from tinygrad.engine.jit import TinyJit from tinygrad.engine.realize import CompiledRunner, ExecItem, ScheduleItem, lower_schedule_...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/introspection.py
tinygrad_repo/extra/introspection.py
import gc from tinygrad.helpers import prod from tinygrad.uop.ops import UOp from tinygrad.device import Buffer from tinygrad import Tensor, GlobalCounters def print_objects(): #gc.collect() tensors = [x for x in gc.get_objects() if isinstance(x, Tensor)] tensor_ram_used = sum([prod(x.shape)*4 for x in tensors])...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/mcts_search.py
tinygrad_repo/extra/mcts_search.py
from __future__ import annotations from typing import List, Optional, Dict, cast import numpy as np np.set_printoptions(suppress=True) import math, functools, time, random, statistics from tinygrad.helpers import DEBUG, getenv, CACHELEVEL, diskcache_get, diskcache_put, colored, Profiling from tinygrad.codegen.opt.kerne...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/dump_cache.py
tinygrad_repo/extra/dump_cache.py
import sys, sqlite3, pickle from tinygrad.helpers import CACHEDB if __name__ == "__main__": fn = sys.argv[1] if len(sys.argv) > 1 else CACHEDB conn = sqlite3.connect(fn) cur = conn.cursor() cur.execute("SELECT name FROM sqlite_master WHERE type='table'") for f in cur.fetchall(): table = f[0] cur2 = c...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/disk_read_speed.py
tinygrad_repo/extra/disk_read_speed.py
#!/usr/bin/env python3 import os, ctypes, ctypes.util, io, mmap, pathlib from tinygrad import Tensor, dtypes, Device from tinygrad.helpers import Timing, from_mv libc = ctypes.CDLL(ctypes.util.find_library("c")) #from extra.hip_gpu_driver import hip_ioctl # sudo su -c "echo 3 > /proc/sys/vm/drop_caches" # sudo su -c...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/f16_decompress.py
tinygrad_repo/extra/f16_decompress.py
from tinygrad import Tensor def bit_extract(x: Tensor, e: int, s: int) -> Tensor: mask = (1 << (e - s + 1)) - 1 return (x >> s) & mask def u16_to_f16(x: Tensor) -> Tensor: sign = bit_extract(x, 15, 15).float() exponent = bit_extract(x, 14, 10).float() fraction = bit_extract(x, 9, 0).float() return sign.wh...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/gradcheck.py
tinygrad_repo/extra/gradcheck.py
import numpy as np from tinygrad.tensor import Tensor, _to_np_dtype def mask_like(like, mask_inx, mask_value = 1.0): mask = np.zeros(like.shape, dtype=_to_np_dtype(like.dtype)).reshape(-1) mask[mask_inx] = mask_value return mask.reshape(like.shape) def jacobian(func, input): output = func(input) ji = input...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/augment.py
tinygrad_repo/extra/augment.py
import numpy as np from PIL import Image from pathlib import Path import sys cwd = Path.cwd() sys.path.append(cwd.as_posix()) sys.path.append((cwd / 'test').as_posix()) from extra.datasets import fetch_mnist from tqdm import trange def augment_img(X, rotate=10, px=3): Xaug = np.zeros_like(X) for i in trange(len(X)...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/test_pyrender.py
tinygrad_repo/extra/test_pyrender.py
from extra.optimization.helpers import load_worlds, ast_str_to_ast from tinygrad.helpers import tqdm from tinygrad.uop.ops import pyrender, UOp, Ops from tinygrad import dtypes from tinygrad.shape.shapetracker import ShapeTracker, View inf, nan = float('inf'), float('nan') if __name__ == "__main__": ast_strs = load_...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/hook_cuda.py
tinygrad_repo/extra/hook_cuda.py
import ctypes, struct, platform, pathlib, os, binascii from hexdump import hexdump from tinygrad.helpers import to_mv, DEBUG, getenv from tinygrad.runtime.autogen import libc, cuda from tinygrad.device import CPUProgram from tinygrad.runtime.support.elf import elf_loader from tinygrad.runtime.ops_cuda import cu_time_ex...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/thneed.py
tinygrad_repo/extra/thneed.py
# this can be constructed from a cl_cache or loaded from a thneed file import time import struct import json import traceback import numpy as np from tinygrad.runtime.ops_cl import CLProgram, compile_gpu from tinygrad.device import Device from tinygrad.helpers import DEBUG, getenv from collections import defaultdict im...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/reduce_speed.py
tinygrad_repo/extra/reduce_speed.py
import numpy as np import ctypes from tinygrad import Tensor, GlobalCounters, Context from tinygrad.engine.realize import lower_schedule, CompiledRunner from tinygrad.device import CPUProgram from dataclasses import replace from keystone import Ks, KS_ARCH_ARM64, KS_MODE_LITTLE_ENDIAN # only the memory access, over 10...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/threefry.py
tinygrad_repo/extra/threefry.py
if __name__ == "__main__": import os if "DEBUG" not in os.environ: os.environ["DEBUG"] = "2" from tinygrad import Tensor, GlobalCounters from tinygrad.helpers import getenv if (seed := getenv("SEED", 0)) != 0: Tensor.manual_seed(seed) print(f"using seed {Tensor._seed}") for N in [10_000_000, 100_00...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/lr_scheduler.py
tinygrad_repo/extra/lr_scheduler.py
import math from typing import List from tinygrad.nn.optim import Optimizer from tinygrad.tensor import Tensor class LR_Scheduler: def __init__(self, optimizer: Optimizer): self.optimizer = optimizer self.epoch_counter = Tensor([0], requires_grad=False, device=self.optimizer.device) def get_lr(self): pass...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/torch_muon.py
tinygrad_repo/extra/torch_muon.py
import torch #credit to KellerJordan at https://github.com/KellerJordan/Muon/tree/master #some changes: classic momentum instead of weighting gradient #added ns_steps, ns_params, nesterov as hyperparams def zeropower_via_newtonschulz5(G:torch.tensor, steps:int, params:tuple[int, ...]): """ Newton-Schulz iteration ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/remu/test/hwtest.py
tinygrad_repo/extra/remu/test/hwtest.py
import numpy as np import unittest import subprocess, struct, math from typing import cast from tinygrad.runtime.ops_amd import AMDProgram, AMDDevice from tinygrad import Tensor, dtypes, Device from tinygrad.helpers import diskcache, OSX, getenv @diskcache def assemble(code:str) -> bytes: try: LLVM_MC = "llvm-mc...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/disassemblers/adreno/__init__.py
tinygrad_repo/extra/disassemblers/adreno/__init__.py
import ctypes import os import pathlib import struct from hexdump import hexdump fxn = None def disasm_raw(buf): global fxn if fxn is None: shared = pathlib.Path(__file__).parent / "disasm.so" if not shared.is_file(): os.system(f'cd {pathlib.Path(__file__).parent} && gcc -shared disasm-a3xx.c -o disa...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/hcq/hcq_smi.py
tinygrad_repo/extra/hcq/hcq_smi.py
#!/usr/bin/env python3 from tinygrad.runtime.support.system import System import argparse, glob, os, re, time, subprocess, sys def scan_devs_based_on_lock(prefix:str, args) -> list[str]: target_dev = args.pci_bus if 'pci_bus' in args.__dir__() else "" devs = [] for dev in glob.glob(f'/tmp/{prefix}_*.lock'): ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/huggingface_onnx/run_models.py
tinygrad_repo/extra/huggingface_onnx/run_models.py
import onnx, yaml, tempfile, time, argparse, json from pathlib import Path from typing import Any from tinygrad.frontend.onnx import OnnxRunner from extra.onnx_helpers import validate, get_example_inputs from extra.huggingface_onnx.huggingface_manager import DOWNLOADS_DIR, snapshot_download_with_retry def get_config(r...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/huggingface_onnx/huggingface_manager.py
tinygrad_repo/extra/huggingface_onnx/huggingface_manager.py
import yaml import time import requests import argparse from pathlib import Path from huggingface_hub import list_models, HfApi, snapshot_download from tinygrad.helpers import _ensure_downloads_dir DOWNLOADS_DIR = _ensure_downloads_dir() / "models" from tinygrad.helpers import tqdm def snapshot_download_with_retry(*, ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/hip_gpu_driver/test_pm4.py
tinygrad_repo/extra/hip_gpu_driver/test_pm4.py
import time from hexdump import hexdump from tinygrad import Tensor, Device import tinygrad.runtime.autogen.amd_gpu as amd_gpu import tinygrad.runtime.autogen.kfd as kfd import tinygrad.runtime.autogen.hsa as hsa from tinygrad.runtime.ops_amd import kio, AMDProgram from tinygrad.helpers import to_mv DISPATCH_INIT_VALU...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/hip_gpu_driver/test_sdma_fun.py
tinygrad_repo/extra/hip_gpu_driver/test_sdma_fun.py
import ctypes, mmap, time from tinygrad.runtime.ops_amd import AMDDevice, kio, sdma_pkts, libc import tinygrad.runtime.autogen.amd_sdma as amd_sdma import tinygrad.runtime.autogen.kfd as kfd from tinygrad.helpers import to_mv if __name__ == "__main__": dev = AMDDevice() sdma_ring = dev._gpu_alloc(1 << 22, kfd.KFD...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/hip_gpu_driver/test_kfd_2.py
tinygrad_repo/extra/hip_gpu_driver/test_kfd_2.py
import os, ctypes, pathlib, re, fcntl, functools, mmap, time import tinygrad.runtime.autogen.kfd as kfd from tinygrad.helpers import to_mv, getenv from extra.hip_gpu_driver import hip_ioctl import tinygrad.runtime.autogen.hsa as hsa from hexdump import hexdump libc = ctypes.CDLL("libc.so.6") libc.memset.argtypes = [ct...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/hip_gpu_driver/hip_ioctl.py
tinygrad_repo/extra/hip_gpu_driver/hip_ioctl.py
# type: ignore import ctypes, ctypes.util, struct, platform, pathlib, re, time, os start = time.perf_counter() # *** ioctl lib *** libc = ctypes.CDLL(ctypes.util.find_library("c")) # platform.processor calls `uname -p` which can return `unknown` on some systems processor = os.getenv("IOCTL_PROCESSOR") or platform.proc...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/perfetto/to_perfetto.py
tinygrad_repo/extra/perfetto/to_perfetto.py
import sys, pickle, decimal, json from tinygrad.device import ProfileDeviceEvent, ProfileGraphEvent from tinygrad.helpers import tqdm, temp, ProfileEvent, ProfileRangeEvent, TracingKey devices:dict[str, tuple[decimal.Decimal, decimal.Decimal, int]] = {} def prep_ts(device:str, ts:decimal.Decimal, is_copy): return int(...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/dsp/opt.py
tinygrad_repo/extra/dsp/opt.py
from tinygrad import Device # PATH=/opt/homebrew/opt/llvm/bin:$PATH python3 extra/dsp/opt.py if __name__ == "__main__": compiler = Device["DSP"].compiler lib = compiler.compile(""" typedef long HVX_Vector __attribute__((__vector_size__(128))) __attribute__ ((aligned(128))); typedef long HVX_VectorPair __attribut...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/dsp/run.py
tinygrad_repo/extra/dsp/run.py
# mypy: ignore-errors #!/usr/bin/env python3 import os, ctypes, ctypes.util, struct, platform, time from tinygrad.runtime.autogen import libc, qcom_dsp def to_mv(ptr, sz) -> memoryview: return memoryview(ctypes.cast(ptr, ctypes.POINTER(ctypes.c_uint8 * sz)).contents).cast("B") from hexdump import hexdump def get_struc...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/dsp/run_3.py
tinygrad_repo/extra/dsp/run_3.py
#!/usr/bin/env python3 import os, ctypes, ctypes.util, struct, platform, pathlib, contextlib, mmap, array from threading import Thread from tinygrad.runtime.autogen import qcom_dsp from tinygrad.helpers import round_up, mv_address, to_mv from hexdump import hexdump def get_struct(argp, stype): return ctypes.cast(cty...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/dsp/invoke_bug.py
tinygrad_repo/extra/dsp/invoke_bug.py
from tinygrad.runtime.ops_dsp import DSPDevice kernel = """__attribute__((noinline)) void r_6_10_13_4_4_29(float* restrict __attribute__((align_value(128))) data0, const float* restrict __attribute__((align_value(128))) data1, const float* restrict __attribute__((align_value(128))) data2, const float* restrict __attri...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/dsp/compile.py
tinygrad_repo/extra/dsp/compile.py
#!/usr/bin/env python3 import os, ctypes, time, fcntl, mmap import llvmlite.binding as llvm from tinygrad.helpers import getenv, to_mv from tinygrad.runtime.support.elf import elf_loader from hexdump import hexdump from tinygrad.runtime.autogen import libc if getenv("IOCTL"): import run # noqa: F401 # pylint: disable=u...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/dsp/invoke_bug_2.py
tinygrad_repo/extra/dsp/invoke_bug_2.py
from tinygrad.runtime.ops_dsp import DSPDevice kernel = """__attribute__((noinline)) void r_64_4_4_64_4_4_4(float* restrict __attribute__((align_value(128))) data0, const float* restrict __attribute__((align_value(128))) data1, const float* restrict __attribute__((align_value(128))) data2, const float* restrict __attr...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/dsp/hook.py
tinygrad_repo/extra/dsp/hook.py
import os print("from import") del os.environ["LD_PRELOAD"] import ctypes, ctypes.util from extra.dsp.run import install_hook, ioctl, libc, get_struct, qcom_dsp, format_struct, to_mv, hexdump @ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_long) d...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/dsp/snpe_logs/parse.py
tinygrad_repo/extra/dsp/snpe_logs/parse.py
di = open("dlc_info_2").read().split("\n") layers = {} for l in di: if not l.startswith("| "): continue if l.startswith("| |"): continue ll = [x.strip() for x in l.split("|")] if ll[1] == "Id": continue layers[int(ll[1])] = (ll[2], ll[6]) hp = open("high_perf_2").read().split("Layer Times:")[1].strip().sp...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/optimization/extract_dataset.py
tinygrad_repo/extra/optimization/extract_dataset.py
#!/usr/bin/env python3 # extract asts from process replay artifacts import os from test.external.process_replay.process_replay import _pmap LOGOPS = os.getenv("LOGOPS", "/tmp/sops") def extract_ast(*args) -> None: open(LOGOPS, "a").write(str(args[1]).replace("\n", "").replace(" ", "")+"\n") return None if __name...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/optimization/search.py
tinygrad_repo/extra/optimization/search.py
import argparse from extra.optimization.helpers import ast_str_to_lin, time_linearizer from tinygrad import dtypes from tinygrad.helpers import BEAM, getenv from tinygrad.device import Device, Compiled from tinygrad.codegen.opt.kernel import Kernel from tinygrad.codegen.opt.search import beam_search, bufs_from_lin i...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/optimization/pretrain_valuenet.py
tinygrad_repo/extra/optimization/pretrain_valuenet.py
from tinygrad.codegen.opt.kernel import Kernel from tqdm import tqdm, trange import math import random from tinygrad.tensor import Tensor from tinygrad.nn import Linear from tinygrad.nn.optim import Adam from tinygrad.nn.state import get_parameters, get_state_dict, safe_save, safe_load, load_state_dict # stuff needed ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/optimization/extract_sa_pairs.py
tinygrad_repo/extra/optimization/extract_sa_pairs.py
import sys, sqlite3, pickle, math from collections import defaultdict from tqdm import tqdm, trange import numpy as np # stuff needed to unpack a kernel from tinygrad.uop.ops import LazyOp, TernaryOps, BinaryOps, UnaryOps, ReduceOps, BufferOps, MemBuffer, ConstBuffer from tinygrad.dtype import dtypes from tinygrad.sha...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false