test.yml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. name: Unit Tests
  2. env:
  3. # increment this when downloads substantially change to avoid the internet
  4. DOWNLOAD_CACHE_VERSION: '5'
  5. RUN_PROCESS_REPLAY: 1
  6. on:
  7. push:
  8. branches:
  9. - master
  10. pull_request:
  11. workflow_dispatch:
  12. jobs:
  13. uops:
  14. name: uops tests
  15. runs-on: ubuntu-latest
  16. timeout-minutes: 10
  17. steps:
  18. - name: Checkout Code
  19. uses: actions/checkout@v4
  20. - name: Set up Python 3.12
  21. uses: actions/setup-python@v5
  22. with:
  23. python-version: 3.12
  24. - name: Cache python packages
  25. uses: actions/cache@v4
  26. with:
  27. path: ${{ env.Python3_ROOT_DIR }}/lib/python3.12/site-packages
  28. key: uops-packages-${{ hashFiles('**/setup.py') }}-3.12
  29. - name: Install dependencies
  30. run: pip install -e '.[testing]' --extra-index-url https://download.pytorch.org/whl/cpu
  31. - name: Test IMAGE=2 support
  32. run: |
  33. IMAGE=2 PYTHON=1 python3 test/test_ops.py TestOps.test_gemm
  34. IMAGE=2 PYTHON=1 python3 test/test_ops.py TestOps.test_simple_conv2d
  35. - name: Test emulated METAL tensor cores
  36. run: DEBUG=2 EMULATE_METAL=1 FORWARD_ONLY=1 PYTHON=1 python3 test/test_ops.py TestOps.test_big_gemm
  37. - name: Test emulated AMD tensor cores
  38. run: |
  39. PYTHONPATH=. DEBUG=2 EMULATE_AMD=1 FORWARD_ONLY=1 PYTHON=1 N=16 HALF=1 ACC_HALF=0 python3 ./extra/gemm/simple_matmul.py
  40. PYTHONPATH=. DEBUG=2 EMULATE_AMD=1 FORWARD_ONLY=1 PYTHON=1 N=64 HALF=1 ACC_HALF=0 python3 ./extra/gemm/simple_matmul.py
  41. PYTHONPATH=. DEBUG=2 EMULATE_AMD=1 FORWARD_ONLY=1 PYTHON=1 N=16 HALF=1 ACC_HALF=1 python3 ./extra/gemm/simple_matmul.py
  42. PYTHONPATH=. DEBUG=2 EMULATE_AMD=1 FORWARD_ONLY=1 PYTHON=1 N=64 HALF=1 ACC_HALF=1 python3 ./extra/gemm/simple_matmul.py
  43. - name: Test emulated CUDA tensor cores
  44. run: DEBUG=2 EMULATE_CUDA=1 FORWARD_ONLY=1 PYTHON=1 python3 test/test_ops.py TestOps.test_gemm
  45. - name: Full test tensor cores
  46. run: |
  47. PYTHONPATH=. DEBUG=2 EMULATE_METAL=1 FORWARD_ONLY=1 PYTHON=1 python3 ./test/test_linearizer.py TestLinearizer.test_tensor_cores
  48. PYTHONPATH=. DEBUG=2 EMULATE_AMD=1 FORWARD_ONLY=1 PYTHON=1 python3 ./test/test_linearizer.py TestLinearizer.test_tensor_cores
  49. PYTHONPATH=. DEBUG=2 EMULATE_CUDA=1 FORWARD_ONLY=1 PYTHON=1 python3 ./test/test_linearizer.py TestLinearizer.test_tensor_cores
  50. - name: Test dtype with Python emulator
  51. run: DEBUG=1 PYTHONPATH=. PYTHON=1 python3 -m pytest -n=auto test/test_dtype.py test/test_dtype_alu.py
  52. - name: Test ops with Python emulator
  53. run: DEBUG=2 PYTHON=1 python3 -m pytest -n=auto test/test_ops.py -k "not (test_split or test_simple_cumsum or test_cumsum or test_einsum or test_dot or test_dot_1d or test_big_gemm or test_broadcastdot or test_multidot or test_var_axis or test_std_axis or test_broadcast_full or test_broadcast_partial or test_simple_conv3d or test_dilated_conv_transpose2d or test_simple_conv_transpose3d or test_large_input_conv2d or test_maxpool2d or test_maxpool2d_simple or test_maxpool2d_bigger_stride or test_avgpool2d or test_cat or test_scaled_product_attention or test_scaled_product_attention_causal or test_slice_fancy_indexing_dim_inject_none or test_slice_fancy_indexing_list_indices or test_slice_fancy_indexing_no_dim_collapse or test_slice_fancy_indexing_tuple_indices or test_slice_fancy_indexing_list_with_tensors or test_slice_fancy_indexing_dim_collapse_int)" --durations=20
  54. - name: Test uops with Python emulator
  55. run: PYTHON=1 python3 -m pytest test/test_uops.py --durations=20
  56. - name: Test symbolic with Python emulator
  57. run: PYTHONPATH=. PYTHON=1 python3 test/test_symbolic_ops.py
  58. - name: test_linearizer_failures with Python emulator
  59. run: PYTHONPATH=. PYTHON=1 python3 -m pytest -rA test/test_linearizer_failures.py::TestLinearizerFailures::test_failure_1
  60. linter:
  61. name: Linters
  62. runs-on: ubuntu-latest
  63. timeout-minutes: 10
  64. # TODO: run the pre-commit hook to replace a lot of this
  65. steps:
  66. - name: Checkout Code
  67. uses: actions/checkout@v4
  68. - name: Set up Python 3.8
  69. uses: actions/setup-python@v5
  70. with:
  71. python-version: 3.8
  72. - name: Cache python packages
  73. uses: actions/cache@v4
  74. with:
  75. path: ${{ env.Python3_ROOT_DIR }}/lib/python3.8/site-packages
  76. key: linting-packages-${{ hashFiles('**/setup.py') }}-3.8
  77. - name: Install dependencies
  78. run: pip install -e '.[linting,testing,docs]' --extra-index-url https://download.pytorch.org/whl/cpu
  79. - name: Lint with pylint
  80. run: python -m pylint --disable=all -e W0311 -e C0303 --jobs=0 --indent-string=' ' **/*.py
  81. - name: Lint with ruff
  82. run: |
  83. pip3 install --upgrade --force-reinstall ruff
  84. python3 -m ruff check .
  85. - name: Lint tinygrad with pylint
  86. run: python -m pylint tinygrad/
  87. - name: Run mypy
  88. run: python -m mypy --strict-equality
  89. - name: Test Docs
  90. run: |
  91. python docs/abstractions2.py
  92. python docs/abstractions3.py
  93. - name: Test Docs Build
  94. run: mkdocs build --strict
  95. - name: Test Quickstart
  96. run: awk '/```python/{flag=1;next}/```/{flag=0}flag' docs/quickstart.md > quickstart.py && PYTHONPATH=. python quickstart.py
  97. - name: Test README
  98. run: awk '/```python/{flag=1;next}/```/{flag=0}flag' README.md > README.py && PYTHONPATH=. python README.py
  99. - name: Fuzz Test symbolic
  100. run: python test/external/fuzz_symbolic.py
  101. - name: Fuzz Test shapetracker
  102. run: |
  103. PYTHONPATH="." python test/external/fuzz_shapetracker.py
  104. PYTHONPATH="." python test/external/fuzz_shapetracker_math.py
  105. - name: Test to_movement_ops
  106. run: PYTHONPATH="." python extra/to_movement_ops.py
  107. - name: Use as an external package
  108. run: |
  109. mkdir $HOME/test_external_dir
  110. cd $HOME/test_external_dir
  111. python -m venv venv
  112. source venv/bin/activate
  113. pip install $GITHUB_WORKSPACE
  114. python -c "from tinygrad.tensor import Tensor; print(Tensor([1,2,3,4,5]))"
  115. - name: Test DEBUG
  116. run: DEBUG=100 python3 -c "from tinygrad import Tensor; N = 1024; a, b = Tensor.rand(N, N), Tensor.rand(N, N); c = (a.reshape(N, 1, N) * b.T.reshape(1, N, N)).sum(axis=2); print((c.numpy() - (a.numpy() @ b.numpy())).mean())"
  117. - name: Repo line count <8500 lines
  118. run: MAX_LINE_COUNT=8500 python sz.py
  119. testopencl:
  120. strategy:
  121. fail-fast: false
  122. matrix:
  123. task: [optimage, onnx]
  124. name: ${{ matrix.task=='optimage'&&'GPU IMAGE+compile Tests' || matrix.task=='onnx'&&'ONNX+Optimization Tests' }}
  125. runs-on: ubuntu-20.04
  126. timeout-minutes: 10
  127. steps:
  128. - name: Checkout Code
  129. uses: actions/checkout@v4
  130. - name: Install OpenCL
  131. run: |
  132. echo 'Acquire::http::Pipeline-Depth "5";' | sudo tee -a /etc/apt/apt.conf.d/99parallel
  133. echo "deb [ allow-insecure=yes ] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
  134. sudo apt update || true
  135. sudo apt install --allow-unauthenticated -y --no-install-recommends \
  136. intel-oneapi-runtime-openmp=2023.2.1-16 intel-oneapi-runtime-compilers-common=2023.2.1-16 intel-oneapi-runtime-compilers=2023.2.1-16 \
  137. intel-oneapi-runtime-dpcpp-sycl-opencl-cpu=2023.2.1-16 intel-oneapi-runtime-tbb-common=2021.10.0-49541 \
  138. intel-oneapi-runtime-tbb=2021.10.0-49541 intel-oneapi-runtime-opencl=2023.2.1-16
  139. - name: Set up Python 3.11
  140. uses: actions/setup-python@v5
  141. with:
  142. python-version: 3.11
  143. - name: Cache python packages
  144. uses: actions/cache@v4
  145. with:
  146. path: ${{ env.Python3_ROOT_DIR }}/lib/python3.11/site-packages
  147. key: testing-packages-${{ hashFiles('**/setup.py') }}
  148. - name: Cache downloads
  149. uses: actions/cache@v4
  150. with:
  151. path: ~/.cache/tinygrad/downloads/
  152. key: downloads-cache-${{ matrix.task }}-${{ env.DOWNLOAD_CACHE_VERSION }}
  153. - name: Install Dependencies
  154. run: pip install -e '.[testing,testing_tf]' --extra-index-url https://download.pytorch.org/whl/cpu
  155. - if: ${{ matrix.task == 'optimage' }}
  156. name: Run Kernel Count Test
  157. run: PYTHONPATH="." GPU=1 python -m pytest -n=auto test/external/external_test_opt.py
  158. - if: ${{ matrix.task == 'optimage'}}
  159. name: Test WINO=1
  160. run: GPU=1 DEBUG=2 WINO=1 python3 test/test_ops.py TestOps.test_simple_conv2d
  161. - if: ${{ matrix.task == 'optimage'}}
  162. name: Test GPU IMAGE=2 ops + training
  163. run: |
  164. GPU=1 IMAGE=2 python -m pytest -n=auto test/test_ops.py
  165. GPU=1 IMAGE=2 python3 test/models/test_end2end.py TestEnd2End.test_linear_mnist
  166. - if: ${{ matrix.task == 'optimage' }}
  167. name: Test openpilot model compile and size
  168. run: |
  169. PYTHONPATH="." DEBUG=2 ALLOWED_KERNEL_COUNT=208 FLOAT16=1 DEBUGCL=1 GPU=1 IMAGE=2 python examples/openpilot/compile2.py
  170. python -c 'import os; assert os.path.getsize("/tmp/output.thneed") < 100_000_000'
  171. - if: ${{ matrix.task == 'optimage' }}
  172. name: Test openpilot model correctness (float32)
  173. run: PYTHONPATH="." FLOAT16=0 DEBUGCL=1 GPU=1 IMAGE=2 python examples/openpilot/compile2.py
  174. - if: ${{ matrix.task == 'optimage' }}
  175. name: Test openpilot alt model correctness (float32)
  176. run: PYTHONPATH="." 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
  177. - if: ${{ matrix.task == 'optimage' }}
  178. name: Test openpilot fastvits model correctness (float32)
  179. run: PYTHONPATH="." 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
  180. - if: ${{ matrix.task == 'optimage' }}
  181. name: Compile EfficientNet to C and test it
  182. run: |
  183. CLANG=1 PYTHONPATH="." python examples/compile_efficientnet.py > recognize.c
  184. clang -O2 recognize.c -lm -o recognize
  185. cat test/models/efficientnet/Chicken.jpg | ./recognize | grep cock
  186. - if: ${{ matrix.task == 'onnx' }}
  187. name: Test ONNX (GPU)
  188. run: GPU=1 python -m pytest -n=auto test/external/external_test_onnx_backend.py --durations=20
  189. - if: ${{ matrix.task == 'onnx' }}
  190. name: Test ONNX (CLANG)
  191. run: CLANG=1 python -m pytest -n=auto test/external/external_test_onnx_backend.py --durations=20
  192. - if: ${{ matrix.task == 'onnx' }}
  193. name: Test Action Space
  194. run: PYTHONPATH="." GPU=1 python3 extra/optimization/get_action_space.py
  195. - if: ${{ matrix.task == 'onnx' }}
  196. name: Test Beam Search
  197. run: PYTHONPATH="." GPU=1 IGNORE_BEAM_CACHE=1 python3 -m pytest extra/optimization/test_beam_search.py
  198. - if: ${{ matrix.task == 'onnx' }}
  199. name: Test MLPerf optimizers
  200. run: GPU=1 python -m pytest -n=auto test/external/external_test_optim.py --durations=20
  201. - if: ${{ matrix.task == 'onnx' }}
  202. name: Test MLPerf losses
  203. run: GPU=1 python -m pytest -n=auto test/external/external_test_losses.py --durations=20
  204. - if: ${{ matrix.task == 'onnx' }}
  205. name: Test MLPerf metrics
  206. run: GPU=1 python -m pytest -n=auto test/external/external_test_metrics.py --durations=20
  207. - if: ${{ matrix.task == 'onnx' }}
  208. name: Test MLPerf datasets
  209. run: GPU=1 python -m pytest -n=auto test/external/external_test_datasets.py --durations=20
  210. - if: ${{ matrix.task == 'onnx' }}
  211. name: Test THREEFRY
  212. run: PYTHONPATH=. THREEFRY=1 GPU=1 python3 -m pytest test/test_randomness.py test/test_jit.py --durations=20
  213. - if: ${{ matrix.task == 'onnx' }}
  214. name: Run handcode_opt
  215. run: PYTHONPATH=. MODEL=resnet GPU=1 DEBUG=1 BS=4 HALF=0 python3 examples/handcode_opt.py
  216. #testwebgpu:
  217. # name: WebGPU Tests
  218. # runs-on: macos-13
  219. # timeout-minutes: 10
  220. # steps:
  221. # - name: Checkout Code
  222. # uses: actions/checkout@v4
  223. # - name: Set up Python 3.11
  224. # uses: actions/setup-python@v5
  225. # with:
  226. # python-version: 3.11
  227. # - name: Cache python packages
  228. # uses: actions/cache@v4
  229. # with:
  230. # path: /Users/runner/Library/Python/3.11/lib/python/site-packages
  231. # key: webgpu-testing-user3-packages-${{ hashFiles('**/setup.py') }}
  232. # - name: Install Dependencies
  233. # run: pip install --user -e '.[webgpu,testing]' --extra-index-url https://download.pytorch.org/whl/cpu
  234. # - name: Cache downloads
  235. # uses: actions/cache@v4
  236. # with:
  237. # path: ~/Library/Caches/tinygrad/downloads/
  238. # key: downloads-cache-webgpu-${{ env.DOWNLOAD_CACHE_VERSION }}
  239. # - name: Check Device.DEFAULT (WEBGPU) and print some source
  240. # run: |
  241. # WEBGPU=1 python -c "from tinygrad import Device; assert Device.DEFAULT == 'WEBGPU', Device.DEFAULT"
  242. # WEBGPU=1 DEBUG=4 FORWARD_ONLY=1 python3 test/test_ops.py TestOps.test_add
  243. #- name: Run webgpu pytest
  244. # run: WEBGPU=1 WGPU_BACKEND_TYPE=Metal python -m pytest -n=auto
  245. # - name: Run selected webgpu tests
  246. # run: |
  247. # WEBGPU=1 WGPU_BACKEND_TYPE=Metal python -m pytest -n=auto test/test_ops.py test/test_dtype.py \
  248. # test/test_jit.py test/test_symbolic_ops.py test/test_symbolic_jit.py test/test_linearizer.py \
  249. # test/test_linearizer_failures.py test/test_nn.py
  250. # - name: Build WEBGPU Efficientnet
  251. # run: WEBGPU=1 WGPU_BACKEND_TYPE=Metal python -m examples.compile_efficientnet
  252. # - name: Install Puppeteer
  253. # run: npm install puppeteer
  254. # - name: Run WEBGPU Efficientnet
  255. # run: node test/web/test_webgpu.js
  256. testmetal:
  257. name: Metal Tests
  258. runs-on: macos-14
  259. timeout-minutes: 20
  260. steps:
  261. - name: Checkout Code
  262. uses: actions/checkout@v4
  263. with:
  264. fetch-depth: 2 # NOTE: this fetches the HEAD commit of the PR
  265. - name: Set up Python 3.11
  266. uses: actions/setup-python@v5
  267. with:
  268. python-version: 3.11
  269. - name: Cache python packages
  270. uses: actions/cache@v4
  271. with:
  272. path: /Users/runner/Library/Python/3.11/lib/python/site-packages
  273. key: metal-m1-testing-user3-packages-${{ hashFiles('**/setup.py') }}
  274. - name: Install Dependencies
  275. run: pip install --user -e '.[testing]' --extra-index-url https://download.pytorch.org/whl/cpu
  276. - name: Cache downloads
  277. uses: actions/cache@v4
  278. with:
  279. path: ~/Library/Caches/tinygrad/downloads/
  280. key: downloads-cache-metal-only-${{ env.DOWNLOAD_CACHE_VERSION }}
  281. - name: Check Device.DEFAULT (METAL) and print some source
  282. run: |
  283. METAL=1 python -c "from tinygrad import Device; assert Device.DEFAULT == 'METAL', Device.DEFAULT"
  284. METAL=1 DEBUG=4 FORWARD_ONLY=1 python3 test/test_ops.py TestOps.test_add
  285. - name: Run metal test
  286. run: JIT=2 METAL=1 python -m pytest -n=auto test/ --ignore=test/external --ignore=test/models --durations=20
  287. - name: Run real world test
  288. run: JIT=2 METAL=1 python -m pytest -n=auto test/models/test_real_world.py --durations=20
  289. - name: Run ONNX
  290. run: JIT=2 METAL=1 python -m pytest -n=auto test/external/external_test_onnx_backend.py --durations=20
  291. - name: Test tensor core ops (fake)
  292. run: TC=2 METAL=1 DEBUG=3 python test/test_ops.py TestOps.test_gemm
  293. - name: Test tensor core ops (real)
  294. run: METAL=1 DEBUG=3 python test/test_ops.py TestOps.test_big_gemm
  295. - name: Test LLaMA compile speed
  296. run: PYTHONPATH="." METAL=1 python test/external/external_test_speed_llama.py
  297. - name: Test Beam Search
  298. run: PYTHONPATH="." METAL=1 IGNORE_BEAM_CACHE=1 python3 -m pytest extra/optimization/test_beam_search.py
  299. - name: Fuzz Test linearizer
  300. run: PYTHONPATH="." METAL=1 CACHELEVEL=0 FUZZ_ALL_ACTIONS=1 DEPTH=2 FUZZ_N=48 FUZZ_MAX_SIZE=10000000 python test/external/fuzz_linearizer.py
  301. - name: Fuzz Test models schedule
  302. run: FUZZ_SCHEDULE=1 FUZZ_SCHEDULE_MAX_PATHS=5 python -m pytest test/models/test_train.py test/models/test_end2end.py
  303. - name: Run TRANSCENDENTAL math
  304. run: TRANSCENDENTAL=2 python -m pytest -n=auto test/test_ops.py::TestOps::test_sin test/test_ops.py::TestOps::test_cos test/test_ops.py::TestOps::test_tan test/test_ops.py::TestOps::test_exp test/test_ops.py::TestOps::test_log --durations=20
  305. - name: Run process replay tests
  306. run: |
  307. export PR_TITLE=$(jq -r .pull_request.title "$GITHUB_EVENT_PATH")
  308. export COMMIT_MESSAGE=$(git show -s --format=%B ${{ github.event.pull_request.head.sha }})
  309. cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
  310. # testwebgl:
  311. # name: WebGL Tests
  312. # runs-on: ubuntu-latest
  313. # timeout-minutes: 10
  314. #
  315. # steps:
  316. # - name: Checkout Code
  317. # uses: actions/checkout@v3
  318. # - name: Set up Python 3.11
  319. # uses: actions/setup-python@v4
  320. # with:
  321. # python-version: 3.11
  322. # - name: Cache python packages
  323. # uses: actions/cache@v4
  324. # with:
  325. # path: ${{ env.Python3_ROOT_DIR }}/lib/python3.11/site-packages
  326. # key: webgl-testing-packages-${{ hashFiles('**/setup.py') }}
  327. # - name: Install Dependencies
  328. # run: pip install -e '.[webgl,testing]' --extra-index-url https://download.pytorch.org/whl/cpu
  329. # - name: Cache downloads
  330. # uses: actions/cache@v4
  331. # with:
  332. # path: ~/Library/Caches/tinygrad/downloads/
  333. # key: downloads-cache-webgl-${{ env.DOWNLOAD_CACHE_VERSION }}
  334. # - name: Prepare
  335. # run: |
  336. # sudo apt-get -y install xvfb
  337. # sudo /usr/bin/Xvfb :0 -screen 0 4096x4096x24+32 &
  338. # - name: Run selected webgl tests
  339. # run: WEBGL=1 python -m pytest -n=auto test/test_ops.py test/test_dtype.py test/test_jit.py
  340. # - name: Build WebGL Efficientnet
  341. # run: WEBGL=1 python -m examples.compile_efficientnet
  342. tests:
  343. strategy:
  344. fail-fast: false
  345. matrix:
  346. backend: [llvm, clang, gpu, ptx, amd, nv] #, triton]
  347. name: Tests on (${{ matrix.backend }})
  348. runs-on: ubuntu-latest
  349. timeout-minutes: 20
  350. steps:
  351. - name: Checkout Code
  352. uses: actions/checkout@v4
  353. with:
  354. fetch-depth: 2 # NOTE: this fetches the HEAD commit of the PR
  355. - name: Set up Python 3.11
  356. uses: actions/setup-python@v5
  357. with:
  358. python-version: 3.11
  359. - name: Cache python packages
  360. uses: actions/cache@v4
  361. with:
  362. path: ${{ env.Python3_ROOT_DIR }}/lib/python3.11/site-packages
  363. key: ${{ matrix.backend }}-packages-${{ hashFiles('**/setup.py') }}
  364. - name: Cache downloads
  365. uses: actions/cache@v4
  366. with:
  367. path: ~/.cache/tinygrad/downloads/
  368. key: downloads-cache-${{ matrix.backend }}-${{ env.DOWNLOAD_CACHE_VERSION }}
  369. - name: Set env
  370. run: printf "${{ matrix.backend == 'llvm' && 'LLVM=1' || matrix.backend == 'clang' && 'CLANG=1' || matrix.backend == 'gpu' && 'GPU=1' || matrix.backend == 'PTX' && 'FORWARD_ONLY=1\nJIT=1\nOPT=2\nNV=1\nPTX=1\nMOCKGPU=1' || matrix.backend == 'triton' && 'FORWARD_ONLY=1\nJIT=1\nOPT=2\nNV=1\nMOCKGPU=1\nTRITON=1\nTRITON_PTXAS_PATH=/usr/bin/ptxas' || matrix.backend == 'amd' && 'AMD=1\nMOCKGPU=1\nFORWARD_ONLY=1' || matrix.backend == 'nv' && 'NV=1\nMOCKGPU=1\nFORWARD_ONLY=1' }}" >> $GITHUB_ENV
  371. - name: Install OpenCL
  372. if: matrix.backend == 'gpu'
  373. run: |
  374. echo 'Acquire::http::Pipeline-Depth "5";' | sudo tee -a /etc/apt/apt.conf.d/99parallel
  375. echo "deb [ allow-insecure=yes ] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
  376. sudo apt update || true
  377. sudo apt install --allow-unauthenticated -y --no-install-recommends opencl-headers \
  378. intel-oneapi-runtime-openmp=2023.2.1-16 intel-oneapi-runtime-compilers-common=2023.2.1-16 intel-oneapi-runtime-compilers=2023.2.1-16 \
  379. intel-oneapi-runtime-dpcpp-sycl-opencl-cpu=2023.2.1-16 intel-oneapi-runtime-tbb-common=2021.10.0-49541 \
  380. intel-oneapi-runtime-tbb=2021.10.0-49541 intel-oneapi-runtime-opencl=2023.2.1-16
  381. - name: Install packages (cuda)
  382. if: matrix.backend == 'ptx' || matrix.backend == 'triton' || matrix.backend == 'nv'
  383. run: |
  384. echo 'Acquire::http::Pipeline-Depth "5";' | sudo tee -a /etc/apt/apt.conf.d/99parallel
  385. sudo apt update -y || true
  386. sudo apt install -y --no-install-recommends git g++ cmake ninja-build llvm-15-dev zlib1g-dev libglew-dev \
  387. flex bison libfl-dev libboost-thread-dev libboost-filesystem-dev nvidia-cuda-toolkit-gcc libzstd-dev
  388. - name: Cache gpuocelot
  389. if: matrix.backend == 'ptx' || matrix.backend == 'triton' || matrix.backend == 'nv'
  390. id: cache-build
  391. uses: actions/cache@v4
  392. env:
  393. cache-name: cache-gpuocelot-build
  394. with:
  395. path: ${{ github.workspace }}/gpuocelot/ocelot
  396. key: ubuntu22.04-gpuocelot-4524e34adb7eaccc6f71262f2e21d7052bb17c2f-rebuild-7
  397. - name: Clone/compile gpuocelot
  398. if: (matrix.backend == 'ptx' || matrix.backend == 'triton' || matrix.backend == 'nv') && steps.cache-build.outputs.cache-hit != 'true'
  399. run: |
  400. git clone --recurse-submodules https://github.com/gpuocelot/gpuocelot.git ${{ github.workspace }}/gpuocelot
  401. cd ${{ github.workspace }}/gpuocelot/ocelot
  402. git checkout 4524e34adb7eaccc6f71262f2e21d7052bb17c2f
  403. mkdir build
  404. cd build
  405. cmake .. -Wno-dev -G Ninja -DOCELOT_BUILD_TOOLS=OFF -DCMAKE_BUILD_ALWAYS=0 -DBUILD_TESTS_CUDA=OFF
  406. ninja
  407. - name: Install gpuocelot
  408. if: matrix.backend == 'ptx' || matrix.backend == 'triton' || matrix.backend == 'nv'
  409. run: |
  410. cd ${{ github.workspace }}/gpuocelot/ocelot/build
  411. sudo ninja install -d explain
  412. - name: Install packages (amd)
  413. if: matrix.backend == 'amd'
  414. run: |
  415. echo 'Acquire::http::Pipeline-Depth "5";' | sudo tee -a /etc/apt/apt.conf.d/99parallel
  416. wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null
  417. sudo tee /etc/apt/sources.list.d/rocm.list <<'EOF'
  418. deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/6.1.2 jammy main
  419. EOF
  420. echo -e 'Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600' | sudo tee /etc/apt/preferences.d/rocm-pin-600
  421. sudo apt update || true
  422. sudo apt install --no-install-recommends --allow-unauthenticated -y hsa-rocr comgr hsa-rocr-dev liburing-dev libc6-dev
  423. curl -s https://api.github.com/repos/Qazalin/remu/releases/latest | \
  424. jq -r '.assets[] | select(.name == "libremu.so").browser_download_url' | \
  425. sudo xargs curl -L -o /usr/local/lib/libremu.so
  426. sudo tee --append /etc/ld.so.conf.d/rocm.conf <<'EOF'
  427. /opt/rocm/lib
  428. /opt/rocm/lib64
  429. EOF
  430. sudo ldconfig
  431. - name: Install dependencies
  432. run: pip install -e '.[testing${{matrix.backend=='llvm'&&',llvm'||matrix.backend=='ptx'&&',cuda'||matrix.backend=='triton'&&',triton'||''}}]' --extra-index-url https://download.pytorch.org/whl/cpu --extra-index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/Triton-Nightly/pypi/simple/
  433. - name: Check Device.DEFAULT and print some source
  434. run: |
  435. PYTHONPATH=${{ github.workspace }} python3 -c "from tinygrad import Device; assert Device.DEFAULT in ['LLVM','CLANG','CUDA','GPU','AMD','NV'], Device.DEFAULT"
  436. DEBUG=5 PYTHONPATH=${{ github.workspace }} FORWARD_ONLY=1 python3 test/test_ops.py TestOps.test_add
  437. - name: Verify OpenCL autogen
  438. if: matrix.backend == 'gpu'
  439. run: |
  440. cp tinygrad/runtime/autogen/opencl.py /tmp/opencl.py.bak
  441. ./autogen_stubs.sh opencl
  442. diff /tmp/opencl.py.bak tinygrad/runtime/autogen/opencl.py
  443. - name: Verify CUDA autogen
  444. if: matrix.backend == 'nv'
  445. run: |
  446. cp tinygrad/runtime/autogen/cuda.py /tmp/cuda.py.bak
  447. cp tinygrad/runtime/autogen/nv_gpu.py /tmp/nv_gpu.py.bak
  448. ./autogen_stubs.sh cuda
  449. ./autogen_stubs.sh nv
  450. diff /tmp/cuda.py.bak tinygrad/runtime/autogen/cuda.py
  451. diff /tmp/nv_gpu.py.bak tinygrad/runtime/autogen/nv_gpu.py
  452. - name: Verify AMD autogen
  453. if: matrix.backend == 'amd'
  454. run: |
  455. cp tinygrad/runtime/autogen/hsa.py /tmp/hsa.py.bak
  456. cp tinygrad/runtime/autogen/comgr.py /tmp/comgr.py.bak
  457. cp tinygrad/runtime/autogen/amd_gpu.py /tmp/amd_gpu.py.bak
  458. ./autogen_stubs.sh hsa
  459. ./autogen_stubs.sh comgr
  460. ./autogen_stubs.sh amd
  461. diff /tmp/hsa.py.bak tinygrad/runtime/autogen/hsa.py
  462. diff /tmp/comgr.py.bak tinygrad/runtime/autogen/comgr.py
  463. diff /tmp/amd_gpu.py.bak tinygrad/runtime/autogen/amd_gpu.py
  464. - name: Verify Linux autogen
  465. if: matrix.backend == 'amd'
  466. run: |
  467. cp tinygrad/runtime/autogen/libc.py /tmp/libc.py.bak
  468. cp tinygrad/runtime/autogen/io_uring.py /tmp/io_uring.py.bak
  469. ./autogen_stubs.sh libc
  470. ./autogen_stubs.sh io_uring
  471. diff /tmp/libc.py.bak tinygrad/runtime/autogen/libc.py
  472. diff /tmp/io_uring.py.bak tinygrad/runtime/autogen/io_uring.py
  473. - name: Run pytest (not cuda or amd)
  474. if: matrix.backend!='ptx' && matrix.backend!='triton' && matrix.backend != 'amd' && matrix.backend != 'nv'
  475. run: python -m pytest -n=auto test/ --durations=20
  476. # - name: Run test_ops with FUZZ_UOPS=1
  477. # if: matrix.backend!='cuda' && matrix.backend!='ptx' && matrix.backend!='triton' && matrix.backend != 'amd' && matrix.backend != 'nv'
  478. # run: FUZZ_UOPS=1 python -m pytest -n=auto test/test_ops.py --durations=20
  479. - name: Run ONNX (only LLVM)
  480. if: matrix.backend == 'llvm'
  481. run: python -m pytest -n=auto test/external/external_test_onnx_backend.py --durations=20
  482. - name: Run pytest (cuda)
  483. if: matrix.backend=='ptx'||matrix.backend=='triton'||matrix.backend=='nv'
  484. run: python -m pytest -n=auto test/ -k 'not (half or test_efficientnet_safetensors)' --ignore=test/external --ignore=test/models --ignore test/test_gc.py --durations=20
  485. - name: Run pytest (amd)
  486. if: matrix.backend=='amd'
  487. run: python -m pytest -n=auto test/test_ops.py test/test_dtype.py test/test_dtype_alu.py test/test_linearizer.py test/test_randomness.py test/imported/test_indexing.py test/test_hcq.py --durations=20
  488. - name: Run TRANSCENDENTAL math
  489. run: TRANSCENDENTAL=2 python -m pytest -n=auto test/test_ops.py::TestOps::test_sin test/test_ops.py::TestOps::test_cos test/test_ops.py::TestOps::test_tan test/test_ops.py::TestOps::test_exp test/test_ops.py::TestOps::test_log --durations=20
  490. - name: Run process replay tests
  491. run: |
  492. export PR_TITLE=$(jq -r .pull_request.title "$GITHUB_EVENT_PATH")
  493. export COMMIT_MESSAGE=$(git show -s --format=%B ${{ github.event.pull_request.head.sha }})
  494. cp test/external/process_replay/process_replay.py ./process_replay.py && git fetch origin master && git -c advice.detachedHead=false checkout origin/master && PYTHONPATH=. python3 process_replay.py
  495. #testunicorn:
  496. # name: ARM64 unicorn Test
  497. # runs-on: ubuntu-latest
  498. # timeout-minutes: 10
  499. # steps:
  500. # - name: Checkout Code
  501. # uses: actions/checkout@v4
  502. # - name: Set up Python 3.11
  503. # uses: actions/setup-python@v5
  504. # with:
  505. # python-version: 3.11
  506. # - name: Cache python packages
  507. # uses: actions/cache@v4
  508. # with:
  509. # path: ${{ env.Python3_ROOT_DIR }}/lib/python3.11/site-packages
  510. # key: testing-arm-packages-${{ hashFiles('**/setup.py') }}
  511. # - name: Install cross-assembler
  512. # run: |
  513. # sudo apt update -y
  514. # sudo apt install -y --no-install-recommends gcc-aarch64-linux-gnu
  515. # - name: Install dependencies
  516. # run: pip install -e '.[testing,arm]' --extra-index-url https://download.pytorch.org/whl/cpu
  517. # - name: Test arm
  518. # run: CI=1 ARM64=1 CLANG=1 python -m pytest -n=auto test/ -k 'not (test_nn.py and (test_conv_transpose2d or test_conv2d))' --ignore=test/models --ignore=test/test_speed_v_torch.py --ignore=test/test_net_speed.py --ignore=test/test_specific_conv.py --ignore=test/unit/test_disk_tensor.py