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/extra/hcqfuzz/tests/allreduce.py
tinygrad_repo/extra/hcqfuzz/tests/allreduce.py
from extra.hcqfuzz.spec import TestSpec import random class RingAllreduce(TestSpec): def prepare(self, dev, seed): random.seed(seed) self.env = { "GPUS": random.choice([2, 3, 4, 5, 6]), "ITERS": random.randint(10, 1000), "DEBUG": 2, } self.cmd = "python3 test/external/external_ben...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/hcqfuzz/tests/allocator.py
tinygrad_repo/extra/hcqfuzz/tests/allocator.py
from extra.hcqfuzz.spec import TestSpec import random class TLSFAllocator(TestSpec): def prepare(self, dev, seed): random.seed(seed) self.env = { "SEED": seed, "ITERS": random.randint(10000, 1000000), } self.cmd = "python3 test/external/external_fuzz_tlsf.py" self.timeout = 60 *...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/usbgpu/patch.py
tinygrad_repo/extra/usbgpu/patch.py
#!/usr/bin/env python3 import sys, os, zlib, struct, hashlib from hexdump import hexdump from tinygrad.helpers import DEBUG, getenv, fetch from tinygrad.runtime.support.usb import USB3 def patch(input_filepath, file_hash, patches): with open(input_filepath, 'rb') as infile: data = bytearray(infile.read()) if_hash...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/usbgpu/scan_pci.py
tinygrad_repo/extra/usbgpu/scan_pci.py
import array, time from hexdump import hexdump from tinygrad.runtime.support.usb import ASM24Controller from tinygrad.runtime.autogen import pci usb = ASM24Controller() def print_cfg(bus, dev): cfg = [] for i in range(0, 256, 4): cfg.append(usb.pcie_cfg_req(i, bus=bus, dev=dev, fn=0, value=None, size=4)) p...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/usbgpu/legacy/wr_speed.py
tinygrad_repo/extra/usbgpu/legacy/wr_speed.py
import array, time, ctypes, struct, random from hexdump import hexdump from tinygrad.runtime.support.usb import ASMController, WriteOp from tinygrad.runtime.autogen import pci from tinygrad.helpers import Timing from tinygrad import Device usb = ASMController() xxx = (ctypes.c_uint8 * 4096)() dfg = random.randint(0, ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/usbgpu/legacy/nvme_speed.py
tinygrad_repo/extra/usbgpu/legacy/nvme_speed.py
import array, time, ctypes, struct, random from hexdump import hexdump from tinygrad.runtime.support.usb import ASM24Controller, WriteOp, ScsiWriteOp from tinygrad.runtime.autogen import pci from tinygrad.helpers import Timing from tinygrad import Device usb = ASM24Controller() def real_scsi_write(): self.exec_ops(...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/usbgpu/legacy/patch_exp.py
tinygrad_repo/extra/usbgpu/legacy/patch_exp.py
#!/usr/bin/env python3 import sys import zlib def patch(input_filepath, output_filepath, patches): with open(input_filepath, 'rb') as infile: data = bytearray(infile.read()) for offset, expected_bytes, new_bytes in patches: if len(expected_bytes) != len(new_bytes): print(len(expected_bytes), len(new_byt...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/extra/mmapeak/mmapeak.py
tinygrad_repo/extra/mmapeak/mmapeak.py
import pathlib from tinygrad.device import Device from tinygrad.runtime.ops_amd import AMDProgram, HIPCompiler import time import os NUM_WORKGROUPS = 96 WAVE_SIZE = 32 NUM_WAVES = 2 FLOPS_PER_MATMUL = 16*16*16*2 INTERNAL_LOOP = 1_000_000 INSTRUCTIONS_PER_LOOP = 1_000 assemblyTemplate = (pathlib.Path(__file__).paren...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/docs/abstractions3.py
tinygrad_repo/docs/abstractions3.py
# abstractions2 goes from back to front, here we will go from front to back from typing import List from tinygrad.helpers import tqdm # ***** # 0. Load mnist on the device from tinygrad.nn.datasets import mnist X_train, Y_train, _, _ = mnist() X_train = X_train.float() X_train -= X_train.mean() # ***** # 1. Define a...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/docs/ramp.py
tinygrad_repo/docs/ramp.py
#!/usr/bin/env python3 # this file is a "ramp" for people new to tinygrad to think about how to approach it # it is runnable and editable. # whenever you see stuff like DEBUG=2 or CPU=1 discussed, these are environment variables # in a unix shell like bash `DEBUG=2 CPU=1 python docs/ramp.py` # this pip installs tinyg...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/docs/abstractions2.py
tinygrad_repo/docs/abstractions2.py
# tinygrad is a tensor library, and as a tensor library it has multiple parts # 1. a "runtime". this allows buffer management, compilation, and running programs # 2. a "Device" that uses the runtime but specifies compute in an abstract way for all # 3. a "UOp" that fuses the compute into kernels, using memory only when...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/efficientnet.py
tinygrad_repo/examples/efficientnet.py
# load weights from # https://github.com/lukemelas/EfficientNet-PyTorch/releases/download/1.0/efficientnet-b0-355c32eb.pth # a rough copy of # https://github.com/lukemelas/EfficientNet-PyTorch/blob/master/efficientnet_pytorch/model.py import sys import ast import time import numpy as np from PIL import Image from tinyg...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/stable_diffusion.py
tinygrad_repo/examples/stable_diffusion.py
# https://arxiv.org/pdf/2112.10752.pdf # https://github.com/ekagra-ranjan/huggingface-blog/blob/main/stable_diffusion.md import tempfile from pathlib import Path import argparse, time from collections import namedtuple from typing import Dict, Any from PIL import Image import numpy as np from tinygrad import Device, G...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/stunning_mnist.py
tinygrad_repo/examples/stunning_mnist.py
# beautiful mnist in the new "one-shot" style # one realize in the whole graph # depends on: # - "big graph" UOp scheduling # - symbolic removal from examples.beautiful_mnist import Model from tinygrad import Tensor, nn, getenv, GlobalCounters, Variable from tinygrad.nn.datasets import mnist from tinygrad.helpers im...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/llama3.py
tinygrad_repo/examples/llama3.py
from pathlib import Path from typing import List import json, argparse, random, time, os import tiktoken from tiktoken.load import load_tiktoken_bpe from extra.models.llama import Transformer, convert_from_huggingface, convert_from_gguf, fix_bf16 from tinygrad.nn.state import safe_load, torch_load, load_state_dict, get...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/vgg7.py
tinygrad_repo/examples/vgg7.py
import sys import random import json import numpy from tinygrad.tensor import Tensor from tinygrad.nn.optim import SGD from tinygrad.nn.state import safe_save, safe_load, get_state_dict, load_state_dict from examples.vgg7_helpers.waifu2x import image_load, image_save, Vgg7 # amount of context erased by model CONTEXT =...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mask_rcnn.py
tinygrad_repo/examples/mask_rcnn.py
from extra.models.mask_rcnn import MaskRCNN from extra.models.resnet import ResNet from extra.models.mask_rcnn import BoxList from torch.nn import functional as F from torchvision import transforms as T from torchvision.transforms import functional as Ft import random from tinygrad.tensor import Tensor from PIL import ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/openelm.py
tinygrad_repo/examples/openelm.py
import json, pprint from tinygrad import fetch, nn, Tensor from tinygrad.helpers import DEBUG class FeedForward: def __init__(self, model_dim, intermediate_dim): self.proj_1 = nn.Linear(model_dim, 2*intermediate_dim, bias=False) self.proj_2 = nn.Linear(intermediate_dim, model_dim, bias=False) def __call__...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/self_tokenize.py
tinygrad_repo/examples/self_tokenize.py
import os, pathlib, argparse from examples.llama3 import Tokenizer from tabulate import tabulate from tinygrad import fetch from tinygrad.helpers import flatten # llama 3 tokenizer tokenizer = Tokenizer(fetch("https://huggingface.co/bofenghuang/Meta-Llama-3-8B/resolve/main/original/tokenizer.model").as_posix()) def r...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/test_onnx_imagenet.py
tinygrad_repo/examples/test_onnx_imagenet.py
import random, sys import numpy as np from extra.datasets.imagenet import get_imagenet_categories, get_val_files, center_crop from examples.benchmark_onnx import load_onnx_model from PIL import Image from tinygrad import Tensor, dtypes, GlobalCounters from tinygrad.helpers import fetch, getenv # works: # ~70% - https...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/olmoe.py
tinygrad_repo/examples/olmoe.py
# https://arxiv.org/pdf/2409.02060 import time, functools import numpy as np np.set_printoptions(suppress=True, linewidth=1000) from tinygrad import Tensor, nn, Device, GlobalCounters from tinygrad.helpers import Timing, getenv from extra.models.llama import Transformer, convert_from_huggingface class MixtureFeedForwa...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/whisper.py
tinygrad_repo/examples/whisper.py
# thanks to https://github.com/openai/whisper for a good chunk of MIT licensed code import sys, base64, multiprocessing, itertools, collections from typing import Optional, Union, Literal, List from tinygrad import Tensor, TinyJit, Variable, nn from tinygrad.nn.state import torch_load, load_state_dict from tinygrad.h...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/llama.py
tinygrad_repo/examples/llama.py
#!/usr/bin/env python3 # pip3 install sentencepiece tiktoken blobfile #import typeguard.importhook #typeguard.importhook.install_import_hook('tinygrad') from pathlib import Path from typing import List, Optional import argparse, json from tinygrad import Tensor, Device, GlobalCounters, nn from tinygrad.helpers import ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/benchmark_onnx.py
tinygrad_repo/examples/benchmark_onnx.py
import sys, time from tinygrad import TinyJit, GlobalCounters, fetch, getenv from tinygrad.frontend.onnx import OnnxRunner from extra.onnx_helpers import get_example_inputs, validate def load_onnx_model(onnx_file): run_onnx = OnnxRunner(onnx_file) run_onnx_jit = TinyJit(lambda **kwargs: next(iter(run_onnx({k:v.to(...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/minrf.py
tinygrad_repo/examples/minrf.py
# much taken from https://github.com/cloneofsimo/minRF from tinygrad import Tensor, nn, GlobalCounters, TinyJit from tinygrad.helpers import getenv, trange from extra.models.llama import Attention, FeedForward, precompute_freqs_cis def modulate(x:Tensor, shift:Tensor, scale:Tensor) -> Tensor: return x * (1 + scale.uns...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/conversation.py
tinygrad_repo/examples/conversation.py
import argparse import multiprocessing as mp import os import re import sys import time from contextlib import contextmanager from pathlib import Path import numpy as np import pyaudio import yaml from llama import LLaMa from vits import MODELS as VITS_MODELS from vits import Y_LENGTH_ESTIMATE_SCALARS, HParams, Synthe...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/vit.py
tinygrad_repo/examples/vit.py
import ast import numpy as np from PIL import Image from tinygrad.tensor import Tensor from tinygrad.helpers import getenv, fetch from extra.models.vit import ViT """ fn = "gs://vit_models/augreg/Ti_16-i21k-300ep-lr_0.001-aug_none-wd_0.03-do_0.0-sd_0.0.npz" import tensorflow as tf with tf.io.gfile.GFile(fn, "rb") as f:...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/beautiful_cartpole.py
tinygrad_repo/examples/beautiful_cartpole.py
from typing import Tuple import time from tinygrad import Tensor, TinyJit, nn import gymnasium as gym from tinygrad.helpers import trange import numpy as np # TODO: remove numpy import ENVIRONMENT_NAME = 'CartPole-v1' #ENVIRONMENT_NAME = 'LunarLander-v2' #import examples.rl.lightupbutton #ENVIRONMENT_NAME = 'PressTh...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/serious_mnist.py
tinygrad_repo/examples/serious_mnist.py
#!/usr/bin/env python #inspired by https://github.com/Matuzas77/MNIST-0.17/blob/master/MNIST_final_solution.ipynb import sys import numpy as np from tinygrad.nn.state import get_parameters from tinygrad.tensor import Tensor from tinygrad.nn import BatchNorm2d, optim from tinygrad.helpers import getenv from extra.datase...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/beautiful_mnist.py
tinygrad_repo/examples/beautiful_mnist.py
# model based off https://medium.com/data-science/going-beyond-99-mnist-handwritten-digits-recognition-cfff96337392 from typing import Callable from tinygrad import Tensor, TinyJit, nn, GlobalCounters from tinygrad.helpers import getenv, colored, trange from tinygrad.nn.datasets import mnist class Model: def __init_...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/beautiful_cifar.py
tinygrad_repo/examples/beautiful_cifar.py
import time start_tm = time.perf_counter() import math from typing import Tuple, cast from tinygrad import Tensor, nn, GlobalCounters, TinyJit, dtypes, Device from tinygrad.helpers import partition, trange, getenv, Context from extra.lr_scheduler import OneCycleLR GPUS = [f'{Device.DEFAULT}:{i}' for i in range(getenv(...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/test_pkl_imagenet.py
tinygrad_repo/examples/test_pkl_imagenet.py
import sys, pickle from tinygrad import GlobalCounters from tinygrad.helpers import fetch, getenv from examples.test_onnx_imagenet import imagenet_dataloader if __name__ == "__main__": with open(fetch(sys.argv[1]), "rb") as f: run_onnx_jit = pickle.load(f) input_name = run_onnx_jit.captured.expected_names[0] ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mamba.py
tinygrad_repo/examples/mamba.py
import os, sys, math, argparse, time sys.path.append(os.getcwd()) from typing import Any, Optional, Dict from tinygrad import Tensor, TinyJit, nn from tinygrad.helpers import fetch from tinygrad.nn.state import load_state_dict, torch_load from tqdm import tqdm from transformers import AutoTokenizer MODELS = { "130...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/beautiful_mnist_multigpu.py
tinygrad_repo/examples/beautiful_mnist_multigpu.py
# model based off https://towardsdatascience.com/going-beyond-99-mnist-handwritten-digits-recognition-cfff96337392 from typing import List, Callable from tinygrad import Tensor, TinyJit, nn, GlobalCounters, Device from tinygrad.helpers import getenv, colored, trange from tinygrad.nn.datasets import mnist GPUS = tuple(...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/simple_conv_bn.py
tinygrad_repo/examples/simple_conv_bn.py
from tinygrad.tensor import Tensor from tinygrad.nn import Conv2d, BatchNorm2d from tinygrad.nn.state import get_parameters if __name__ == "__main__": with Tensor.train(): BS, C1, H, W = 4, 16, 224, 224 C2, K, S, P = 64, 7, 2, 1 x = Tensor.uniform(BS, C1, H, W) conv = Conv2d(C1, C2, kernel_size=K, ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/hlb_cifar10.py
tinygrad_repo/examples/hlb_cifar10.py
#!/usr/bin/env python3 # tinygrad implementation of https://github.com/tysam-code/hlb-CIFAR10/blob/main/main.py # https://myrtle.ai/learn/how-to-train-your-resnet-8-bag-of-tricks/ # https://siboehm.com/articles/22/CUDA-MMM import random, time import numpy as np from typing import Optional from extra.lr_scheduler impor...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/flux1.py
tinygrad_repo/examples/flux1.py
# pip3 install sentencepiece # This file incorporates code from the following: # Github Name | License | Link # black-forest-labs/flux | Apache | https://github.com/black-forest-labs/flux/tree/main/model_licenses from tinygrad import Tensor, nn, dtypes, TinyJit from tinygrad.nn.state impor...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/qwq.py
tinygrad_repo/examples/qwq.py
import argparse import os import sys from transformers import AutoTokenizer from pathlib import Path from typing import Dict, Union from extra.models.llama import Transformer, convert_from_huggingface, fix_bf16 from examples.llama3 import load from tinygrad import nn, Tensor, Device from tinygrad.helpers import fetch...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/torch_cuda_kernel.py
tinygrad_repo/examples/torch_cuda_kernel.py
#!POPCORN leaderboard grayscale #!POPCORN gpu A100 # not a stable API, but works import torch from tinygrad import Tensor, TinyJit, Device from tinygrad.helpers import Context, OSX from tinygrad.dtype import _from_torch_dtype @TinyJit def f(tg_out, tg_data): return tg_out.assign(tg_data[:, :, 0] * 0.2989 + tg_data[:,...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/train_resnet.py
tinygrad_repo/examples/train_resnet.py
#!/usr/bin/env python3 import numpy as np from PIL import Image from tinygrad.nn.state import get_parameters from tinygrad.nn import optim from tinygrad.helpers import getenv from extra.training import train, evaluate from extra.models.resnet import ResNet from extra.datasets import fetch_mnist class ComposeTransfor...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/sdv2.py
tinygrad_repo/examples/sdv2.py
from tinygrad import Tensor, dtypes, TinyJit from tinygrad.helpers import fetch from tinygrad.nn.state import safe_load, load_state_dict, get_state_dict from examples.stable_diffusion import AutoencoderKL, get_alphas_cumprod from examples.sdxl import DPMPP2MSampler, append_dims, LegacyDDPMDiscretization from extra.mode...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/yolov3.py
tinygrad_repo/examples/yolov3.py
# https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov3.cfg import sys import io import time import math import cv2 import numpy as np from PIL import Image from tinygrad.tensor import Tensor from tinygrad.nn import BatchNorm2d, Conv2d from tinygrad.helpers import fetch def show_labels(prediction, confi...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/train_efficientnet.py
tinygrad_repo/examples/train_efficientnet.py
import traceback import time from multiprocessing import Process, Queue import numpy as np from tinygrad.nn.state import get_parameters from tinygrad.nn import optim from tinygrad.helpers import getenv, trange from tinygrad.tensor import Tensor from extra.datasets import fetch_cifar from extra.models.efficientnet impor...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/gpt2.py
tinygrad_repo/examples/gpt2.py
#!/usr/bin/env python3 import os, argparse, contextlib from typing import Optional, Union with contextlib.suppress(ImportError): import tiktoken from tinygrad import Tensor, TinyJit, Device, GlobalCounters, Variable, dtypes from tinygrad.uop.ops import UOp from tinygrad.helpers import Timing, DEBUG, JIT, getenv, fetch,...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/__init__.py
tinygrad_repo/examples/__init__.py
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mixtral.py
tinygrad_repo/examples/mixtral.py
import functools, argparse, pathlib from tinygrad import Tensor, nn, Device, GlobalCounters, Variable from tinygrad.helpers import Timing, Profiling, CI, tqdm from tinygrad.nn.state import torch_load, get_state_dict from extra.models.llama import FeedForward, Transformer from extra.bench_log import BenchEvent, WallTime...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/yolov8.py
tinygrad_repo/examples/yolov8.py
from tinygrad.nn import Conv2d, BatchNorm2d from tinygrad.tensor import Tensor import numpy as np from itertools import chain from pathlib import Path import cv2 from collections import defaultdict import time, sys from tinygrad.helpers import fetch from tinygrad.nn.state import safe_load, load_state_dict import json ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/so_vits_svc.py
tinygrad_repo/examples/so_vits_svc.py
# original implementation: https://github.com/svc-develop-team/so-vits-svc from __future__ import annotations import sys, logging, time, io, math, argparse, operator, numpy as np from functools import partial, reduce from pathlib import Path from typing import Tuple, Optional, Type from tinygrad import nn, dtypes, Tens...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
true
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/sdxl.py
tinygrad_repo/examples/sdxl.py
# This file incorporates code from the following: # Github Name | License | Link # Stability-AI/generative-models | MIT | https://github.com/Stability-AI/generative-models/blob/fbdc58cab9f4ee2be7a5e1f2e2787ecd9311942f/LICENSE-CODE # mlfoundations/open_clip | MIT | https://github.com/ml...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/compile_tensorflow.py
tinygrad_repo/examples/compile_tensorflow.py
# An example to compile a small Tensorflow model to extremely portable C code import os, sys os.environ["CPU"] = '1' os.environ["JIT"] = '2' import numpy as np import subprocess import tensorflow as tf import tf2onnx from tinygrad.frontend.onnx import OnnxRunner from tinygrad.tensor import Tensor from tinygrad.helper...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/compile_efficientnet.py
tinygrad_repo/examples/compile_efficientnet.py
from pathlib import Path from extra.models.efficientnet import EfficientNet from tinygrad.tensor import Tensor from tinygrad.nn.state import get_state_dict, safe_save, safe_load, load_state_dict from extra.export_model import export_model from tinygrad.helpers import getenv, fetch import ast if __name__ == "__main__":...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mnist_gan.py
tinygrad_repo/examples/mnist_gan.py
from pathlib import Path import numpy as np import torch from torchvision.utils import make_grid, save_image from tinygrad.nn.state import get_parameters from tinygrad.tensor import Tensor from tinygrad.helpers import trange from tinygrad.nn import optim from extra.datasets import fetch_mnist class LinearGen: def __...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/transformer.py
tinygrad_repo/examples/transformer.py
#!/usr/bin/env python3 import numpy as np import random from tinygrad.nn.state import get_parameters from tinygrad.nn.optim import Adam from extra.training import train, evaluate from extra.models.transformer import Transformer # dataset idea from https://github.com/karpathy/minGPT/blob/master/projects/adder/adder.py...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/vits.py
tinygrad_repo/examples/vits.py
import json, logging, math, re, sys, time, wave, argparse, numpy as np from phonemizer.phonemize import default_separator, _phonemize from phonemizer.backend import EspeakBackend from phonemizer.punctuation import Punctuation from functools import reduce from pathlib import Path from typing import List from tinygrad im...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
true
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/yolov8-onnx.py
tinygrad_repo/examples/yolov8-onnx.py
#!/usr/bin/env python3 import os from ultralytics import YOLO from pathlib import Path from tinygrad.frontend.onnx import OnnxRunner from extra.onnx_helpers import get_example_inputs os.chdir("/tmp") if not Path("yolov8n-seg.onnx").is_file(): model = YOLO("yolov8n-seg.pt") model.export(format="onnx", imgsz=[480,64...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/coder.py
tinygrad_repo/examples/coder.py
#!/usr/bin/env python3 import os, sys, traceback sys.path.append(os.getcwd()) from io import StringIO from contextlib import redirect_stdout from tinygrad import Tensor, nn from tinygrad.helpers import Timing, colored, getenv, fetch from extra.models.llama import Transformer, convert_from_huggingface, fix_bf16 from se...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/rl/lightupbutton.py
tinygrad_repo/examples/rl/lightupbutton.py
import gymnasium as gym import numpy as np from gymnasium.envs.registration import register # a very simple game # one of <size> lights will light up # take the action of the lit up light # in <hard_mode>, you act differently based on the step number and need to track this class PressTheLightUpButton(gym.Env): meta...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/llm.c/train_gpt2.py
tinygrad_repo/examples/llm.c/train_gpt2.py
#!/usr/bin/env python3 import os, math, time import numpy as np from tinygrad import Tensor, nn, fetch, Device, TinyJit, GlobalCounters from dataclasses import dataclass @dataclass class GPTConfig: block_size: int = 1024 vocab_size: int = 50257 padded_vocab_size: int = 50304 n_layer: int = 12 n_head: int = 1...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/llm.c/export.py
tinygrad_repo/examples/llm.c/export.py
#!/usr/bin/env python3 import os if "NOOPT" not in os.environ: os.environ["NOOPT"] = "1" from tinygrad import Device, nn, Tensor, dtypes Device.DEFAULT = "CPU" from train_gpt2 import GPT, GPTConfig from tinygrad.helpers import dedup, flatten, getenv, GlobalCounters, to_function_name from tinygrad.engine.realize import ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mlperf/metrics.py
tinygrad_repo/examples/mlperf/metrics.py
import re, string from collections import Counter from tinygrad import Tensor def levenshtein(a, b): n, m = len(a), len(b) if n > m: a, b, n, m = b, a, m, n current = list(range(n + 1)) for i in range(1, m + 1): previous, current = current, [i] + [0] * n for j in range(1, n + 1): add, delete...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mlperf/model_spec.py
tinygrad_repo/examples/mlperf/model_spec.py
# load each model here, quick benchmark from tinygrad import Tensor, GlobalCounters from tinygrad.helpers import getenv import numpy as np def test_model(model, *inputs): GlobalCounters.reset() out = model(*inputs) if isinstance(out, Tensor): out = out.numpy() # TODO: return event future to still get the time_...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mlperf/model_train.py
tinygrad_repo/examples/mlperf/model_train.py
import os, time, math, functools, random, contextlib from pathlib import Path import multiprocessing from tinygrad import Device, GlobalCounters, Tensor, TinyJit, dtypes from tinygrad.helpers import getenv, BEAM, WINO, round_up, diskcache_clear, FUSE_CONV_BW, Profiling from tinygrad.nn.state import get_parameters, get...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
true
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mlperf/model_eval.py
tinygrad_repo/examples/mlperf/model_eval.py
import time, math start = time.perf_counter() from pathlib import Path import numpy as np from tinygrad import Tensor, Device, dtypes, GlobalCounters, TinyJit from tinygrad.nn.state import get_parameters, load_state_dict, safe_load from tinygrad.helpers import getenv from extra.bench_log import BenchEvent, WallTimeEven...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mlperf/initializers.py
tinygrad_repo/examples/mlperf/initializers.py
import math from typing import Union from tinygrad import Tensor, nn, dtypes from tinygrad.helpers import prod, argfix # rejection sampling truncated randn def rand_truncn(*shape, dtype=None, truncstds=2, **kwargs) -> Tensor: CNT=8 x = Tensor.randn(*(*shape, CNT), dtype=dtype, **kwargs) ctr = Tensor.arange(CNT)...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mlperf/helpers.py
tinygrad_repo/examples/mlperf/helpers.py
from collections import OrderedDict import unicodedata from typing import Optional import math import numpy as np from tinygrad.nn import state from tinygrad.tensor import Tensor, dtypes from tinygrad.helpers import getenv # # checkpointing utils # def invert_dict(d): return {v: k for k, v in reversed(d.items())} def...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mlperf/losses.py
tinygrad_repo/examples/mlperf/losses.py
from examples.mlperf.metrics import dice_score from tinygrad import Tensor def dice_ce_loss(pred, tgt): ce = pred.permute(0, 2, 3, 4, 1).sparse_categorical_crossentropy(tgt.squeeze(1)) dice = (1.0 - dice_score(pred, tgt, argmax=False, to_one_hot_x=False)).mean() return (dice + ce) / 2 def sigmoid_focal_loss(pre...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mlperf/lr_schedulers.py
tinygrad_repo/examples/mlperf/lr_schedulers.py
import math from tinygrad import dtypes from tinygrad.nn.optim import Optimizer from extra.lr_scheduler import LR_Scheduler # https://github.com/mlcommons/training/blob/e237206991d10449d9675d95606459a3cb6c21ad/image_classification/tensorflow2/lars_util.py class PolynomialDecayWithWarmup(LR_Scheduler): def __init__(...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/mlperf/dataloader.py
tinygrad_repo/examples/mlperf/dataloader.py
import os, random, pickle, queue, struct, math, functools, hashlib, time from typing import List from pathlib import Path from multiprocessing import Queue, Process, shared_memory, connection, Lock, cpu_count import numpy as np from tinygrad import dtypes, Tensor from tinygrad.helpers import getenv, prod, Context, rou...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/other_mnist/beautiful_mnist_mlx.py
tinygrad_repo/examples/other_mnist/beautiful_mnist_mlx.py
from tinygrad.helpers import trange from tinygrad.nn.datasets import mnist import mlx.core as mx import mlx.nn as nn import mlx.optimizers as optim from functools import partial class Model(nn.Module): def __init__(self): super().__init__() self.c1 = nn.Conv2d(1, 32, 5) self.c2 = nn.Conv2d(32, 32, 5) ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/other_mnist/beautiful_mnist_torch.py
tinygrad_repo/examples/other_mnist/beautiful_mnist_torch.py
from tinygrad import dtypes, getenv, Device from tinygrad.helpers import trange, colored, DEBUG, temp from tinygrad.nn.datasets import mnist import torch from torch import nn, optim class Model(nn.Module): def __init__(self): super().__init__() self.c1 = nn.Conv2d(1, 32, 5) self.c2 = nn.Conv2d(32, 32, 5)...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/vgg7_helpers/waifu2x.py
tinygrad_repo/examples/vgg7_helpers/waifu2x.py
# Implementation of waifu2x vgg7 in tinygrad. # Obviously, not developed, supported, etc. by the original waifu2x author(s). import numpy from tinygrad.tensor import Tensor from PIL import Image from tinygrad.helpers import fetch # File Formats # tinygrad convolution tensor input layout is (1,c,y,x) - and therefore ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/tinychat/tinychat-browser/compile.py
tinygrad_repo/examples/tinychat/tinychat-browser/compile.py
import os, json, hashlib, math from extra.export_model import export_model from examples.llama3 import build_transformer, Tokenizer from tinygrad.nn.state import get_state_dict, load_state_dict from tinygrad import Device, Variable, Tensor, dtypes, TinyJit from tinygrad.helpers import fetch, Context from tiktoken.load ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/sovits_helpers/preprocess.py
tinygrad_repo/examples/sovits_helpers/preprocess.py
import math from typing import Optional, Tuple from tinygrad import Tensor, dtypes import librosa import soundfile import numpy as np import parselmouth class PMF0Predictor: # from https://github.com/svc-develop-team/so-vits-svc/ def __init__(self,hop_length=512,f0_min=50,f0_max=1100,sampling_rate=44100): self....
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/openpilot/compile3.py
tinygrad_repo/examples/openpilot/compile3.py
import os, sys, pickle, time import numpy as np if "FLOAT16" not in os.environ: os.environ["FLOAT16"] = "1" if "IMAGE" not in os.environ: os.environ["IMAGE"] = "2" if "NOLOCALS" not in os.environ: os.environ["NOLOCALS"] = "1" if "JIT_BATCH_SIZE" not in os.environ: os.environ["JIT_BATCH_SIZE"] = "0" from tinygrad impor...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/openpilot/compile4.py
tinygrad_repo/examples/openpilot/compile4.py
import sys from tinygrad import Tensor, fetch, GlobalCounters, dtypes from tinygrad.uop.ops import UOp from tinygrad.frontend.onnx import OnnxRunner from tinygrad.schedule.kernelize import get_kernelize_map from tinygrad.engine.schedule import create_schedule_with_vars from tinygrad.engine.realize import run_schedule ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/webgpu/yolov8/compile.py
tinygrad_repo/examples/webgpu/yolov8/compile.py
from pathlib import Path from examples.yolov8 import YOLOv8, get_weights_location from tinygrad.tensor import Tensor from tinygrad.nn.state import safe_save from extra.export_model import export_model from tinygrad.device import Device from tinygrad.nn.state import safe_load, load_state_dict if __name__ == "__main__":...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/tinygrad_repo/examples/webgpu/stable_diffusion/compile.py
tinygrad_repo/examples/webgpu/stable_diffusion/compile.py
import os from extra.export_model import compile_net, jit_model, dtype_to_js_type from extra.f16_decompress import u32_to_f16 from examples.stable_diffusion import StableDiffusion from tinygrad.nn.state import get_state_dict, safe_save, safe_load_metadata, torch_load, load_state_dict from tinygrad.tensor import Tensor ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/msgq_repo/site_scons/site_tools/cython.py
msgq_repo/site_scons/site_tools/cython.py
import re import SCons from SCons.Action import Action from SCons.Scanner import Scanner pyx_from_import_re = re.compile(r'^from\s+(\S+)\s+cimport', re.M) pyx_import_re = re.compile(r'^cimport\s+(\S+)', re.M) cdef_import_re = re.compile(r'^cdef extern from\s+.(\S+).:', re.M) def pyx_scan(node, env, path, arg=None): ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/msgq_repo/msgq/__init__.py
msgq_repo/msgq/__init__.py
# must be built with scons from msgq.ipc_pyx import Context, Poller, SubSocket, PubSocket, SocketEventHandle, toggle_fake_events, \ set_fake_prefix, get_fake_prefix, delete_fake_prefix, wait_for_one_event from msgq.ipc_pyx import MultiplePublishersError, IpcError from typing import Opti...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/msgq_repo/msgq/visionipc/__init__.py
msgq_repo/msgq/visionipc/__init__.py
from msgq.visionipc.visionipc_pyx import VisionBuf, VisionIpcClient, VisionIpcServer, VisionStreamType, get_endpoint_name assert VisionBuf assert VisionIpcClient assert VisionIpcServer assert VisionStreamType assert get_endpoint_name
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/msgq_repo/msgq/visionipc/tests/test_visionipc.py
msgq_repo/msgq/visionipc/tests/test_visionipc.py
import os import time import random import numpy as np from msgq.visionipc import VisionIpcServer, VisionIpcClient, VisionStreamType def zmq_sleep(t=1): if "ZMQ" in os.environ: time.sleep(t) class TestVisionIpc: def setup_vipc(self, name, *stream_types, num_buffers=1, width=100, height=100, conflate=False):...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/msgq_repo/msgq/visionipc/tests/__init__.py
msgq_repo/msgq/visionipc/tests/__init__.py
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/msgq_repo/msgq/tests/test_poller.py
msgq_repo/msgq/tests/test_poller.py
import pytest import time import msgq import concurrent.futures SERVICE_NAME = 'myService' def poller(): context = msgq.Context() p = msgq.Poller() sub = msgq.SubSocket() sub.connect(context, SERVICE_NAME) p.registerSocket(sub) socks = p.poll(10000) r = [s.receive(non_blocking=True) for s in socks] ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/msgq_repo/msgq/tests/test_messaging.py
msgq_repo/msgq/tests/test_messaging.py
import os import random import time import string import msgq def random_sock(): return ''.join(random.choices(string.ascii_uppercase + string.digits, k=10)) def random_bytes(length=1000): return bytes([random.randrange(0xFF) for _ in range(length)]) def zmq_sleep(t=1): if "ZMQ" in os.environ: time.sleep(...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/msgq_repo/msgq/tests/test_fake.py
msgq_repo/msgq/tests/test_fake.py
import pytest import os import multiprocessing import platform import msgq from parameterized import parameterized_class from typing import Optional WAIT_TIMEOUT = 5 @pytest.mark.skipif(condition=platform.system() == "Darwin", reason="Events not supported on macOS") class TestEvents: def test_mutation(self): ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/msgq_repo/msgq/tests/__init__.py
msgq_repo/msgq/tests/__init__.py
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/site_scons/site_tools/cython.py
site_scons/site_tools/cython.py
import re import SCons from SCons.Action import Action from SCons.Scanner import Scanner import numpy as np pyx_from_import_re = re.compile(r'^from\s+(\S+)\s+cimport', re.M) pyx_import_re = re.compile(r'^cimport\s+(\S+)', re.M) cdef_import_re = re.compile(r'^cdef extern from\s+.(\S+).:', re.M) np_version = SCons.Scri...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/params.py
common/params.py
from openpilot.common.params_pyx import Params, ParamKeyType, UnknownKeyName assert Params assert ParamKeyType assert UnknownKeyName if __name__ == "__main__": import sys params = Params() key = sys.argv[1] assert params.check_key(key), f"unknown param: {key}" if len(sys.argv) == 3: val = sys.argv[2] ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/run.py
common/run.py
import subprocess def run_cmd(cmd: list[str], cwd=None, env=None) -> str: return subprocess.check_output(cmd, encoding='utf8', cwd=cwd, env=env).strip() def run_cmd_default(cmd: list[str], default: str = "", cwd=None, env=None) -> str: try: return run_cmd(cmd, cwd=cwd, env=env) except subprocess.CalledPro...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/file_helpers.py
common/file_helpers.py
import io import os import tempfile import contextlib import zstandard as zstd LOG_COMPRESSION_LEVEL = 10 # little benefit up to level 15. level ~17 is a small step change class CallbackReader: """Wraps a file, but overrides the read method to also call a callback function with the number of bytes read so far.""...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/text_window.py
common/text_window.py
#!/usr/bin/env python3 import os import time import subprocess from openpilot.common.basedir import BASEDIR class TextWindow: def __init__(self, text): try: self.text_proc = subprocess.Popen(["./text", text], stdin=subprocess.PIPE, ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/simple_kalman.py
common/simple_kalman.py
import numpy as np def get_kalman_gain(dt, A, C, Q, R, iterations=100): P = np.zeros_like(Q) for _ in range(iterations): P = A.dot(P).dot(A.T) + dt * Q S = C.dot(P).dot(C.T) + R K = P.dot(C.T).dot(np.linalg.inv(S)) P = (np.eye(len(P)) - K.dot(C)).dot(P) return K class KF1D: # this EKF assume...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/spinner.py
common/spinner.py
import os import subprocess from openpilot.common.basedir import BASEDIR class Spinner: def __init__(self): try: self.spinner_proc = subprocess.Popen(["./spinner"], stdin=subprocess.PIPE, cwd=os.path.join(BASEDIR, "selfd...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/time_helpers.py
common/time_helpers.py
import datetime from pathlib import Path MIN_DATE = datetime.datetime(year=2025, month=2, day=21) def min_date(): # on systemd systems, the default time is the systemd build time systemd_path = Path("/lib/systemd/systemd") if systemd_path.exists(): d = datetime.datetime.fromtimestamp(systemd_path.stat().st_...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/pid.py
common/pid.py
import numpy as np from numbers import Number class PIDController: def __init__(self, k_p, k_i, k_f=0., k_d=0., pos_limit=1e308, neg_limit=-1e308, rate=100): self._k_p = k_p self._k_i = k_i self._k_d = k_d self.k_f = k_f # feedforward gain if isinstance(self._k_p, Number): self._k_p = [[0...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/api.py
common/api.py
import jwt import os import requests from datetime import datetime, timedelta, UTC from openpilot.system.hardware.hw import Paths from openpilot.system.version import get_version API_HOST = os.getenv('API_HOST', 'https://api.commadotai.com') class Api: def __init__(self, dongle_id): self.dongle_id = dongle_id ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/timeout.py
common/timeout.py
import signal class TimeoutException(Exception): pass class Timeout: """ Timeout context manager. For example this code will raise a TimeoutException: with Timeout(seconds=5, error_msg="Sleep was too long"): time.sleep(10) """ def __init__(self, seconds, error_msg=None): if error_msg is None: ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/util.py
common/util.py
import os import subprocess def sudo_write(val: str, path: str) -> None: try: with open(path, 'w') as f: f.write(str(val)) except PermissionError: os.system(f"sudo chmod a+w {path}") try: with open(path, 'w') as f: f.write(str(val)) except PermissionError: # fallback for d...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/constants.py
common/constants.py
import numpy as np # conversions class CV: # Speed MPH_TO_KPH = 1.609344 KPH_TO_MPH = 1. / MPH_TO_KPH MS_TO_KPH = 3.6 KPH_TO_MS = 1. / MS_TO_KPH MS_TO_MPH = MS_TO_KPH * KPH_TO_MPH MPH_TO_MS = MPH_TO_KPH * KPH_TO_MS MS_TO_KNOTS = 1.9438 KNOTS_TO_MS = 1. / MS_TO_KNOTS # Angle DEG_TO_RAD = np.pi / ...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false
ajouatom/openpilot
https://github.com/ajouatom/openpilot/blob/b0eab6e8de2d57522b657426fbb794f2d736c75c/common/git.py
common/git.py
from functools import cache import subprocess from openpilot.common.run import run_cmd, run_cmd_default @cache def get_commit(cwd: str = None, branch: str = "HEAD") -> str: return run_cmd_default(["git", "rev-parse", branch], cwd=cwd) @cache def get_commit_date(cwd: str = None, commit: str = "HEAD") -> str: ret...
python
MIT
b0eab6e8de2d57522b657426fbb794f2d736c75c
2026-01-05T07:04:53.428285Z
false