diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3f5191bd8b..72f5e2421f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -264,8 +264,8 @@ jobs: run: python -c "from tinygrad import Device; assert Device.DEFAULT == 'CPU', Device.DEFAULT" - name: Run unit tests run: CPU=1 python -m pytest -n=auto test/unit/ --durations=20 - - name: Check SPEC=1 - run: SPEC=1 python3 test/test_tiny.py + - name: Check SPEC=2 + run: SPEC=2 python3 test/test_tiny.py - name: Run targetted tests on NULL backend run: NULL=1 python3 -m unittest test.test_multitensor.TestMultiTensor.test_data_parallel_resnet_train_step test/device/test_null.py # TODO: too slow diff --git a/tinygrad/codegen/__init__.py b/tinygrad/codegen/__init__.py index b2b6b9aa94..99416e44c7 100644 --- a/tinygrad/codegen/__init__.py +++ b/tinygrad/codegen/__init__.py @@ -1,4 +1,4 @@ -from tinygrad.helpers import QUANTIZE, DEVECTORIZE, TRANSCENDENTAL +from tinygrad.helpers import QUANTIZE, DEVECTORIZE, TRANSCENDENTAL, SPEC from tinygrad.uop.ops import PatternMatcher, graph_rewrite, UOp, pm_lower_index_dtype from tinygrad.uop.spec import type_verify, program_spec from tinygrad.renderer import Renderer @@ -102,5 +102,5 @@ def full_rewrite(sink:UOp, ren:Renderer|None=None) -> list[UOp]: full_sink = full_rewrite_to_sink(sink, ren, optimize=sink.tag is None) assert len(full_sink.ranges) == 0, "all ranges must end by the sink" lst = linearize(full_sink) - if __debug__: type_verify(lst, program_spec) + if SPEC: type_verify(lst, program_spec) return lst diff --git a/tinygrad/helpers.py b/tinygrad/helpers.py index 6c0fb1cb13..fe5af45099 100644 --- a/tinygrad/helpers.py +++ b/tinygrad/helpers.py @@ -167,7 +167,7 @@ EMULATE = ContextVar("EMULATE", "") CPU_COUNT = ContextVar("CPU_COUNT", max(1, len(os.sched_getaffinity(0)) if hasattr(os, "sched_getaffinity") else (os.cpu_count() or 1))) CPU_LLVM, CPU_LVP, AMD_LLVM = ContextVar("CPU_LLVM", 0), ContextVar("CPU_LVP", 0), ContextVar("AMD_LLVM", 1) VIZ = PROFILE = ContextVar("VIZ", 0) -SPEC = ContextVar("SPEC", 0) +SPEC = ContextVar("SPEC", 1) # TODO: disable by default due to speed IGNORE_OOB = ContextVar("IGNORE_OOB", 1) PCONTIG = ContextVar("PCONTIG", 0) # partial contiguous in rangeify diff --git a/tinygrad/tensor.py b/tinygrad/tensor.py index c26360852d..57bd08ab2e 100644 --- a/tinygrad/tensor.py +++ b/tinygrad/tensor.py @@ -6,7 +6,7 @@ from typing import Callable, ClassVar, Sequence, cast, get_args, Literal, Suppor from tinygrad.dtype import DType, DTypeLike, dtypes, ImageDType, ConstType, least_upper_float, least_upper_dtype, sum_acc_dtype, to_dtype, truncate from tinygrad.dtype import _from_np_dtype, _to_np_dtype from tinygrad.helpers import argfix, make_tuple, flatten, prod, all_int, round_up, merge_dicts, argsort, getenv, all_same, fully_flatten, dedup -from tinygrad.helpers import IMAGE, WINO, Metadata, TRACEMETA, ceildiv, fetch, polyN, DEBUG, is_numpy_ndarray, FUSE_ATTENTION +from tinygrad.helpers import IMAGE, WINO, Metadata, TRACEMETA, ceildiv, fetch, polyN, DEBUG, is_numpy_ndarray, FUSE_ATTENTION, SPEC from tinygrad.helpers import suppress_finalizing from tinygrad.gradient import compute_gradient from tinygrad.uop.mathtraits import MathTrait @@ -229,7 +229,7 @@ class Tensor(MathTrait): big_sink = UOp.sink(*[x.uop for x in (self,)+lst]) # verify Tensors match the spec - if __debug__: type_verify(list(big_sink.toposort()), tensor_spec) + if SPEC: type_verify(list(big_sink.toposort()), tensor_spec) if any(isinstance(x._device, tuple) for x in big_sink.toposort()): _apply_map_to_tensors(get_multi_map(big_sink), "Apply Multi Map") diff --git a/tinygrad/uop/ops.py b/tinygrad/uop/ops.py index 18502fbfd8..f6328ffea1 100644 --- a/tinygrad/uop/ops.py +++ b/tinygrad/uop/ops.py @@ -64,7 +64,7 @@ class UOpMetaClass(type): if _buffer is not None: assert op is Ops.BUFFER, f"trying to set Buffer {_buffer} for {op}" buffers[created] = _buffer - if SPEC: + if SPEC > 1: from tinygrad.uop.spec import full_spec with Context(IGNORE_OOB=1): ret = full_spec.rewrite(created) if cast(bool|None, ret) is not True: raise RuntimeError(f"SPEC ISSUE {ret}: {created}")