tinygrad 0.7.0__tar.gz → 0.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. {tinygrad-0.7.0 → tinygrad-0.9.0}/LICENSE +1 -1
  2. tinygrad-0.9.0/PKG-INFO +227 -0
  3. tinygrad-0.9.0/README.md +172 -0
  4. tinygrad-0.9.0/setup.py +70 -0
  5. tinygrad-0.9.0/test/test_arange.py +17 -0
  6. tinygrad-0.9.0/test/test_assign.py +378 -0
  7. tinygrad-0.9.0/test/test_const_folding.py +253 -0
  8. {tinygrad-0.7.0 → tinygrad-0.9.0}/test/test_conv.py +17 -8
  9. tinygrad-0.9.0/test/test_conv_shapetracker.py +22 -0
  10. tinygrad-0.9.0/test/test_copy_speed.py +67 -0
  11. {tinygrad-0.7.0 → tinygrad-0.9.0}/test/test_custom_function.py +19 -21
  12. tinygrad-0.9.0/test/test_device_speed.py +38 -0
  13. tinygrad-0.9.0/test/test_dtype.py +674 -0
  14. tinygrad-0.9.0/test/test_dtype_alu.py +163 -0
  15. tinygrad-0.9.0/test/test_fusion_op.py +50 -0
  16. tinygrad-0.9.0/test/test_fuzz_shape_ops.py +87 -0
  17. {tinygrad-0.7.0 → tinygrad-0.9.0}/test/test_gc.py +8 -8
  18. tinygrad-0.9.0/test/test_image_dtype.py +77 -0
  19. tinygrad-0.9.0/test/test_jit.py +337 -0
  20. tinygrad-0.9.0/test/test_kernel_cache.py +27 -0
  21. tinygrad-0.9.0/test/test_lazybuffer.py +117 -0
  22. tinygrad-0.9.0/test/test_lazyop.py +34 -0
  23. tinygrad-0.9.0/test/test_linearizer.py +1453 -0
  24. tinygrad-0.9.0/test/test_linearizer_failures.py +248 -0
  25. tinygrad-0.9.0/test/test_linearizer_overflows.py +89 -0
  26. tinygrad-0.9.0/test/test_masked_st.py +32 -0
  27. tinygrad-0.9.0/test/test_method_cache.py +48 -0
  28. tinygrad-0.9.0/test/test_multitensor.py +771 -0
  29. {tinygrad-0.7.0 → tinygrad-0.9.0}/test/test_net_speed.py +6 -21
  30. tinygrad-0.9.0/test/test_nn.py +406 -0
  31. tinygrad-0.9.0/test/test_ops.py +1754 -0
  32. {tinygrad-0.7.0 → tinygrad-0.9.0}/test/test_optim.py +50 -13
  33. tinygrad-0.9.0/test/test_pattern_matcher.py +93 -0
  34. tinygrad-0.9.0/test/test_pickle.py +60 -0
  35. tinygrad-0.9.0/test/test_randomness.py +204 -0
  36. tinygrad-0.9.0/test/test_sample.py +20 -0
  37. tinygrad-0.9.0/test/test_schedule.py +859 -0
  38. tinygrad-0.9.0/test/test_search.py +101 -0
  39. tinygrad-0.9.0/test/test_setitem.py +138 -0
  40. {tinygrad-0.7.0 → tinygrad-0.9.0}/test/test_specific_conv.py +7 -9
  41. {tinygrad-0.7.0 → tinygrad-0.9.0}/test/test_speed_v_torch.py +21 -26
  42. tinygrad-0.9.0/test/test_subbuffer.py +52 -0
  43. {tinygrad-0.7.0 → tinygrad-0.9.0}/test/test_symbolic_jit.py +102 -36
  44. {tinygrad-0.7.0 → tinygrad-0.9.0}/test/test_symbolic_ops.py +85 -32
  45. tinygrad-0.9.0/test/test_symbolic_shapetracker.py +190 -0
  46. tinygrad-0.9.0/test/test_tensor.py +570 -0
  47. tinygrad-0.9.0/test/test_tensor_data.py +57 -0
  48. tinygrad-0.9.0/test/test_tensor_variable.py +69 -0
  49. tinygrad-0.9.0/test/test_to_numpy.py +17 -0
  50. tinygrad-0.9.0/test/test_uop_graph.py +82 -0
  51. tinygrad-0.9.0/test/test_uops.py +245 -0
  52. tinygrad-0.9.0/test/test_uops_stats.py +83 -0
  53. tinygrad-0.9.0/test/test_winograd.py +71 -0
  54. tinygrad-0.9.0/test/test_zero_copy.py +27 -0
  55. tinygrad-0.9.0/tinygrad/__init__.py +6 -0
  56. tinygrad-0.9.0/tinygrad/codegen/kernel.py +632 -0
  57. tinygrad-0.9.0/tinygrad/codegen/linearizer.py +460 -0
  58. tinygrad-0.9.0/tinygrad/codegen/uops.py +415 -0
  59. tinygrad-0.9.0/tinygrad/device.py +183 -0
  60. tinygrad-0.9.0/tinygrad/dtype.py +113 -0
  61. tinygrad-0.9.0/tinygrad/engine/__init__.py +0 -0
  62. tinygrad-0.9.0/tinygrad/engine/graph.py +100 -0
  63. tinygrad-0.9.0/tinygrad/engine/jit.py +195 -0
  64. tinygrad-0.9.0/tinygrad/engine/realize.py +191 -0
  65. tinygrad-0.9.0/tinygrad/engine/schedule.py +362 -0
  66. tinygrad-0.9.0/tinygrad/engine/search.py +196 -0
  67. tinygrad-0.7.0/tinygrad/mlops.py → tinygrad-0.9.0/tinygrad/function.py +76 -55
  68. tinygrad-0.9.0/tinygrad/helpers.py +241 -0
  69. tinygrad-0.9.0/tinygrad/lazy.py +220 -0
  70. tinygrad-0.9.0/tinygrad/multi.py +169 -0
  71. tinygrad-0.9.0/tinygrad/nn/__init__.py +304 -0
  72. tinygrad-0.9.0/tinygrad/nn/datasets.py +7 -0
  73. tinygrad-0.9.0/tinygrad/nn/optim.py +150 -0
  74. tinygrad-0.9.0/tinygrad/nn/state.py +217 -0
  75. tinygrad-0.9.0/tinygrad/ops.py +136 -0
  76. tinygrad-0.9.0/tinygrad/renderer/__init__.py +61 -0
  77. tinygrad-0.9.0/tinygrad/renderer/assembly.py +276 -0
  78. tinygrad-0.9.0/tinygrad/renderer/cstyle.py +384 -0
  79. tinygrad-0.9.0/tinygrad/renderer/llvmir.py +160 -0
  80. tinygrad-0.9.0/tinygrad/runtime/autogen/amd_gpu.py +1900 -0
  81. tinygrad-0.9.0/tinygrad/runtime/autogen/comgr.py +865 -0
  82. tinygrad-0.9.0/tinygrad/runtime/autogen/cuda.py +5923 -0
  83. tinygrad-0.9.0/tinygrad/runtime/autogen/hip.py +5909 -0
  84. tinygrad-0.9.0/tinygrad/runtime/autogen/hsa.py +5761 -0
  85. tinygrad-0.9.0/tinygrad/runtime/autogen/kfd.py +812 -0
  86. tinygrad-0.9.0/tinygrad/runtime/autogen/nv_gpu.py +33328 -0
  87. tinygrad-0.9.0/tinygrad/runtime/autogen/opencl.py +1795 -0
  88. tinygrad-0.9.0/tinygrad/runtime/driver/hip_comgr.py +47 -0
  89. tinygrad-0.9.0/tinygrad/runtime/driver/hsa.py +143 -0
  90. tinygrad-0.9.0/tinygrad/runtime/graph/clang.py +38 -0
  91. tinygrad-0.9.0/tinygrad/runtime/graph/cuda.py +81 -0
  92. tinygrad-0.9.0/tinygrad/runtime/graph/hcq.py +143 -0
  93. tinygrad-0.9.0/tinygrad/runtime/graph/hsa.py +171 -0
  94. tinygrad-0.9.0/tinygrad/runtime/graph/metal.py +75 -0
  95. tinygrad-0.9.0/tinygrad/runtime/ops_amd.py +564 -0
  96. tinygrad-0.9.0/tinygrad/runtime/ops_clang.py +28 -0
  97. tinygrad-0.9.0/tinygrad/runtime/ops_cuda.py +185 -0
  98. tinygrad-0.9.0/tinygrad/runtime/ops_disk.py +60 -0
  99. tinygrad-0.9.0/tinygrad/runtime/ops_gpu.py +103 -0
  100. tinygrad-0.9.0/tinygrad/runtime/ops_hsa.py +278 -0
  101. tinygrad-0.9.0/tinygrad/runtime/ops_llvm.py +46 -0
  102. tinygrad-0.9.0/tinygrad/runtime/ops_metal.py +106 -0
  103. tinygrad-0.9.0/tinygrad/runtime/ops_npy.py +9 -0
  104. tinygrad-0.9.0/tinygrad/runtime/ops_nv.py +630 -0
  105. tinygrad-0.9.0/tinygrad/runtime/ops_python.py +204 -0
  106. tinygrad-0.9.0/tinygrad/shape/shapetracker.py +118 -0
  107. tinygrad-0.9.0/tinygrad/shape/symbolic.py +329 -0
  108. tinygrad-0.9.0/tinygrad/shape/view.py +296 -0
  109. tinygrad-0.9.0/tinygrad/tensor.py +2878 -0
  110. tinygrad-0.9.0/tinygrad.egg-info/PKG-INFO +227 -0
  111. tinygrad-0.9.0/tinygrad.egg-info/SOURCES.txt +113 -0
  112. tinygrad-0.9.0/tinygrad.egg-info/requires.txt +52 -0
  113. tinygrad-0.7.0/PKG-INFO +0 -182
  114. tinygrad-0.7.0/README.md +0 -162
  115. tinygrad-0.7.0/setup.py +0 -51
  116. tinygrad-0.7.0/test/test_allocators.py +0 -106
  117. tinygrad-0.7.0/test/test_assign.py +0 -67
  118. tinygrad-0.7.0/test/test_conv_shapetracker.py +0 -28
  119. tinygrad-0.7.0/test/test_dtype.py +0 -160
  120. tinygrad-0.7.0/test/test_helpers.py +0 -129
  121. tinygrad-0.7.0/test/test_jit.py +0 -138
  122. tinygrad-0.7.0/test/test_lazybuffer.py +0 -72
  123. tinygrad-0.7.0/test/test_linearizer.py +0 -60
  124. tinygrad-0.7.0/test/test_nn.py +0 -301
  125. tinygrad-0.7.0/test/test_ops.py +0 -1190
  126. tinygrad-0.7.0/test/test_randomness.py +0 -125
  127. tinygrad-0.7.0/test/test_symbolic_shapetracker.py +0 -169
  128. tinygrad-0.7.0/test/test_tensor.py +0 -224
  129. tinygrad-0.7.0/test/test_uops.py +0 -94
  130. tinygrad-0.7.0/tinygrad/codegen/assembly.py +0 -190
  131. tinygrad-0.7.0/tinygrad/codegen/kernel.py +0 -143
  132. tinygrad-0.7.0/tinygrad/codegen/linearizer.py +0 -440
  133. tinygrad-0.7.0/tinygrad/codegen/optimizer.py +0 -379
  134. tinygrad-0.7.0/tinygrad/codegen/search.py +0 -72
  135. tinygrad-0.7.0/tinygrad/graph.py +0 -83
  136. tinygrad-0.7.0/tinygrad/helpers.py +0 -134
  137. tinygrad-0.7.0/tinygrad/jit.py +0 -57
  138. tinygrad-0.7.0/tinygrad/lazy.py +0 -381
  139. tinygrad-0.7.0/tinygrad/nn/__init__.py +0 -124
  140. tinygrad-0.7.0/tinygrad/nn/image.py +0 -100
  141. tinygrad-0.7.0/tinygrad/nn/optim.py +0 -70
  142. tinygrad-0.7.0/tinygrad/nn/state.py +0 -120
  143. tinygrad-0.7.0/tinygrad/ops.py +0 -219
  144. tinygrad-0.7.0/tinygrad/renderer/assembly_arm64.py +0 -169
  145. tinygrad-0.7.0/tinygrad/renderer/assembly_ptx.py +0 -98
  146. tinygrad-0.7.0/tinygrad/renderer/cstyle.py +0 -197
  147. tinygrad-0.7.0/tinygrad/renderer/llvmir.py +0 -148
  148. tinygrad-0.7.0/tinygrad/renderer/wgsl.py +0 -53
  149. tinygrad-0.7.0/tinygrad/runtime/lib.py +0 -113
  150. tinygrad-0.7.0/tinygrad/runtime/ops_clang.py +0 -81
  151. tinygrad-0.7.0/tinygrad/runtime/ops_cpu.py +0 -51
  152. tinygrad-0.7.0/tinygrad/runtime/ops_cuda.py +0 -99
  153. tinygrad-0.7.0/tinygrad/runtime/ops_disk.py +0 -37
  154. tinygrad-0.7.0/tinygrad/runtime/ops_gpu.py +0 -106
  155. tinygrad-0.7.0/tinygrad/runtime/ops_hip.py +0 -82
  156. tinygrad-0.7.0/tinygrad/runtime/ops_llvm.py +0 -67
  157. tinygrad-0.7.0/tinygrad/runtime/ops_metal.py +0 -88
  158. tinygrad-0.7.0/tinygrad/runtime/ops_shm.py +0 -29
  159. tinygrad-0.7.0/tinygrad/runtime/ops_torch.py +0 -30
  160. tinygrad-0.7.0/tinygrad/runtime/ops_webgpu.py +0 -45
  161. tinygrad-0.7.0/tinygrad/shape/shapetracker.py +0 -286
  162. tinygrad-0.7.0/tinygrad/shape/symbolic.py +0 -304
  163. tinygrad-0.7.0/tinygrad/tensor.py +0 -707
  164. tinygrad-0.7.0/tinygrad.egg-info/PKG-INFO +0 -182
  165. tinygrad-0.7.0/tinygrad.egg-info/SOURCES.txt +0 -66
  166. tinygrad-0.7.0/tinygrad.egg-info/requires.txt +0 -46
  167. {tinygrad-0.7.0 → tinygrad-0.9.0}/setup.cfg +0 -0
  168. {tinygrad-0.7.0 → tinygrad-0.9.0}/tinygrad.egg-info/dependency_links.txt +0 -0
  169. {tinygrad-0.7.0 → tinygrad-0.9.0}/tinygrad.egg-info/top_level.txt +0 -0
