mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-06-13 08:28:55 +08:00
* models matrix * fix typo and install gpu deps * install llvm deps if needed * fix * testops with cuda * remove pip cache since not work * cuda env * install cuda deps * maybe it will work now * i can't read * all tests in matrix * trim down more * opencl stuff in matrix * opencl pip cache * test split * change cuda test exclusion * test * fix cuda maybe * add models * add more n=auto * third thing * fix bug * cache pip more * change name * update tests * try again cause why not * balance * try again... * try apt cache for cuda * try on gpu: * try cuda again * update packages step * replace libz-dev with zlib1g-dev * only cache cuda * why error * fix gpuocelot bug * apt cache err * apt cache to slow? * opt and image in single runner * add a couple n=autos * remove test matrix * try cuda apt cache again * libz-dev -> zlib1g-dev * remove -s since not supported by xdist * the cache takes too long and doesn't work * combine webgpu and metal tests * combine imagenet to c and cpu tests * torch tests with linters * torch back by itself * small windows clang test with torch tests * fix a goofy windows bug * im dumb * bro * clang with linters * fix pylint error * linter not work on windows * try with clang again * clang and imagenet? * install deps * fix * fix quote * clang by itself (windows too slow) * env vars for imagenet * cache pip for metal and webgpu tests * try torch with metal and webgpu * doesn't work, too long * remove -v * try -n=logical * don't use logical * revert accidental thing * remove some prints unless CI * fix print unless CI * ignore speed tests for slow tests * clang windows in matrix (ubuntu being tested in imagenet->c test) * try manual pip cache * fix windows pip cache path * all manual pip cache * fix pip cache dir for macos * print_ci function in helpers * CI as variable, no print_ci * missed one * cuda tests with docker image * remove setup-python action for cuda * python->python3? * remove -s -v * try fix pip cache * maybe fix * try to fix pip cache * is this the path? * maybe cache pip * try again * create wheels dir * ? * cuda pip deps in dockerfile * disable pip cache for clang * image from ghcr instead of docker hub * why is clang like this * fast deps * try use different caches * remove the fast thing * try with lighter image * remove setup python for cuda * small docker and cuda fast deps * ignore a few more tests * cool docker thing (maybe) * oops * quotes * fix docker command * fix bug * ignore train efficientnet test * remove dockerfile (docker stuff takes too long) * remove docker stuff and normal cuda * oops * ignore the tests for cuda * does this work * ignore test_train on slow backends * add space * llvm ignore same tests as cuda * nvm * ignore lr scheduler tests * get some stats * fix ignore bug * remove extra ' * remove and * ignore test for llvm * change ignored tests and durationon all backends * fix * and -> or * ignore some more cuda tests * finally? * does this fix it * remove durations=0 * add some more tests to llvm * make last pytest more readable * fix * don't train efficientnet on cpu * try w/out pip cache * pip cache seems to be generally better * pytest file markers * try apt fast for cuda * use quick install for apt-fast * apt-fast not worth * apt-get to apt * fix typo * suppress warnings * register markers * disable debug on fuzz tests * change marker names * apt update and apt install in one command * update marker names in test.yml * webgpu pytest marker
128 lines
3.5 KiB
Python
128 lines
3.5 KiB
Python
import unittest
|
|
import numpy as np
|
|
from tinygrad.tensor import Tensor
|
|
import pytest
|
|
|
|
pytestmark = [pytest.mark.exclude_cuda, pytest.mark.webgpu]
|
|
|
|
class TestConv(unittest.TestCase):
|
|
def test_simple(self):
|
|
x = Tensor.ones(1,12,128,256)
|
|
w = Tensor.ones(32,12,3,3)
|
|
ret = x.conv2d(w, stride=(2,2), padding=(1,1)).numpy()
|
|
# it's not 108 around the padding
|
|
assert (ret[:, :, 1:-1, 1:-1] == 108).all()
|
|
assert ret[0,0,0,0] == 48
|
|
assert ret[0,0,0,1] == 72
|
|
|
|
def test_many_simple(self):
|
|
x = Tensor(np.arange(8*2*8).reshape(1,8,2,8).astype(np.float32))
|
|
#w = Tensor(np.arange(8*8*1*1).reshape(8,8,1,1).astype(np.float32))
|
|
w = Tensor.eye(8).reshape((8,8,1,1))
|
|
ret = x.conv2d(w, stride=(1,2), padding=(0,0)).numpy()
|
|
print(ret)
|
|
|
|
def test_lazycache(self):
|
|
Tensor.no_grad = True
|
|
x = Tensor.zeros(1, 32)
|
|
y = Tensor.zeros(32)
|
|
out = x + y.reshape((1,32,1)).reshape((1,32)) + y.reshape((1,32,1)).reshape((1,32))
|
|
out.numpy()
|
|
Tensor.no_grad = False
|
|
|
|
def test_simple_biased(self):
|
|
C = 8
|
|
x = Tensor.zeros(1,C,5,5)
|
|
w = Tensor.eye(C).reshape((C,C,1,1))
|
|
b = Tensor(np.arange(C).astype(np.float32))
|
|
ret = Tensor.conv2d(x,w,b).relu().conv2d(w,b)
|
|
|
|
print(ret.numpy())
|
|
|
|
def test_two_binops_no_rerun(self):
|
|
Tensor.no_grad = True
|
|
x = Tensor.randn(1,12,128,256)
|
|
w = Tensor.randn(32,12,3,3)
|
|
out = x.conv2d(w, stride=(2,2), padding=(1,1))
|
|
r1, r2 = out.relu(), (out-1)
|
|
np.testing.assert_allclose(r1.numpy(), np.maximum(out.numpy(), 0))
|
|
np.testing.assert_allclose(r2.numpy(), out.numpy() - 1)
|
|
Tensor.no_grad = False
|
|
|
|
def test_two_overlapping_binops_no_rerun(self):
|
|
Tensor.no_grad = True
|
|
x = Tensor.randn(1,12,128,256)
|
|
w = Tensor.randn(32,12,3,3)
|
|
out = x.conv2d(w, stride=(2,2), padding=(1,1))
|
|
r1, r2 = out.relu(), out.elu()
|
|
np.testing.assert_allclose(r1.numpy(), np.maximum(out.numpy(), 0))
|
|
np.testing.assert_allclose(r2.numpy(), np.where(out.numpy() > 0, out.numpy(), (np.exp(out.numpy()) - 1)), atol=1e-5)
|
|
Tensor.no_grad = False
|
|
|
|
def test_first_three(self):
|
|
Tensor.no_grad = True
|
|
x = Tensor.ones(1,12,128,256)
|
|
|
|
w = Tensor.ones(32,12,3,3)
|
|
x = x.conv2d(w, stride=(2,2), padding=(1,1)).elu()
|
|
|
|
w = Tensor.ones(32,1,3,3)
|
|
x = x.conv2d(w, padding=(1,1), groups=32).elu()
|
|
|
|
w = Tensor.ones(16,32,1,1)
|
|
x = x.conv2d(w).elu()
|
|
|
|
x = x.numpy()
|
|
print(x.shape)
|
|
Tensor.no_grad = False
|
|
|
|
def test_elu(self):
|
|
Tensor.no_grad = True
|
|
x = Tensor.ones(1,12,128,256)
|
|
|
|
w = Tensor.ones(32,12,3,3)
|
|
x = x.conv2d(w, stride=(2,2), padding=(1,1))
|
|
|
|
x = x.elu()
|
|
|
|
w = Tensor.ones(32,1,3,3)
|
|
x = x.conv2d(w, padding=(1,1), groups=32)
|
|
out = x.numpy()
|
|
Tensor.no_grad = False
|
|
|
|
def test_reduce_relu(self):
|
|
Tensor.no_grad = True
|
|
x = Tensor.ones(1,12,128,256)
|
|
x = x.sum(keepdim=True).relu()
|
|
out = x.numpy()
|
|
Tensor.no_grad = False
|
|
|
|
def test_bias(self):
|
|
Tensor.no_grad = True
|
|
from tinygrad.nn import Conv2d
|
|
x = Tensor.ones(1,12,128,256)
|
|
c = Conv2d(12, 32, 3)
|
|
x = c(x).relu()
|
|
w = Tensor.uniform(32, 1, 3, 3)
|
|
x = x.conv2d(w, groups=32)
|
|
out = x.numpy()
|
|
Tensor.no_grad = False
|
|
|
|
def test_multiadd(self):
|
|
w = Tensor.ones(32)
|
|
x = Tensor.ones(32).relu()
|
|
(w+x).numpy()
|
|
|
|
def test_reorder(self):
|
|
x = Tensor.ones(1,12,128,256)
|
|
w = Tensor.ones(12,12,3,3)
|
|
x = x.conv2d(w, padding=(1,1))
|
|
print(x.shape)
|
|
x = x.reshape((1, 12, 256, 128))
|
|
x += 1
|
|
x += 1
|
|
x = x.reshape((1, 12, 128, 256))
|
|
x.numpy()
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main() |