diff --git a/tinygrad/codegen/kernel.py b/tinygrad/codegen/kernel.py index 7b9426d99c..d97a1e01bf 100644 --- a/tinygrad/codegen/kernel.py +++ b/tinygrad/codegen/kernel.py @@ -2,7 +2,7 @@ from __future__ import annotations import itertools, functools from dataclasses import dataclass from collections import defaultdict -from typing import Optional, cast, Final, DefaultDict, Callable, Sequence +from typing import Optional, cast, Final, Callable, Sequence from enum import Enum, auto from tinygrad.ops import GroupOp, KernelInfo, UOp, Ops, can_pad, print_uops, type_verify, resolve, Variable, sint, \ @@ -566,7 +566,7 @@ class Kernel: # **** kernel outputs **** - kernel_cnt: Final[DefaultDict[str, int]] = defaultdict(int) + kernel_cnt: Final[defaultdict[str, int]] = defaultdict(int) @functools.cached_property def name(self) -> str: # kernel name (before late upcast) diff --git a/tinygrad/codegen/uopgraph.py b/tinygrad/codegen/uopgraph.py index a536db0f04..3588f548e8 100644 --- a/tinygrad/codegen/uopgraph.py +++ b/tinygrad/codegen/uopgraph.py @@ -1,5 +1,5 @@ from __future__ import annotations -from typing import Optional, TYPE_CHECKING, Any, DefaultDict, Callable +from typing import Optional, TYPE_CHECKING, Any, Callable import functools, itertools, operator from collections import defaultdict from tinygrad.dtype import dtypes, ImageDType, PtrDType @@ -19,7 +19,7 @@ def fold_expanded(ex, buf): is_load, is_image = new_srcs[0].op is Ops.LOAD, isinstance(buf.dtype, ImageDType) # first, extract all the relevant offsets - offsets_rootsrc: DefaultDict[Any, dict] = defaultdict(dict) + offsets_rootsrc: defaultdict[Any, dict] = defaultdict(dict) for i,s in enumerate(new_srcs): idx = s.src[0].src[1] if s.dtype.count != 1 or (is_image and idx.dtype.count == 2): continue diff --git a/tinygrad/helpers.py b/tinygrad/helpers.py index f050f9ffce..458b31bbd5 100644 --- a/tinygrad/helpers.py +++ b/tinygrad/helpers.py @@ -2,7 +2,7 @@ from __future__ import annotations import os, functools, platform, time, re, contextlib, operator, hashlib, pickle, sqlite3, tempfile, pathlib, string, ctypes, sys, gzip import urllib.request, subprocess, shutil, math, contextvars, types, copyreg, inspect, importlib from dataclasses import dataclass -from typing import Dict, Union, ClassVar, Optional, Iterable, Any, TypeVar, Callable, Sequence, TypeGuard +from typing import Union, ClassVar, Optional, Iterable, Any, TypeVar, Callable, Sequence, TypeGuard T = TypeVar("T") U = TypeVar("U") @@ -181,7 +181,7 @@ def diskcache_clear(): drop_tables = cur.execute("SELECT 'DROP TABLE IF EXISTS ' || quote(name) || ';' FROM sqlite_master WHERE type = 'table';").fetchall() cur.executescript("\n".join([s[0] for s in drop_tables] + ["VACUUM;"])) -def diskcache_get(table:str, key:Union[Dict, str, int]) -> Any: +def diskcache_get(table:str, key:Union[dict, str, int]) -> Any: if CACHELEVEL == 0: return None if isinstance(key, (str,int)): key = {"key": key} conn = db_connection() @@ -194,7 +194,7 @@ def diskcache_get(table:str, key:Union[Dict, str, int]) -> Any: return None _db_tables = set() -def diskcache_put(table:str, key:Union[Dict, str, int], val:Any, prepickled=False): +def diskcache_put(table:str, key:Union[dict, str, int], val:Any, prepickled=False): if CACHELEVEL == 0: return val if isinstance(key, (str,int)): key = {"key": key} conn = db_connection() diff --git a/tinygrad/multi.py b/tinygrad/multi.py index f056e9ae91..0ef54a9434 100644 --- a/tinygrad/multi.py +++ b/tinygrad/multi.py @@ -2,8 +2,7 @@ from __future__ import annotations import functools, itertools, operator from tinygrad.helpers import all_same, all_int, dedup, prod, DEBUG, RING, getenv from tinygrad.dtype import DType -from tinygrad.ops import Ops, MathTrait, UOp -from tinygrad.shape.shapetracker import sint +from tinygrad.ops import Ops, MathTrait, UOp, sint def all_reduce(bop: Ops, lbs: list[UOp]) -> list[UOp]: assert all_int(lbs[0].shape), f"does not support symbolic shape {lbs[0].shape}" diff --git a/tinygrad/nn/__init__.py b/tinygrad/nn/__init__.py index 088b45df5a..fd9af9b2d9 100644 --- a/tinygrad/nn/__init__.py +++ b/tinygrad/nn/__init__.py @@ -1,6 +1,7 @@ from __future__ import annotations import math -from tinygrad.tensor import Tensor, dtypes +from tinygrad.tensor import Tensor +from tinygrad.dtype import dtypes from tinygrad.device import is_dtype_supported from tinygrad.helpers import prod, make_tuple, flatten from tinygrad.nn import optim, state, datasets # noqa: F401 diff --git a/tinygrad/renderer/cstyle.py b/tinygrad/renderer/cstyle.py index 5ab62c76ee..3e41ff400d 100644 --- a/tinygrad/renderer/cstyle.py +++ b/tinygrad/renderer/cstyle.py @@ -1,4 +1,4 @@ -from typing import Dict, Optional, Union, DefaultDict, Literal, Callable, cast +from typing import Optional, Union, Literal, Callable, cast import os, math from collections import defaultdict, Counter from tinygrad.ops import GroupOp, Ops, UOp, PatternMatcher, UPat @@ -77,7 +77,7 @@ class CStyleLanguage(Renderer): type_map: dict[DType, str] = {} infinity: str = "INFINITY" nan: str = "NAN" - code_for_op: Dict = { + code_for_op: dict = { Ops.SQRT: lambda x,dtype: f"sqrt({x})", Ops.RECIP: lambda x,dtype: f"(1/{x})", Ops.NEG: lambda x,dtype: f"-{x}", Ops.EXP2: lambda x,dtype: f"exp2({x})", Ops.LOG2: lambda x,dtype: f"log2({x})", Ops.SIN: lambda x,dtype: f"sin({x})", Ops.AND: lambda a,b,dtype: f"({a}&{b})", Ops.XOR: lambda a,b,dtype: f"({a}^{b})", Ops.OR: lambda a,b,dtype: f"({a}|{b})", @@ -117,7 +117,7 @@ class CStyleLanguage(Renderer): bufs: dict[UOp, tuple[str, tuple[DType, bool]]] = {} kernel = [] depth = 1 - c: DefaultDict[str, int] = defaultdict(int) + c: defaultdict[str, int] = defaultdict(int) for u in uops: if u.op in (Ops.DEFINE_GLOBAL, Ops.DEFINE_VAR): r[u] = f"data{u.arg}" if u.op is Ops.DEFINE_GLOBAL else u.arg[0] diff --git a/tinygrad/runtime/ops_python.py b/tinygrad/runtime/ops_python.py index 38c56e7744..650f6a8e12 100644 --- a/tinygrad/runtime/ops_python.py +++ b/tinygrad/runtime/ops_python.py @@ -2,9 +2,8 @@ # a python uops emulator # works to test the tensor cores, and all the uops in general # this is the (living) definition of uops -import sys from typing import Optional, Any, TYPE_CHECKING -import pickle, base64, itertools, time, struct +import pickle, base64, itertools, time, struct, sys from tinygrad.dtype import DType, dtypes, ImageDType, PtrDType, truncate from tinygrad.helpers import all_same, getenv, flatten, get_single_element from tinygrad.device import Compiled, Compiler, Allocator