Skip to content

[pull] master from tinygrad:master #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions test/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import numpy as np
from typing import List, Callable
import torch
import warnings
from tinygrad.helpers import getenv, IMAGE, DEBUG, CI, Context, TRANSCENDENTAL
from tinygrad import Tensor, Device, dtypes
from tinygrad.tensor import _to_np_dtype
from tinygrad.device import is_dtype_supported

if CI:
import warnings
warnings.filterwarnings("ignore", message="Non-empty compiler output encountered")

FORWARD_ONLY = getenv("FORWARD_ONLY", 0)
Expand Down Expand Up @@ -1275,18 +1275,22 @@ def test_var_axis(self):
helper_test_op([(15, 25, 35)], lambda x: x.var(2, correction=0))
helper_test_op([(15, 25, 35)], lambda x: x.var([1, 2], correction=0))
def test_var_zero_in_axis(self):
helper_test_op([(1,0,3,0,5)], lambda x: x.var(axis=(1,3)))
helper_test_op([(1,0,3,0,5)], lambda x: x.var(axis=(1,3), correction=0))
helper_test_op([(1,0,3,0,5)], lambda x: x.var(axis=(1,3), correction=5))
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="var\\(\\): degrees of freedom is <= 0")
helper_test_op([(1,0,3,0,5)], lambda x: x.var(axis=(1,3)))
helper_test_op([(1,0,3,0,5)], lambda x: x.var(axis=(1,3), correction=0))
helper_test_op([(1,0,3,0,5)], lambda x: x.var(axis=(1,3), correction=5))
def test_var_one_in_axis(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="var\\(\\): degrees of freedom is <= 0")
helper_test_op([(1,2,3,1,5)], lambda x: x.var(axis=(0,3)))
helper_test_op([(1,2,3,1,5)], lambda x: x.var(axis=(0,3), correction=5))
# TODO: fix backward
helper_test_op([(1,2,3,1,5)], lambda x: x.var(axis=(0,4), correction=5), forward_only=True)
helper_test_op([(1,)], lambda x: x.var(axis=(0,), correction=0))
helper_test_op([(1,2,3,1,5)], lambda x: x.var(axis=(0,3)))
helper_test_op([(1,2,3,1,5)], lambda x: x.var(axis=(0,3), correction=0))
helper_test_op([(1,2,3,1,5)], lambda x: x.var(axis=(0,3), correction=5))
helper_test_op([(1,2,3,1,5)], lambda x: x.var(axis=(0,4)))
helper_test_op([(1,2,3,1,5)], lambda x: x.var(axis=(0,4), correction=0))
# TODO: fix backward
helper_test_op([(1,2,3,1,5)], lambda x: x.var(axis=(0,4), correction=5), forward_only=True)
def test_var_keepdim(self):
helper_test_op([(15, 25, 35)], lambda x: x.var(keepdim=True))
helper_test_op([(15, 25, 35)], lambda x: x.var(0, keepdim=True, correction=0))
Expand All @@ -1303,18 +1307,22 @@ def test_std_axis(self):
helper_test_op([(15, 25, 35)], lambda x: x.std(2, correction=0))
helper_test_op([(15, 25, 35)], lambda x: x.std([1, 2], correction=0))
def test_std_zero_in_axis(self):
helper_test_op([(1,0,3,0,5)], lambda x: x.std(axis=(1,3)))
helper_test_op([(1,0,3,0,5)], lambda x: x.std(axis=(1,3), correction=0))
helper_test_op([(1,0,3,0,5)], lambda x: x.std(axis=(1,3), correction=5))
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="std\\(\\): degrees of freedom is <= 0")
helper_test_op([(1,0,3,0,5)], lambda x: x.std(axis=(1,3)))
helper_test_op([(1,0,3,0,5)], lambda x: x.std(axis=(1,3), correction=0))
helper_test_op([(1,0,3,0,5)], lambda x: x.std(axis=(1,3), correction=5))
def test_std_one_in_axis(self):
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="std\\(\\): degrees of freedom is <= 0")
helper_test_op([(1,2,3,1,5)], lambda x: x.std(axis=(0,3)))
helper_test_op([(1,2,3,1,5)], lambda x: x.std(axis=(0,3), correction=5))
helper_test_op([(1,2,3,1,5)], lambda x: x.std(axis=(0,4), correction=5))
# TODO: fix backward
helper_test_op([(1,)], lambda x: x.std(axis=(0,), correction=0), forward_only=True)
helper_test_op([(1,2,3,1,5)], lambda x: x.std(axis=(0,3)))
helper_test_op([(1,2,3,1,5)], lambda x: x.std(axis=(0,3), correction=0), forward_only=True)
helper_test_op([(1,2,3,1,5)], lambda x: x.std(axis=(0,3), correction=5))
helper_test_op([(1,2,3,1,5)], lambda x: x.std(axis=(0,4)))
helper_test_op([(1,2,3,1,5)], lambda x: x.std(axis=(0,4), correction=0))
helper_test_op([(1,2,3,1,5)], lambda x: x.std(axis=(0,4), correction=5))
def test_std_keepdim(self):
helper_test_op([(15, 25, 35)], lambda x: x.std(keepdim=True))
helper_test_op([(15, 25, 35)], lambda x: x.std(0, keepdim=True, correction=0))
Expand Down
1 change: 1 addition & 0 deletions tinygrad/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def capstone_flatdump(lib: bytes):
case 'x86_64' | 'AMD64': cs = capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_64)
case 'aarch64' | 'arm64': cs = capstone.Cs(capstone.CS_ARCH_ARM64, capstone.CS_MODE_ARM)
case machine: raise NotImplementedError(f"Capstone disassembly isn't supported for {machine}")
cs.skipdata = True
for instr in cs.disasm(lib, 0):
print(f"{instr.address:#08x}: {instr.mnemonic}\t{instr.op_str}")
sys.stdout.flush()
Expand Down
Loading