@@ -1,4 +1,4 @@
1
- Copyright (c) 2023 George Hotz
1
+ Copyright (c) 2024, the tiny corp
2
2
 
3
3
  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:
4
4
 
@@ -0,0 +1,227 @@
1
+ Metadata-Version: 2.1
2
+ Name: tinygrad
3
+ Version: 0.9.0
4
+ Summary: You like pytorch? You like micrograd? You love tinygrad! <3
5
+ Author: George Hotz
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: numpy
13
+ Requires-Dist: tqdm
14
+ Requires-Dist: pyobjc-framework-Metal; platform_system == "Darwin"
15
+ Requires-Dist: pyobjc-framework-libdispatch; platform_system == "Darwin"
16
+ Provides-Extra: llvm
17
+ Requires-Dist: llvmlite; extra == "llvm"
18
+ Provides-Extra: arm
19
+ Requires-Dist: unicorn; extra == "arm"
20
+ Provides-Extra: triton
21
+ Requires-Dist: triton-nightly>=2.1.0.dev20231014192330; extra == "triton"
22
+ Provides-Extra: linting
23
+ Requires-Dist: pylint; extra == "linting"
24
+ Requires-Dist: mypy; extra == "linting"
25
+ Requires-Dist: typing-extensions; extra == "linting"
26
+ Requires-Dist: pre-commit; extra == "linting"
27
+ Requires-Dist: ruff; extra == "linting"
28
+ Requires-Dist: types-tqdm; extra == "linting"
29
+ Provides-Extra: testing
30
+ Requires-Dist: torch; extra == "testing"
31
+ Requires-Dist: pillow; extra == "testing"
32
+ Requires-Dist: pytest; extra == "testing"
33
+ Requires-Dist: pytest-xdist; extra == "testing"
34
+ Requires-Dist: onnx==1.16.0; extra == "testing"
35
+ Requires-Dist: onnx2torch; extra == "testing"
36
+ Requires-Dist: opencv-python; extra == "testing"
37
+ Requires-Dist: tabulate; extra == "testing"
38
+ Requires-Dist: safetensors; extra == "testing"
39
+ Requires-Dist: transformers; extra == "testing"
40
+ Requires-Dist: sentencepiece; extra == "testing"
41
+ Requires-Dist: tiktoken; extra == "testing"
42
+ Requires-Dist: librosa; extra == "testing"
43
+ Requires-Dist: networkx; extra == "testing"
44
+ Requires-Dist: hypothesis; extra == "testing"
45
+ Requires-Dist: nibabel; extra == "testing"
46
+ Provides-Extra: docs
47
+ Requires-Dist: mkdocs-material; extra == "docs"
48
+ Requires-Dist: mkdocstrings[python]; extra == "docs"
49
+ Requires-Dist: markdown-callouts; extra == "docs"
50
+ Requires-Dist: markdown-exec[ansi]; extra == "docs"
51
+ Requires-Dist: black; extra == "docs"
52
+ Provides-Extra: testing-tf
53
+ Requires-Dist: tensorflow==2.15.1; extra == "testing-tf"
54
+ Requires-Dist: tensorflow_addons; extra == "testing-tf"
55
+
56
+ <div align="center">
57
+
58
+ <picture>
59
+ <source media="(prefers-color-scheme: light)" srcset="/docs/logo_tiny_light.svg">
60
+ <img alt="tiny corp logo" src="/docs/logo_tiny_dark.svg" width="50%" height="50%">
61
+ </picture>
62
+
63
+ 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).
64
+
65
+ <h3>
66
+
67
+ [Homepage](https://github.com/tinygrad/tinygrad) | [Documentation](/docs) | [Examples](/examples) | [Showcase](/docs/showcase.md) | [Discord](https://discord.gg/ZjZadyC7PK)
68
+
69
+ </h3>
70
+
71
+ [![GitHub Repo stars](https://img.shields.io/github/stars/tinygrad/tinygrad)](https://github.com/tinygrad/tinygrad/stargazers)
72
+ [![Unit Tests](https://github.com/tinygrad/tinygrad/actions/workflows/test.yml/badge.svg)](https://github.com/tinygrad/tinygrad/actions/workflows/test.yml)
73
+ [![Discord](https://img.shields.io/discord/1068976834382925865)](https://discord.gg/ZjZadyC7PK)
74
+
75
+ </div>
76
+
77
+ ---
78
+
79
+ This may not be the best deep learning framework, but it is a deep learning framework.
80
+
81
+ Due to its extreme simplicity, it aims to be the easiest framework to add new accelerators to, with support for both inference and training. If XLA is CISC, tinygrad is RISC.
82
+
83
+ tinygrad is still alpha software, but we [raised some money](https://geohot.github.io/blog/jekyll/update/2023/05/24/the-tiny-corp-raised-5M.html) to make it good. Someday, we will tape out chips.
84
+
85
+ ## Features
86
+
87
+ ### LLaMA and Stable Diffusion
88
+
89
+ tinygrad can run [LLaMA](/docs/showcase.md#llama) and [Stable Diffusion](/docs/showcase.md#stable-diffusion)!
90
+
91
+ ### Laziness
92
+
93
+ Try a matmul. See how, despite the style, it is fused into one kernel with the power of laziness.
94
+
95
+ ```sh
96
+ DEBUG=3 python3 -c "from tinygrad import Tensor;
97
+ N = 1024; a, b = Tensor.rand(N, N), Tensor.rand(N, N);
98
+ c = (a.reshape(N, 1, N) * b.T.reshape(1, N, N)).sum(axis=2);
99
+ print((c.numpy() - (a.numpy() @ b.numpy())).mean())"
100
+ ```
101
+
102
+ And we can change `DEBUG` to `4` to see the generated code.
103
+
104
+ ### Neural networks
105
+
106
+ As it turns out, 90% of what you need for neural networks are a decent autograd/tensor library.
107
+ Throw in an optimizer, a data loader, and some compute, and you have all you need.
108
+
109
+ ```py
110
+ from tinygrad import Tensor, nn
111
+
112
+ class LinearNet:
113
+ def __init__(self):
114
+ self.l1 = Tensor.kaiming_uniform(784, 128)
115
+ self.l2 = Tensor.kaiming_uniform(128, 10)
116
+ def __call__(self, x:Tensor) -> Tensor:
117
+ return x.flatten(1).dot(self.l1).relu().dot(self.l2)
118
+
119
+ model = LinearNet()
120
+ optim = nn.optim.Adam([model.l1, model.l2], lr=0.001)
121
+
122
+ x, y = Tensor.rand(4, 1, 28, 28), Tensor([2,4,3,7]) # replace with real mnist dataloader
123
+
124
+ for i in range(10):
125
+ optim.zero_grad()
126
+ loss = model(x).sparse_categorical_crossentropy(y).backward()
127
+ optim.step()
128
+ print(i, loss.item())
129
+ ```
130
+
131
+ See [examples/beautiful_mnist.py](examples/beautiful_mnist.py) for the full version that gets 98% in ~5 seconds
132
+
133
+ ## Accelerators
134
+
135
+ tinygrad already supports numerous accelerators, including:
136
+
137
+ - [x] [GPU (OpenCL)](tinygrad/runtime/ops_gpu.py)
138
+ - [x] [CLANG (C Code)](tinygrad/runtime/ops_clang.py)
139
+ - [x] [LLVM](tinygrad/runtime/ops_llvm.py)
140
+ - [x] [METAL](tinygrad/runtime/ops_metal.py)
141
+ - [x] [CUDA](tinygrad/runtime/ops_cuda.py)
142
+ - [x] [HSA](tinygrad/runtime/ops_hsa.py)
143
+
144
+ And it is easy to add more! Your accelerator of choice only needs to support a total of ~25 low level ops.
145
+
146
+ ## Installation
147
+
148
+ The current recommended way to install tinygrad is from source.
149
+
150
+ ### From source
151
+
152
+ ```sh
153
+ git clone https://github.com/tinygrad/tinygrad.git
154
+ cd tinygrad
155
+ python3 -m pip install -e .
156
+ ```
157
+
158
+ ### Direct (master)
159
+
160
+ ```sh
161
+ python3 -m pip install git+https://github.com/tinygrad/tinygrad.git
162
+ ```
163
+
164
+ ## Documentation
165
+
166
+ Documentation along with a quick start guide can be found in the [docs/](/docs) directory.
167
+
168
+ ### Quick example comparing to PyTorch
169
+
170
+ ```py
171
+ from tinygrad import Tensor
172
+
173
+ x = Tensor.eye(3, requires_grad=True)
174
+ y = Tensor([[2.0,0,-2.0]], requires_grad=True)
175
+ z = y.matmul(x).sum()
176
+ z.backward()
177
+
178
+ print(x.grad.numpy()) # dz/dx
179
+ print(y.grad.numpy()) # dz/dy
180
+ ```
181
+
182
+ The same thing but in PyTorch:
183
+ ```py
184
+ import torch
185
+
186
+ x = torch.eye(3, requires_grad=True)
187
+ y = torch.tensor([[2.0,0,-2.0]], requires_grad=True)
188
+ z = y.matmul(x).sum()
189
+ z.backward()
190
+
191
+ print(x.grad.numpy()) # dz/dx
192
+ print(y.grad.numpy()) # dz/dy
193
+ ```
194
+
195
+ ## Contributing
196
+
197
+ There has been a lot of interest in tinygrad lately. Following these guidelines will help your PR get accepted.
198
+
199
+ We'll start with what will get your PR closed with a pointer to this section:
200
+
201
+ - No code golf! While low line count is a guiding light of this project, anything that remotely looks like code golf will be closed. The true goal is reducing complexity and increasing readability, and deleting `\n`s does nothing to help with that.
202
+ - All docs and whitespace changes will be closed unless you are a well-known contributor. The people writing the docs should be those who know the codebase the absolute best. People who have not demonstrated that shouldn't be messing with docs. Whitespace changes are both useless *and* carry a risk of introducing bugs.
203
+ - Anything you claim is a "speedup" must be benchmarked. In general, the goal is simplicity, so even if your PR makes things marginally faster, you have to consider the tradeoff with maintainablity and readablity.
204
+ - In general, the code outside the core `tinygrad/` folder is not well tested, so unless the current code there is broken, you shouldn't be changing it.
205
+ - If your PR looks "complex", is a big diff, or adds lots of lines, it won't be reviewed or merged. Consider breaking it up into smaller PRs that are individually clear wins. A common pattern I see is prerequisite refactors before adding new functionality. If you can (cleanly) refactor to the point that the feature is a 3 line change, this is great, and something easy for us to review.
206
+
207
+ Now, what we want:
208
+
209
+ - Bug fixes (with a regression test) are great! This library isn't 1.0 yet, so if you stumble upon a bug, fix it, write a test, and submit a PR, this is valuable work.
210
+ - Solving bounties! tinygrad [offers cash bounties](https://docs.google.com/spreadsheets/d/1WKHbT-7KOgjEawq5h5Ic1qUWzpfAzuD_J06N1JwOCGs/edit?usp=sharing) for certain improvements to the library. All new code should be high quality and well tested.
211
+ - Features. However, if you are adding a feature, consider the line tradeoff. If it's 3 lines, there's less of a bar of usefulness it has to meet over something that's 30 or 300 lines. All features must have regression tests. In general with no other constraints, your feature's API should match torch or numpy.
212
+ - Refactors that are clear wins. In general, if your refactor isn't a clear win it will be closed. But some refactors are amazing! Think about readability in a deep core sense. A whitespace change or moving a few functions around is useless, but if you realize that two 100 line functions can actually use the same 110 line function with arguments while also improving readability, this is a big win.
213
+ - Tests/fuzzers. If you can add tests that are non brittle, they are welcome. We have some fuzzers in here too, and there's a plethora of bugs that can be found with them and by improving them. Finding bugs, even writing broken tests (that should pass) with `@unittest.expectedFailure` is great. This is how we make progress.
214
+ - Dead code removal from core `tinygrad/` folder. We don't care about the code in extra, but removing dead code from the core library is great. Less for new people to read and be confused by.
215
+
216
+ ### Running tests
217
+
218
+ You should install the pre-commit hooks with `pre-commit install`. This will run the linter, mypy, and a subset of the tests on every commit.
219
+
220
+ For more examples on how to run the full test suite please refer to the [CI workflow](.github/workflows/test.yml).
221
+
222
+ Some examples of running tests locally:
223
+ ```sh
224
+ python3 -m pip install -e '.[testing]' # install extra deps for testing
225
+ python3 test/test_ops.py # just the ops tests
226
+ python3 -m pytest test/ # whole test suite
227
+ ```
@@ -0,0 +1,172 @@
1
+ <div align="center">
2
+
3
+ <picture>
4
+ <source media="(prefers-color-scheme: light)" srcset="/docs/logo_tiny_light.svg">
5
+ <img alt="tiny corp logo" src="/docs/logo_tiny_dark.svg" width="50%" height="50%">
6
+ </picture>
7
+
8
+ 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).
9
+
10
+ <h3>
11
+
12
+ [Homepage](https://github.com/tinygrad/tinygrad) | [Documentation](/docs) | [Examples](/examples) | [Showcase](/docs/showcase.md) | [Discord](https://discord.gg/ZjZadyC7PK)
13
+
14
+ </h3>
15
+
16
+ [![GitHub Repo stars](https://img.shields.io/github/stars/tinygrad/tinygrad)](https://github.com/tinygrad/tinygrad/stargazers)
17
+ [![Unit Tests](https://github.com/tinygrad/tinygrad/actions/workflows/test.yml/badge.svg)](https://github.com/tinygrad/tinygrad/actions/workflows/test.yml)
18
+ [![Discord](https://img.shields.io/discord/1068976834382925865)](https://discord.gg/ZjZadyC7PK)
19
+
20
+ </div>
21
+
22
+ ---
23
+
24
+ This may not be the best deep learning framework, but it is a deep learning framework.
25
+
26
+ Due to its extreme simplicity, it aims to be the easiest framework to add new accelerators to, with support for both inference and training. If XLA is CISC, tinygrad is RISC.
27
+
28
+ tinygrad is still alpha software, but we [raised some money](https://geohot.github.io/blog/jekyll/update/2023/05/24/the-tiny-corp-raised-5M.html) to make it good. Someday, we will tape out chips.
29
+
30
+ ## Features
31
+
32
+ ### LLaMA and Stable Diffusion
33
+
34
+ tinygrad can run [LLaMA](/docs/showcase.md#llama) and [Stable Diffusion](/docs/showcase.md#stable-diffusion)!
35
+
36
+ ### Laziness
37
+
38
+ Try a matmul. See how, despite the style, it is fused into one kernel with the power of laziness.
39
+
40
+ ```sh
41
+ DEBUG=3 python3 -c "from tinygrad import Tensor;
42
+ N = 1024; a, b = Tensor.rand(N, N), Tensor.rand(N, N);
43
+ c = (a.reshape(N, 1, N) * b.T.reshape(1, N, N)).sum(axis=2);
44
+ print((c.numpy() - (a.numpy() @ b.numpy())).mean())"
45
+ ```
46
+
47
+ And we can change `DEBUG` to `4` to see the generated code.
48
+
49
+ ### Neural networks
50
+
51
+ As it turns out, 90% of what you need for neural networks are a decent autograd/tensor library.
52
+ Throw in an optimizer, a data loader, and some compute, and you have all you need.
53
+
54
+ ```py
55
+ from tinygrad import Tensor, nn
56
+
57
+ class LinearNet:
58
+ def __init__(self):
59
+ self.l1 = Tensor.kaiming_uniform(784, 128)
60
+ self.l2 = Tensor.kaiming_uniform(128, 10)
61
+ def __call__(self, x:Tensor) -> Tensor:
62
+ return x.flatten(1).dot(self.l1).relu().dot(self.l2)
63
+
64
+ model = LinearNet()
65
+ optim = nn.optim.Adam([model.l1, model.l2], lr=0.001)
66
+
67
+ x, y = Tensor.rand(4, 1, 28, 28), Tensor([2,4,3,7]) # replace with real mnist dataloader
68
+
69
+ for i in range(10):
70
+ optim.zero_grad()
71
+ loss = model(x).sparse_categorical_crossentropy(y).backward()
72
+ optim.step()
73
+ print(i, loss.item())
74
+ ```
75
+
76
+ See [examples/beautiful_mnist.py](examples/beautiful_mnist.py) for the full version that gets 98% in ~5 seconds
77
+
78
+ ## Accelerators
79
+
80
+ tinygrad already supports numerous accelerators, including:
81
+
82
+ - [x] [GPU (OpenCL)](tinygrad/runtime/ops_gpu.py)
83
+ - [x] [CLANG (C Code)](tinygrad/runtime/ops_clang.py)
84
+ - [x] [LLVM](tinygrad/runtime/ops_llvm.py)
85
+ - [x] [METAL](tinygrad/runtime/ops_metal.py)
86
+ - [x] [CUDA](tinygrad/runtime/ops_cuda.py)
87
+ - [x] [HSA](tinygrad/runtime/ops_hsa.py)
88
+
89
+ And it is easy to add more! Your accelerator of choice only needs to support a total of ~25 low level ops.
90
+
91
+ ## Installation
92
+
93
+ The current recommended way to install tinygrad is from source.
94
+
95
+ ### From source
96
+
97
+ ```sh
98
+ git clone https://github.com/tinygrad/tinygrad.git
99
+ cd tinygrad
100
+ python3 -m pip install -e .
101
+ ```
102
+
103
+ ### Direct (master)
104
+
105
+ ```sh
106
+ python3 -m pip install git+https://github.com/tinygrad/tinygrad.git
107
+ ```
108
+
109
+ ## Documentation
110
+
111
+ Documentation along with a quick start guide can be found in the [docs/](/docs) directory.
112
+
113
+ ### Quick example comparing to PyTorch
114
+
115
+ ```py
116
+ from tinygrad import Tensor
117
+
118
+ x = Tensor.eye(3, requires_grad=True)
119
+ y = Tensor([[2.0,0,-2.0]], requires_grad=True)
120
+ z = y.matmul(x).sum()
121
+ z.backward()
122
+
123
+ print(x.grad.numpy()) # dz/dx
124
+ print(y.grad.numpy()) # dz/dy
125
+ ```
126
+
127
+ The same thing but in PyTorch:
128
+ ```py
129
+ import torch
130
+
131
+ x = torch.eye(3, requires_grad=True)
132
+ y = torch.tensor([[2.0,0,-2.0]], requires_grad=True)
133
+ z = y.matmul(x).sum()
134
+ z.backward()
135
+
136
+ print(x.grad.numpy()) # dz/dx
137
+ print(y.grad.numpy()) # dz/dy
138
+ ```
139
+
140
+ ## Contributing
141
+
142
+ There has been a lot of interest in tinygrad lately. Following these guidelines will help your PR get accepted.
143
+
144
+ We'll start with what will get your PR closed with a pointer to this section:
145
+
146
+ - No code golf! While low line count is a guiding light of this project, anything that remotely looks like code golf will be closed. The true goal is reducing complexity and increasing readability, and deleting `\n`s does nothing to help with that.
147
+ - All docs and whitespace changes will be closed unless you are a well-known contributor. The people writing the docs should be those who know the codebase the absolute best. People who have not demonstrated that shouldn't be messing with docs. Whitespace changes are both useless *and* carry a risk of introducing bugs.
148
+ - Anything you claim is a "speedup" must be benchmarked. In general, the goal is simplicity, so even if your PR makes things marginally faster, you have to consider the tradeoff with maintainablity and readablity.
149
+ - In general, the code outside the core `tinygrad/` folder is not well tested, so unless the current code there is broken, you shouldn't be changing it.
150
+ - If your PR looks "complex", is a big diff, or adds lots of lines, it won't be reviewed or merged. Consider breaking it up into smaller PRs that are individually clear wins. A common pattern I see is prerequisite refactors before adding new functionality. If you can (cleanly) refactor to the point that the feature is a 3 line change, this is great, and something easy for us to review.
151
+
152
+ Now, what we want:
153
+
154
+ - Bug fixes (with a regression test) are great! This library isn't 1.0 yet, so if you stumble upon a bug, fix it, write a test, and submit a PR, this is valuable work.
155
+ - Solving bounties! tinygrad [offers cash bounties](https://docs.google.com/spreadsheets/d/1WKHbT-7KOgjEawq5h5Ic1qUWzpfAzuD_J06N1JwOCGs/edit?usp=sharing) for certain improvements to the library. All new code should be high quality and well tested.
156
+ - Features. However, if you are adding a feature, consider the line tradeoff. If it's 3 lines, there's less of a bar of usefulness it has to meet over something that's 30 or 300 lines. All features must have regression tests. In general with no other constraints, your feature's API should match torch or numpy.
157
+ - Refactors that are clear wins. In general, if your refactor isn't a clear win it will be closed. But some refactors are amazing! Think about readability in a deep core sense. A whitespace change or moving a few functions around is useless, but if you realize that two 100 line functions can actually use the same 110 line function with arguments while also improving readability, this is a big win.
158
+ - Tests/fuzzers. If you can add tests that are non brittle, they are welcome. We have some fuzzers in here too, and there's a plethora of bugs that can be found with them and by improving them. Finding bugs, even writing broken tests (that should pass) with `@unittest.expectedFailure` is great. This is how we make progress.
159
+ - Dead code removal from core `tinygrad/` folder. We don't care about the code in extra, but removing dead code from the core library is great. Less for new people to read and be confused by.
160
+
161
+ ### Running tests
162
+
163
+ You should install the pre-commit hooks with `pre-commit install`. This will run the linter, mypy, and a subset of the tests on every commit.
164
+
165
+ For more examples on how to run the full test suite please refer to the [CI workflow](.github/workflows/test.yml).
166
+
167
+ Some examples of running tests locally:
168
+ ```sh
169
+ python3 -m pip install -e '.[testing]' # install extra deps for testing
170
+ python3 test/test_ops.py # just the ops tests
171
+ python3 -m pytest test/ # whole test suite
172
+ ```
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from pathlib import Path
4
+ from setuptools import setup
5
+
6
+ directory = Path(__file__).resolve().parent
7
+ with open(directory / 'README.md', encoding='utf-8') as f:
8
+ long_description = f.read()
9
+
10
+ setup(name='tinygrad',
11
+ version='0.9.0',
12
+ description='You like pytorch? You like micrograd? You love tinygrad! <3',
13
+ author='George Hotz',
14
+ license='MIT',
15
+ long_description=long_description,
16
+ long_description_content_type='text/markdown',
17
+ packages = ['tinygrad', 'tinygrad.runtime.autogen', 'tinygrad.codegen', 'tinygrad.nn', 'tinygrad.renderer', 'tinygrad.engine',
18
+ 'tinygrad.runtime', 'tinygrad.runtime.driver', 'tinygrad.runtime.graph', 'tinygrad.shape'],
19
+ classifiers=[
20
+ "Programming Language :: Python :: 3",
21
+ "License :: OSI Approved :: MIT License"
22
+ ],
23
+ install_requires=["numpy", "tqdm",
24
+ "pyobjc-framework-Metal; platform_system=='Darwin'",
25
+ "pyobjc-framework-libdispatch; platform_system=='Darwin'"],
26
+ python_requires='>=3.8',
27
+ extras_require={
28
+ 'llvm': ["llvmlite"],
29
+ 'arm': ["unicorn"],
30
+ 'triton': ["triton-nightly>=2.1.0.dev20231014192330"],
31
+ 'linting': [
32
+ "pylint",
33
+ "mypy",
34
+ "typing-extensions",
35
+ "pre-commit",
36
+ "ruff",
37
+ "types-tqdm",
38
+ ],
39
+ #'mlperf': ["mlperf-logging @ git+https://github.com/mlperf/logging.git@4.0.0-rc2"],
40
+ 'testing': [
41
+ "torch",
42
+ "pillow",
43
+ "pytest",
44
+ "pytest-xdist",
45
+ "onnx==1.16.0",
46
+ "onnx2torch",
47
+ "opencv-python",
48
+ "tabulate",
49
+ "safetensors",
50
+ "transformers",
51
+ "sentencepiece",
52
+ "tiktoken",
53
+ "librosa",
54
+ "networkx",
55
+ "hypothesis",
56
+ "nibabel",
57
+ ],
58
+ 'docs': [
59
+ "mkdocs-material",
60
+ "mkdocstrings[python]",
61
+ "markdown-callouts",
62
+ "markdown-exec[ansi]",
63
+ "black"
64
+ ],
65
+ 'testing_tf': [
66
+ "tensorflow==2.15.1",
67
+ "tensorflow_addons",
68
+ ]
69
+ },
70
+ include_package_data=True)
@@ -0,0 +1,17 @@
1
+ import unittest
2
+ from tinygrad import Tensor, GlobalCounters
3
+
4
+ class TestArange(unittest.TestCase):
5
+ def _get_flops(self, N):
6
+ GlobalCounters.reset()
7
+ Tensor.arange(N).realize()
8
+ return GlobalCounters.global_ops
9
+
10
+ def test_complexity(self):
11
+ f1 = self._get_flops(256)
12
+ f2 = self._get_flops(2560)
13
+ print(f"{f1=}, {f2=}")
14
+ assert f2 / f1 < 15, f"bad complexity, flops {f2/f1:.1f}X while inputs 10X"
15
+
16
+ if __name__ == "__main__":
17
+ unittest.main()