move disassemblers and openpilot (#4592)

* move disassemblers and openpilot

* delete junk

* put that in pre-commit

* fixup readme
This commit is contained in:
George Hotz 2024-05-14 19:30:02 -07:00 committed by GitHub
parent 2b0ee74bb6
commit fd02ab1e8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 17 additions and 41 deletions

View File

@ -22,7 +22,7 @@ jobs:
- name: Symlink models and datasets - name: Symlink models and datasets
run: | run: |
mkdir -p weights mkdir -p weights
ln -s ~/tinygrad/disassemblers/applegpu disassemblers/applegpu ln -s ~/tinygrad/extra/disassemblers/applegpu extra/disassemblers/applegpu
ln -s ~/tinygrad/weights/sd-v1-4.ckpt weights/sd-v1-4.ckpt ln -s ~/tinygrad/weights/sd-v1-4.ckpt weights/sd-v1-4.ckpt
ln -s ~/tinygrad/weights/bpe_simple_vocab_16e6.txt.gz weights/bpe_simple_vocab_16e6.txt.gz ln -s ~/tinygrad/weights/bpe_simple_vocab_16e6.txt.gz weights/bpe_simple_vocab_16e6.txt.gz
ln -s ~/tinygrad/weights/LLaMA weights/LLaMA ln -s ~/tinygrad/weights/LLaMA weights/LLaMA

View File

@ -167,17 +167,17 @@ jobs:
- if: ${{ matrix.task == 'openpilot' }} - if: ${{ matrix.task == 'openpilot' }}
name: Test openpilot model compile and size name: Test openpilot model compile and size
run: | run: |
DEBUG=2 ALLOWED_KERNEL_COUNT=208 FLOAT16=1 DEBUGCL=1 GPU=1 IMAGE=2 python openpilot/compile2.py DEBUG=2 ALLOWED_KERNEL_COUNT=208 FLOAT16=1 DEBUGCL=1 GPU=1 IMAGE=2 python examples/openpilot/compile2.py
#python -c 'import os; assert os.path.getsize("/tmp/output.thneed") < 100_000_000' #python -c 'import os; assert os.path.getsize("/tmp/output.thneed") < 100_000_000'
- if: ${{ matrix.task == 'openpilot' }} - if: ${{ matrix.task == 'openpilot' }}
name: Test openpilot model correctness (float32) name: Test openpilot model correctness (float32)
run: FLOAT16=0 DEBUGCL=1 GPU=1 IMAGE=2 python openpilot/compile2.py run: FLOAT16=0 DEBUGCL=1 GPU=1 IMAGE=2 python examples/openpilot/compile2.py
- if: ${{ matrix.task == 'openpilot' }} - if: ${{ matrix.task == 'openpilot' }}
name: Test openpilot alt model correctness (float32) name: Test openpilot alt model correctness (float32)
run: FLOAT16=0 DEBUGCL=1 GPU=1 IMAGE=2 python openpilot/compile2.py https://github.com/commaai/openpilot/raw/3799fe46b3a629e491d4b8498b8ae83e4c88c304/selfdrive/modeld/models/supercombo.onnx run: FLOAT16=0 DEBUGCL=1 GPU=1 IMAGE=2 python examples/openpilot/compile2.py https://github.com/commaai/openpilot/raw/3799fe46b3a629e491d4b8498b8ae83e4c88c304/selfdrive/modeld/models/supercombo.onnx
- if: ${{ matrix.task == 'openpilot' }} - if: ${{ matrix.task == 'openpilot' }}
name: Test openpilot fastvits model correctness (float32) name: Test openpilot fastvits model correctness (float32)
run: FLOAT16=0 DEBUGCL=1 GPU=1 IMAGE=2 python openpilot/compile2.py https://github.com/commaai/openpilot/raw/9118973ed03c1ae1d40cf69a29507ec2cc78efd7/selfdrive/modeld/models/supercombo.onnx run: FLOAT16=0 DEBUGCL=1 GPU=1 IMAGE=2 python examples/openpilot/compile2.py https://github.com/commaai/openpilot/raw/9118973ed03c1ae1d40cf69a29507ec2cc78efd7/selfdrive/modeld/models/supercombo.onnx
- if: ${{ matrix.task == 'onnx' }} - if: ${{ matrix.task == 'onnx' }}
name: Test ONNX (GPU) name: Test ONNX (GPU)
run: GPU=1 python -m pytest -n=auto test/external/external_test_onnx_backend.py --durations=20 run: GPU=1 python -m pytest -n=auto test/external/external_test_onnx_backend.py --durations=20

3
.gitignore vendored
View File

@ -18,9 +18,8 @@ pandecode.dump
vertex.bin vertex.bin
recognize* recognize*
.idea .idea
disassemblers/applegpu
disassemblers/cuda_ioctl_sniffer
*.prof *.prof
extra/disassemblers/applegpu
extra/datasets/cifar-10-python.tar.gz extra/datasets/cifar-10-python.tar.gz
extra/datasets/librispeech/ extra/datasets/librispeech/
extra/datasets/imagenet/ extra/datasets/imagenet/

View File

@ -3,7 +3,7 @@ repos:
hooks: hooks:
- id: whitespace - id: whitespace
name: strip whitespace name: strip whitespace
entry: ./strip_whitespace.sh entry: find tinygrad -type f -name "*.py" -exec sed -i '' 's/ *$//' '{}' ';'
language: system language: system
always_run: true always_run: true
pass_filenames: false pass_filenames: false

View File

@ -1,4 +1,4 @@
Copyright (c) 2023 George Hotz Copyright (c) 2024, the tiny corp
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -1,9 +1,8 @@
<div align="center"> <div align="center">
<picture> <picture>
<source media="(prefers-color-scheme: dark)" srcset="/docs-legacy/logo_tiny_dark.svg">
<source media="(prefers-color-scheme: light)" srcset="/docs-legacy/logo_tiny_light.svg"> <source media="(prefers-color-scheme: light)" srcset="/docs-legacy/logo_tiny_light.svg">
<img alt="tiny corp logo" src="/docs-legacy/logo_tiny_light.svg" width="50%" height="50%"> <img alt="tiny corp logo" src="/docs-legacy/logo_tiny_dark.svg" width="50%" height="50%">
</picture> </picture>
tinygrad: For something between [PyTorch](https://github.com/pytorch/pytorch) and [karpathy/micrograd](https://github.com/karpathy/micrograd). Maintained by [tiny corp](https://tinygrad.org). tinygrad: For something between [PyTorch](https://github.com/pytorch/pytorch) and [karpathy/micrograd](https://github.com/karpathy/micrograd). Maintained by [tiny corp](https://tinygrad.org).

2
examples/openpilot/go.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
NOLOCALS=1 FLOAT16=1 DEBUGCL=1 IMAGE=2 GPU=1 python3 examples/openpilot/compile2.py

View File

@ -17,7 +17,7 @@ python3 examples/beautiful_mnist.py
python3 examples/beautiful_cartpole.py python3 examples/beautiful_cartpole.py
python3 examples/mlperf/model_spec.py python3 examples/mlperf/model_spec.py
python3 examples/yolov8.py ./test/models/efficientnet/Chicken.jpg python3 examples/yolov8.py ./test/models/efficientnet/Chicken.jpg
openpilot/go.sh examples/openpilot/go.sh
BIG=1 MPS=1 pytest test/ --ignore=test/test_fusion_op.py --ignore=test/test_linearizer_failures.py BIG=1 MPS=1 pytest test/ --ignore=test/test_fusion_op.py --ignore=test/test_linearizer_failures.py
# sort and uniq # sort and uniq

View File

@ -72,7 +72,7 @@ def parse_cmd_buf(dat):
num_unit = vals[0]>>22 num_unit = vals[0]>>22
print(f"{num_unit=} {state_block=} {state_src=} {state_type=} {dst_off=}") print(f"{num_unit=} {state_block=} {state_src=} {state_type=} {dst_off=}")
from disassemblers.adreno import disasm_raw from extra.disassemblers.adreno import disasm_raw
if state_type == ST6_SHADER: disasm_raw(get_mem(((vals[2] << 32) | vals[1]), 0x180)) if state_type == ST6_SHADER: disasm_raw(get_mem(((vals[2] << 32) | vals[1]), 0x180))
if state_type == ST6_CONSTANTS: hexdump(get_mem(((vals[2] << 32) | vals[1]), min(0x180, num_unit*4))) if state_type == ST6_CONSTANTS: hexdump(get_mem(((vals[2] << 32) | vals[1]), min(0x180, num_unit*4)))
pass pass

View File

@ -1,2 +0,0 @@
#!/bin/bash
NOLOCALS=1 FLOAT16=1 DEBUGCL=1 IMAGE=2 GPU=1 python3 openpilot/compile2.py

View File

@ -1,5 +0,0 @@
#!/bin/bash -e
rm -rf dist
ipython3 setup.py sdist bdist_wheel
twine upload dist/*

View File

@ -26,12 +26,10 @@ lint.select = [
line-length = 150 line-length = 150
exclude = [ exclude = [
"disassemblers/",
"docs/", "docs/",
"docs-legacy/", "docs-legacy/",
"examples/", "examples/",
"extra/", "extra/",
"openpilot/",
"tinygrad/runtime/autogen", "tinygrad/runtime/autogen",
"test/external/mlperf_resnet", "test/external/mlperf_resnet",
"test/external/mlperf_unet3d", "test/external/mlperf_unet3d",

View File

@ -1,13 +0,0 @@
#!/bin/bash -e
echo "********* CPU *********"
CPU=1 python3 "$@"
echo "********* GPU *********"
GPU=1 python3 "$@"
echo "********* METAL *********"
METAL=1 python3 "$@"
echo "********* CLANG *********"
CLANG=1 python3 "$@"
echo "********* LLVM *********"
LLVM=1 python3 "$@"
echo "********* TORCH *********"
TORCH=1 python3 "$@"

View File

@ -1,2 +0,0 @@
#!/bin/bash
find tinygrad -type f -name "*.py" -exec sed -i '' 's/ *$//' '{}' ';'

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# cd disassemblers/ && git clone --recursive github.com:geohot/cuda_ioctl_sniffer.git # cd extra/disassemblers/ && git clone --recursive github.com:geohot/cuda_ioctl_sniffer.git
# LD_PRELOAD=$PWD/disassemblers/cuda_ioctl_sniffer/out/sniff.so GPU=1 python3 test/external/external_multi_gpu.py # LD_PRELOAD=$PWD/extra/disassemblers/cuda_ioctl_sniffer/out/sniff.so GPU=1 python3 test/external/external_multi_gpu.py
import numpy as np import numpy as np
from tinygrad.tensor import Tensor from tinygrad.tensor import Tensor
from tinygrad.helpers import colored, Timing, getenv from tinygrad.helpers import colored, Timing, getenv

View File

@ -790,7 +790,7 @@ class TestSchedule(unittest.TestCase):
a = Tensor.rand(3, 4, 5).realize() a = Tensor.rand(3, 4, 5).realize()
out = a.log2().pad(((0, 1), (0, 1), (0, 1)), 1.0).sum().contiguous() out = a.log2().pad(((0, 1), (0, 1), (0, 1)), 1.0).sum().contiguous()
run_schedule(check_schedule(out, 2)) run_schedule(check_schedule(out, 2))
np.testing.assert_allclose(out.numpy(), np.pad(np.log2(a.numpy()), ((0, 1), (0, 1), (0, 1)), constant_values=1.0).sum()) np.testing.assert_allclose(out.numpy(), np.pad(np.log2(a.numpy()), ((0, 1), (0, 1), (0, 1)), constant_values=1.0).sum(), rtol=1e-6)
def test_shrink_pad_safe(self): def test_shrink_pad_safe(self):
a = Tensor.ones((3, )).contiguous().realize() a = Tensor.ones((3, )).contiguous().realize()

View File

@ -33,7 +33,7 @@ class MetalProgram:
with tempfile.NamedTemporaryFile(delete=True) as shader: with tempfile.NamedTemporaryFile(delete=True) as shader:
shader.write(lib) shader.write(lib)
shader.flush() shader.flush()
os.system(f"cd {pathlib.Path(__file__).parents[2]}/disassemblers/applegpu && python3 compiler_explorer.py {shader.name}") os.system(f"cd {pathlib.Path(__file__).parents[2]}/extra/disassemblers/applegpu && python3 compiler_explorer.py {shader.name}")
assert lib[:4] == b"MTLB", "Invalid Metal library. Could be due to using conda. Try system python or METAL_XCODE=1 DISABLE_COMPILER_CACHE=1." assert lib[:4] == b"MTLB", "Invalid Metal library. Could be due to using conda. Try system python or METAL_XCODE=1 DISABLE_COMPILER_CACHE=1."
data = libdispatch.dispatch_data_create(lib, len(lib), None, None) data = libdispatch.dispatch_data_create(lib, len(lib), None, None)
self.library = unwrap2(self.device.device.newLibraryWithData_error_(data, None)) self.library = unwrap2(self.device.device.newLibraryWithData_error_(data, None))