repo
stringlengths
7
90
file_url
stringlengths
81
315
file_path
stringlengths
4
228
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 14:38:15
2026-01-05 02:33:18
truncated
bool
2 classes
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hcqfuzz/tests/resnet.py
extra/hcqfuzz/tests/resnet.py
from extra.hcqfuzz.spec import TestSpec import random resnet_train_params = { "DEFAULT_FLOAT": "HALF", "SUM_DTYPE": "HALF", "GPUS": 6, "BS": 1536, "EVAL_BS": 192, "TRAIN_BEAM": 4, "IGNORE_JIT_FIRST_BEAM": 1, "BEAM_UOPS_MAX": 2000, "BEAM_UPCAST_MAX": 96, "BEAM_LOCAL_MAX": 1024, "BEAM_MIN_PROGRESS"...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hcqfuzz/tests/hcq.py
extra/hcqfuzz/tests/hcq.py
from extra.hcqfuzz.spec import TestSpec import random class HCQSignalFuzzer(TestSpec): def prepare(self, dev, seed): random.seed(seed) self.env = { "GPUS": random.choice([2, 3, 4, 5, 6]), "ITERS": random.randint(1000000, 10000000), "SEED": seed, } self.cmd = "python3 test/external...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hcqfuzz/tests/allreduce.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/hcqfuzz/tests/allocator.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/usbgpu/patch.py
extra/usbgpu/patch.py
#!/usr/bin/env python3 import sys, os, zlib, struct, hashlib from tinygrad.helpers import DEBUG, getenv, fetch from tinygrad.runtime.support.usb import USB3 SUPPORTED_CONTROLLERS = [ (0x174C, 0x2464), (0x174C, 0x2463), (0xADD1, 0x0001), ] if getenv("USBDEV", ""): SUPPORTED_CONTROLLERS.insert(0, (int(x, 16) for x...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/usbgpu/scan_pci.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/usbgpu/legacy/wr_speed.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/usbgpu/legacy/nvme_speed.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/usbgpu/legacy/patch_exp.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/usbgpu/tbgpu/main.py
extra/usbgpu/tbgpu/main.py
import ctypes, ctypes.util, sys cf = ctypes.CDLL(ctypes.util.find_library("CoreFoundation")) iokit = ctypes.CDLL(ctypes.util.find_library("IOKit")) libsys = ctypes.CDLL(ctypes.util.find_library("System")) kern_return_t = ctypes.c_int mach_port_t = ctypes.c_uint io_object_t = mach_port_t io_service_t = io_object_t io_...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/extra/mmapeak/mmapeak.py
extra/mmapeak/mmapeak.py
import os, pathlib # TODO: there is a timing bug without this os.environ["AMD_AQL"] = "1" from tinygrad.device import Device from tinygrad.runtime.support.compiler_amd import HIPCompiler from tinygrad.runtime.ops_amd import AMDProgram NUM_WORKGROUPS = 96 WAVE_SIZE = 32 NUM_WAVES = 2 FLOPS_PER_MATMUL = 16*16*16*2 INT...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/docs/abstractions3.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/stable_diffusion.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/stunning_mnist.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/llama3.py
examples/llama3.py
from pathlib import Path from typing import List import json, argparse, random, time, os 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_parameters, gguf_load from tinygrad import Tensor, dtypes, ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/vgg7.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/test_onnx_imagenet.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/olmoe.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/whisper.py
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, dtypes from tinygrad.nn.state import torch_load, load_state_dict from ti...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/llama.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/benchmark_onnx.py
examples/benchmark_onnx.py
import sys, time from tinygrad import TinyJit, GlobalCounters, fetch, getenv from tinygrad.nn.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(None) ...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/minrf.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/beautiful_cartpole.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/beautiful_mnist.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/beautiful_cifar.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/test_pkl_imagenet.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/mamba.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/beautiful_mnist_multigpu.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/gradaccum_mnist.py
examples/gradaccum_mnist.py
import itertools from typing import Callable from tinygrad import nn, Tensor, dtypes, Device, TinyJit from tinygrad.helpers import getenv, trange, partition class Model: def __init__(self): self.layers: list[Callable[[Tensor], Tensor]] = [ nn.Conv2d(1, 32, 5), Tensor.relu, nn.Conv2d(32, 32, 5), Tenso...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/hlb_cifar10.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/qwq.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/torch_cuda_kernel.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/train_resnet.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/sdv2.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/yolov3.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/gpt2.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/__init__.py
examples/__init__.py
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/mixtral.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/yolov8.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/sdxl.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/compile_tensorflow.py
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.nn.onnx import OnnxRunner from tinygrad.tensor import Tensor from tinygrad.helpers impo...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/compile_efficientnet.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/mnist_gan.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/transformer.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/yolov8-onnx.py
examples/yolov8-onnx.py
#!/usr/bin/env python3 import os from ultralytics import YOLO from pathlib import Path from tinygrad.nn.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,640]) ru...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/tools/gpuburn.py
examples/tools/gpuburn.py
from tinygrad import Tensor, Device, TinyJit, dtypes from tinygrad.helpers import getenv GPUS = getenv("GPUS", 4) # TODO: expose a way in tinygrad to access this N = 6144 @TinyJit def many_matmul(A, B): out = A for _ in range(8): out = out@B return out if __name__ == "__main__": A = Tensor.ones(GPUS, N, N, d...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/tools/bandwidth_test.py
examples/tools/bandwidth_test.py
#!/usr/bin/env python3 from tinygrad import Tensor, Device, GlobalCounters, Context, dtypes from tinygrad.helpers import getenv, colored SZ = 8_000_000_000 GPUS = getenv("GPUS", 4) # TODO: expose a way in tinygrad to access this if __name__ == "__main__": # create tensors tens = [Tensor.ones(SZ, dtype=dtypes.uint...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/llm.c/train_gpt2.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/llm.c/export.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/mlperf/metrics.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/mlperf/model_spec.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/mlperf/model_train.py
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, Profiling from tinygrad.nn.state import get_parameters, get_state_dict, l...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
true
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/mlperf/model_eval.py
examples/mlperf/model_eval.py
import time, math, os 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, Context, prod from extra.bench_log import Bench...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/mlperf/initializers.py
examples/mlperf/initializers.py
import math from typing import Union from tinygrad import Tensor, nn, dtypes from tinygrad.helpers import prod, argfix, Context from tinygrad.nn.state import get_parameters from extra.models.unet import UNetModel # rejection sampling truncated randn def rand_truncn(*shape, dtype=None, truncstds=2, **kwargs) -> Tensor...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/mlperf/helpers.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/mlperf/losses.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/mlperf/lr_schedulers.py
examples/mlperf/lr_schedulers.py
import math from tinygrad import dtypes, Tensor from tinygrad.nn.optim import Optimizer from extra.lr_scheduler import LR_Scheduler from typing import Callable # https://github.com/mlcommons/training/blob/e237206991d10449d9675d95606459a3cb6c21ad/image_classification/tensorflow2/lars_util.py class PolynomialDecayWithW...
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/mlperf/dataloader.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/other_mnist/beautiful_mnist_torch.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/vgg7_helpers/waifu2x.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/tinychat/tinychat-browser/compile.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/openpilot/compile3.py
examples/openpilot/compile3.py
import os, sys, pickle, time, re import numpy as np if "JIT_BATCH_SIZE" not in os.environ: os.environ["JIT_BATCH_SIZE"] = "0" from tinygrad import fetch, Tensor, TinyJit, Context, GlobalCounters, Device, dtypes from tinygrad.helpers import DEBUG, getenv from tinygrad.engine.realize import CompiledRunner from tinygrad....
python
MIT
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/webgpu/yolov8/compile.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
tinygrad/tinygrad
https://github.com/tinygrad/tinygrad/blob/bf356ae99621f42ad218b902ae7afdcb1f4a2f03/examples/webgpu/stable_diffusion/compile.py
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
bf356ae99621f42ad218b902ae7afdcb1f4a2f03
2026-01-04T14:43:17.197982Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/bin/geo-proxy.py
bin/geo-proxy.py
import gevent from gevent.pywsgi import WSGIServer from gevent.queue import Queue from gevent.monkey import patch_all from gevent.subprocess import Popen, PIPE, STDOUT patch_all() import sys import os import json from flask import ( Flask, request, render_template, send_from_directory, send_file,...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/bin/srv.py
bin/srv.py
#!/usr/bin/env python # vim: set encoding=utf-8 from gevent.pywsgi import WSGIServer from gevent.monkey import patch_all patch_all() # pylint: disable=wrong-import-position,wrong-import-order import sys import os import jinja2 from flask import Flask, request, send_from_directory, send_file APP = Flask(__name__) ...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/bin/proxy.py
bin/proxy.py
# vim: fileencoding=utf-8 """ The proxy server acts as a backend for the wttr.in service. It caches the answers and handles various data sources transforming their answers into format supported by the wttr.in service. If WTTRIN_TEST is specified, it works in a special test mode: it does not fetch and does not store...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/buttons.py
lib/buttons.py
TWITTER_BUTTON = """ <a href="https://twitter.com/igor_chubin?ref_src=twsrc%5Etfw" class="twitter-follow-button" data-show-count="false">Follow @igor_chubin</a><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script> """ GITHUB_BUTTON = """ <a aria-label="Star chubin/wttr.in on GitHub" dat...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/proxy_log.py
lib/proxy_log.py
""" Logger of proxy queries """ # pylint: disable=consider-using-with,too-few-public-methods import datetime class Logger: """ Generic logger. For specific loggers, _shorten_query() should be rewritten. """ def __init__(self, filename_access, filename_errors): self._filename_access =...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/constants.py
lib/constants.py
# vim: fileencoding=utf-8 WWO_CODE = { "113": "Sunny", "116": "PartlyCloudy", "119": "Cloudy", "122": "VeryCloudy", "143": "Fog", "176": "LightShowers", "179": "LightSleetShowers", "182": "LightSleet", "185": "LightSleet", "200": "ThunderyShowers", "227": "LightSnow", "2...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/wttr_srv.py
lib/wttr_srv.py
#!/usr/bin/env python # vim: set encoding=utf-8 """ Main wttr.in rendering function implementation """ import logging import io import os import time from gevent.threadpool import ThreadPool from flask import render_template, send_file, make_response import fmt.png import parse_query from translations import ( ...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/translations.py
lib/translations.py
# vim: fileencoding=utf-8 """ Translation of almost everything. """ FULL_TRANSLATION = [ "am", "ar", "af", "be", "bn", "ca", "da", "de", "el", "et", "fr", "fa", "gl", "hi", "hu", "ia", "id", "it", "lt", "mg", "nb", "nl", "oc",...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
true
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/airports.py
lib/airports.py
import csv AIRPORTS_DAT_FILE = "/home/igor/wttrin-geo/share/airports.dat" def load_aiports_index(): file_ = open(AIRPORTS_DAT_FILE, "r") reader = csv.reader(file_) airport_index = {} for line in reader: airport_index[line[4]] = line return airport_index AIRPORTS_INDEX = load_aiports_i...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/translations_v2.py
lib/translations_v2.py
# vim: fileencoding=utf-8 """ Translation of v2 """ # pylint: disable=line-too-long,bad-whitespace V2_TRANSLATION = { "en": ( "Weather report for:", "Weather", "Timezone", "Now", "Dawn", "Sunrise", "Zenith", "Sunset", "Dusk", ), "af":...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/limits.py
lib/limits.py
""" Connection limitation. Number of connections from one IP is limited. We have nothing against scripting and automated queries. Even the opposite, we encourage them. But there are some connection limits that even we can't handle. Currently the limits are quite restrictive, but they will be relaxed in the future. Us...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/parse_query.py
lib/parse_query.py
import re import json import zlib import base64 def serialize(parsed_query): return base64.b64encode( zlib.compress(json.dumps(parsed_query).encode("utf-8")), altchars=b"-_" ).decode("utf-8") def deserialize(url): string = url[2:] extension = None if "." in string: string, exte...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/metno.py
lib/metno.py
#!/bin/env python # vim: fileencoding=utf-8 from datetime import datetime, timedelta import json import logging import os import re import sys import timezonefinder from pytz import timezone from constants import WWO_CODE logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO")) logger = logging.getLogger(__name...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/duplicate_translations.py
lib/duplicate_translations.py
import os def remove_colon_and_strip_from_str(line): """ Removes the colon from the line and strips the line. """ return line.replace(":", "").strip() def print_result_for_file(file_path, file_name, duplicate_entries): """ Prints the result for a given file. """ print("-" * 50) p...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/location.py
lib/location.py
""" All location related functions and converters. The main entry point is `location_processing` which gets `location` and `source_ip_address` and basing on this information generates precise location description. [query] --> [location] --> [(lat,long)] --> ^ ...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/extract_emoji.py
lib/extract_emoji.py
#!/usr/bin/env python # vim: fileencoding=utf-8 """ At the moment, Pillow library does not support colorful emojis, that is why emojis must be extracted to external files first, and then they must be handled as usual graphical objects and not as text. The files are extracted using Imagemagick. Usage: ve/bi/pyt...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/fields.py
lib/fields.py
""" Human readable description of the available data fields describing current weather, weather forecast, and astronomical data """ DESCRIPTION = { # current condition fields "FeelsLikeC": ( "Feels Like Temperature in Celsius", "temperature_feels_like_celsius", ), "FeelsLikeF": ( ...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/globals.py
lib/globals.py
""" global configuration of the project External environment variables: WTTR_MYDIR WTTR_GEOLITE WTTR_WEGO WTTR_LISTEN_HOST WTTR_LISTEN_PORT WTTR_USER_AGENT """ from __future__ import print_function import logging import os import re MYDIR = os.path.abspath(os.path.dirname(os.path.dirname("_...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/cache.py
lib/cache.py
""" LRU-Cache implementation for formatted (`format=`) answers """ import datetime import re import time import os import hashlib import random import pytz import pylru from globals import LRU_CACHE CACHE_SIZE = 10000 CACHE = pylru.lrucache(CACHE_SIZE) # strings longer than this are stored not in ram # but in the ...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/weather_data.py
lib/weather_data.py
""" Weather data source """ import json import requests from globals import WWO_KEY def get_weather_data(location, lang): """ Get weather data for `location` """ key = WWO_KEY url = ( "/premium/v1/weather.ashx" "?key=%s&q=%s&format=json" "&num_of_days=3&tp=3&lang=%s" )...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/view/prometheus.py
lib/view/prometheus.py
""" Rendering weather data in the Prometheus format. """ from datetime import datetime from fields import DESCRIPTION def _render_current(data, for_day="current", already_seen=[]): "Converts data into prometheus style format" output = [] for field_name, val in DESCRIPTION.items(): help, name...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/view/wttr.py
lib/view/wttr.py
# vim: set encoding=utf-8 # pylint: disable=wrong-import-position """ Main view (wttr.in) implementation. The module is a wrapper for the modified Wego program. """ import sys import re from gevent.subprocess import Popen, PIPE sys.path.insert(0, "..") from translations import get_message, SUPPORTED_LANGS from glob...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/view/moon.py
lib/view/moon.py
import sys import os import dateutil.parser from gevent.subprocess import Popen, PIPE sys.path.insert(0, "..") import constants import parse_query import globals def get_moon(parsed_query): location = parsed_query["orig_location"] html = parsed_query["html_output"] lang = parsed_query["lang"] hemi...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/view/__init__.py
lib/view/__init__.py
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/view/line.py
lib/view/line.py
# vim: fileencoding=utf-8 """ One-line output mode. Initial implementation of one-line output mode. [ ] forecast [ ] spark [ ] several locations [ ] location handling [ ] more preconfigured format lines [ ] add information about this mode to /:help """ import sys import re import datetime import json import request...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/view/v2.py
lib/view/v2.py
# vim: fileencoding=utf-8 # vim: foldmethod=marker foldenable: """ [X] emoji [ ] wego icon [ ] v2.wttr.in [X] astronomical (sunset) [X] time [X] frames [X] colorize rain data [ ] date + locales [X] wind color [ ] highlight current date [ ] bind to real site [ ] max values: temperature [X] max value: rain [ ] comment g...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/fmt/unicodedata2.py
lib/fmt/unicodedata2.py
# downloaded from https://gist.github.com/2204527 # described/recommended here: # # http://stackoverflow.com/questions/9868792/find-out-the-unicode-script-of-a-character # from __future__ import print_function from unicodedata import * script_data = { "names": [ "Common", "Latin", "Greek...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
true
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/fmt/__init__.py
lib/fmt/__init__.py
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
chubin/wttr.in
https://github.com/chubin/wttr.in/blob/f1eb35993f0a919bf8da147a59f8919cb21fcb89/lib/fmt/png.py
lib/fmt/png.py
#!/usr/bin/python # vim: encoding=utf-8 # pylint: disable=wrong-import-position,wrong-import-order,redefined-builtin """ This module is used to generate png-files for wttr.in queries. The only exported function is: * render_ansi(png_file, text, options=None) `render_ansi` is the main function of the module, which do...
python
Apache-2.0
f1eb35993f0a919bf8da147a59f8919cb21fcb89
2026-01-04T14:43:49.710263Z
false
hpcaitech/Open-Sora
https://github.com/hpcaitech/Open-Sora/blob/d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc/setup.py
setup.py
from typing import List from setuptools import find_packages, setup def fetch_requirements(paths) -> List[str]: """ This function reads the requirements file. Args: path (str): the path to the requirements file. Returns: The lines in the requirements file. """ if not isinsta...
python
Apache-2.0
d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc
2026-01-04T14:43:51.030080Z
false
hpcaitech/Open-Sora
https://github.com/hpcaitech/Open-Sora/blob/d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc/scripts/vae/train.py
scripts/vae/train.py
import gc import os import random import subprocess import warnings from contextlib import nullcontext from copy import deepcopy from pprint import pformat warnings.filterwarnings("ignore", category=FutureWarning) warnings.filterwarnings("ignore", category=UserWarning) gc.disable() import torch import torch.distribu...
python
Apache-2.0
d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc
2026-01-04T14:43:51.030080Z
false
hpcaitech/Open-Sora
https://github.com/hpcaitech/Open-Sora/blob/d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc/scripts/vae/inference.py
scripts/vae/inference.py
import os from pprint import pformat import colossalai import torch from colossalai.utils import get_current_device, set_seed from tqdm import tqdm from opensora.acceleration.parallel_states import get_data_parallel_group from opensora.datasets import save_sample from opensora.datasets.dataloader import prepare_datal...
python
Apache-2.0
d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc
2026-01-04T14:43:51.030080Z
false
hpcaitech/Open-Sora
https://github.com/hpcaitech/Open-Sora/blob/d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc/scripts/vae/stats.py
scripts/vae/stats.py
from pprint import pformat import colossalai import torch from colossalai.utils import get_current_device, set_seed from tqdm import tqdm from opensora.acceleration.parallel_states import get_data_parallel_group from opensora.datasets.dataloader import prepare_dataloader from opensora.registry import DATASETS, MODELS...
python
Apache-2.0
d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc
2026-01-04T14:43:51.030080Z
false
hpcaitech/Open-Sora
https://github.com/hpcaitech/Open-Sora/blob/d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc/scripts/cnv/meta.py
scripts/cnv/meta.py
import argparse import numpy as np import pandas as pd from pandarallel import pandarallel from torchvision.io.video import read_video from tqdm import tqdm def set_parallel(num_workers: int = None) -> callable: if num_workers == 0: return lambda x, *args, **kwargs: x.progress_apply(*args, **kwargs) ...
python
Apache-2.0
d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc
2026-01-04T14:43:51.030080Z
false
hpcaitech/Open-Sora
https://github.com/hpcaitech/Open-Sora/blob/d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc/scripts/cnv/shard.py
scripts/cnv/shard.py
import os import pandas as pd from tqdm import tqdm try: import dask.dataframe as dd SUPPORT_DASK = True except: SUPPORT_DASK = False def shard_parquet(input_path, k): # 检查输入路径是否存在 if not os.path.exists(input_path): raise FileNotFoundError(f"Input file {input_path} does not exist.") ...
python
Apache-2.0
d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc
2026-01-04T14:43:51.030080Z
false
hpcaitech/Open-Sora
https://github.com/hpcaitech/Open-Sora/blob/d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc/scripts/diffusion/train.py
scripts/diffusion/train.py
import gc import math import os import subprocess import warnings from contextlib import nullcontext from copy import deepcopy from pprint import pformat warnings.filterwarnings("ignore", category=FutureWarning) warnings.filterwarnings("ignore", category=UserWarning) gc.disable() import torch import torch.distribute...
python
Apache-2.0
d0cd5ac50da79e9a9d2285a952d4dcd806e6c8fc
2026-01-04T14:43:51.030080Z
false