Skip to content

Commit 372bc1b

Browse files
committed
Add tinygrad submodule and remove unnecessary type ignores
Introduce tinygrad as a submodule for streamlined integration. Clean up code by removing redundant type ignore comments, enhancing code readability and maintainability.
1 parent 9cc8ed1 commit 372bc1b

File tree

12 files changed

+142
-25
lines changed

12 files changed

+142
-25
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "tinygrad_"]
2+
path = tinygrad_
3+
url = https://github.com/tinygrad/tinygrad

omdev/scripts/ci.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,15 @@ def _unpack_isinstance_spec(self, spec: ta.Any) -> tuple:
656656
spec = (object,)
657657
return spec
658658

659-
def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> T: # noqa
659+
@ta.overload
660+
def isinstance(self, v: ta.Any, spec: ta.Type[T], msg: CheckMessage = None) -> T:
661+
...
662+
663+
@ta.overload
664+
def isinstance(self, v: ta.Any, spec: ta.Any, msg: CheckMessage = None) -> ta.Any:
665+
...
666+
667+
def isinstance(self, v, spec, msg=None):
660668
if not isinstance(v, self._unpack_isinstance_spec(spec)):
661669
self._raise(
662670
TypeError,
@@ -668,7 +676,15 @@ def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMes
668676

669677
return v
670678

671-
def of_isinstance(self, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
679+
@ta.overload
680+
def of_isinstance(self, spec: ta.Type[T], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
681+
...
682+
683+
@ta.overload
684+
def of_isinstance(self, spec: ta.Any, msg: CheckMessage = None) -> ta.Callable[[ta.Any], ta.Any]:
685+
...
686+
687+
def of_isinstance(self, spec, msg=None):
672688
def inner(v):
673689
return self.isinstance(v, self._unpack_isinstance_spec(spec), msg)
674690

omdev/scripts/interp.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,15 @@ def _unpack_isinstance_spec(self, spec: ta.Any) -> tuple:
692692
spec = (object,)
693693
return spec
694694

695-
def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> T: # noqa
695+
@ta.overload
696+
def isinstance(self, v: ta.Any, spec: ta.Type[T], msg: CheckMessage = None) -> T:
697+
...
698+
699+
@ta.overload
700+
def isinstance(self, v: ta.Any, spec: ta.Any, msg: CheckMessage = None) -> ta.Any:
701+
...
702+
703+
def isinstance(self, v, spec, msg=None):
696704
if not isinstance(v, self._unpack_isinstance_spec(spec)):
697705
self._raise(
698706
TypeError,
@@ -704,7 +712,15 @@ def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMes
704712

705713
return v
706714

707-
def of_isinstance(self, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
715+
@ta.overload
716+
def of_isinstance(self, spec: ta.Type[T], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
717+
...
718+
719+
@ta.overload
720+
def of_isinstance(self, spec: ta.Any, msg: CheckMessage = None) -> ta.Callable[[ta.Any], ta.Any]:
721+
...
722+
723+
def of_isinstance(self, spec, msg=None):
708724
def inner(v):
709725
return self.isinstance(v, self._unpack_isinstance_spec(spec), msg)
710726

omdev/scripts/pyproject.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,15 @@ def _unpack_isinstance_spec(self, spec: ta.Any) -> tuple:
19931993
spec = (object,)
19941994
return spec
19951995

1996-
def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> T: # noqa
1996+
@ta.overload
1997+
def isinstance(self, v: ta.Any, spec: ta.Type[T], msg: CheckMessage = None) -> T:
1998+
...
1999+
2000+
@ta.overload
2001+
def isinstance(self, v: ta.Any, spec: ta.Any, msg: CheckMessage = None) -> ta.Any:
2002+
...
2003+
2004+
def isinstance(self, v, spec, msg=None):
19972005
if not isinstance(v, self._unpack_isinstance_spec(spec)):
19982006
self._raise(
19992007
TypeError,
@@ -2005,7 +2013,15 @@ def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMes
20052013

20062014
return v
20072015

2008-
def of_isinstance(self, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
2016+
@ta.overload
2017+
def of_isinstance(self, spec: ta.Type[T], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
2018+
...
2019+
2020+
@ta.overload
2021+
def of_isinstance(self, spec: ta.Any, msg: CheckMessage = None) -> ta.Callable[[ta.Any], ta.Any]:
2022+
...
2023+
2024+
def of_isinstance(self, spec, msg=None):
20092025
def inner(v):
20102026
return self.isinstance(v, self._unpack_isinstance_spec(spec), msg)
20112027

ominfra/scripts/journald2aws.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,15 @@ def _unpack_isinstance_spec(self, spec: ta.Any) -> tuple:
12681268
spec = (object,)
12691269
return spec
12701270

1271-
def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> T: # noqa
1271+
@ta.overload
1272+
def isinstance(self, v: ta.Any, spec: ta.Type[T], msg: CheckMessage = None) -> T:
1273+
...
1274+
1275+
@ta.overload
1276+
def isinstance(self, v: ta.Any, spec: ta.Any, msg: CheckMessage = None) -> ta.Any:
1277+
...
1278+
1279+
def isinstance(self, v, spec, msg=None):
12721280
if not isinstance(v, self._unpack_isinstance_spec(spec)):
12731281
self._raise(
12741282
TypeError,
@@ -1280,7 +1288,15 @@ def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMes
12801288

12811289
return v
12821290

1283-
def of_isinstance(self, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
1291+
@ta.overload
1292+
def of_isinstance(self, spec: ta.Type[T], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
1293+
...
1294+
1295+
@ta.overload
1296+
def of_isinstance(self, spec: ta.Any, msg: CheckMessage = None) -> ta.Callable[[ta.Any], ta.Any]:
1297+
...
1298+
1299+
def of_isinstance(self, spec, msg=None):
12841300
def inner(v):
12851301
return self.isinstance(v, self._unpack_isinstance_spec(spec), msg)
12861302

ominfra/scripts/manage.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,7 +2507,15 @@ def _unpack_isinstance_spec(self, spec: ta.Any) -> tuple:
25072507
spec = (object,)
25082508
return spec
25092509

2510-
def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> T: # noqa
2510+
@ta.overload
2511+
def isinstance(self, v: ta.Any, spec: ta.Type[T], msg: CheckMessage = None) -> T:
2512+
...
2513+
2514+
@ta.overload
2515+
def isinstance(self, v: ta.Any, spec: ta.Any, msg: CheckMessage = None) -> ta.Any:
2516+
...
2517+
2518+
def isinstance(self, v, spec, msg=None):
25112519
if not isinstance(v, self._unpack_isinstance_spec(spec)):
25122520
self._raise(
25132521
TypeError,
@@ -2519,7 +2527,15 @@ def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMes
25192527

25202528
return v
25212529

2522-
def of_isinstance(self, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
2530+
@ta.overload
2531+
def of_isinstance(self, spec: ta.Type[T], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
2532+
...
2533+
2534+
@ta.overload
2535+
def of_isinstance(self, spec: ta.Any, msg: CheckMessage = None) -> ta.Callable[[ta.Any], ta.Any]:
2536+
...
2537+
2538+
def of_isinstance(self, spec, msg=None):
25232539
def inner(v):
25242540
return self.isinstance(v, self._unpack_isinstance_spec(spec), msg)
25252541

ominfra/scripts/supervisor.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,15 @@ def _unpack_isinstance_spec(self, spec: ta.Any) -> tuple:
20372037
spec = (object,)
20382038
return spec
20392039

2040-
def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> T: # noqa
2040+
@ta.overload
2041+
def isinstance(self, v: ta.Any, spec: ta.Type[T], msg: CheckMessage = None) -> T:
2042+
...
2043+
2044+
@ta.overload
2045+
def isinstance(self, v: ta.Any, spec: ta.Any, msg: CheckMessage = None) -> ta.Any:
2046+
...
2047+
2048+
def isinstance(self, v, spec, msg=None):
20412049
if not isinstance(v, self._unpack_isinstance_spec(spec)):
20422050
self._raise(
20432051
TypeError,
@@ -2049,7 +2057,15 @@ def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMes
20492057

20502058
return v
20512059

2052-
def of_isinstance(self, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
2060+
@ta.overload
2061+
def of_isinstance(self, spec: ta.Type[T], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
2062+
...
2063+
2064+
@ta.overload
2065+
def of_isinstance(self, spec: ta.Any, msg: CheckMessage = None) -> ta.Callable[[ta.Any], ta.Any]:
2066+
...
2067+
2068+
def of_isinstance(self, spec, msg=None):
20532069
def inner(v):
20542070
return self.isinstance(v, self._unpack_isinstance_spec(spec), msg)
20552071

omlish/asyncs/anyio/streams.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def staple_memory_object_stream(
5454
) -> MemoryStapledObjectStream[T]:
5555
send, receive = args
5656
return MemoryStapledObjectStream(
57-
check.isinstance(send, MemoryObjectSendStream), # type: ignore
58-
check.isinstance(receive, MemoryObjectReceiveStream), # type: ignore
57+
check.isinstance(send, MemoryObjectSendStream),
58+
check.isinstance(receive, MemoryObjectReceiveStream),
5959
)
6060

6161

@@ -64,6 +64,6 @@ def staple_memory_object_stream(
6464
def staple_memory_object_stream2[T](max_buffer_size: float = 0) -> MemoryStapledObjectStream[T]:
6565
send, receive = anyio.create_memory_object_stream[T](max_buffer_size)
6666
return MemoryStapledObjectStream(
67-
check.isinstance(send, MemoryObjectSendStream), # type: ignore
68-
check.isinstance(receive, MemoryObjectReceiveStream), # type: ignore
67+
check.isinstance(send, MemoryObjectSendStream),
68+
check.isinstance(receive, MemoryObjectReceiveStream),
6969
)

omlish/lite/check.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,15 @@ def _unpack_isinstance_spec(self, spec: ta.Any) -> tuple:
143143
spec = (object,)
144144
return spec
145145

146-
def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> T: # noqa
146+
@ta.overload
147+
def isinstance(self, v: ta.Any, spec: ta.Type[T], msg: CheckMessage = None) -> T:
148+
...
149+
150+
@ta.overload
151+
def isinstance(self, v: ta.Any, spec: ta.Any, msg: CheckMessage = None) -> ta.Any:
152+
...
153+
154+
def isinstance(self, v, spec, msg=None):
147155
if not isinstance(v, self._unpack_isinstance_spec(spec)):
148156
self._raise(
149157
TypeError,
@@ -155,7 +163,15 @@ def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMes
155163

156164
return v
157165

158-
def of_isinstance(self, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
166+
@ta.overload
167+
def of_isinstance(self, spec: ta.Type[T], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
168+
...
169+
170+
@ta.overload
171+
def of_isinstance(self, spec: ta.Any, msg: CheckMessage = None) -> ta.Callable[[ta.Any], ta.Any]:
172+
...
173+
174+
def of_isinstance(self, spec, msg=None):
159175
def inner(v):
160176
return self.isinstance(v, self._unpack_isinstance_spec(spec), msg)
161177

ommlx/tinygrad/models/sdxl/clip.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import re
55
import typing as ta
66

7-
from omlish import check
87
from tinygrad import Tensor
98
from tinygrad import dtypes
109
from tinygrad.helpers import fetch
@@ -13,6 +12,8 @@
1312
from tinygrad.nn import LayerNorm
1413
from tinygrad.nn import Linear
1514

15+
from omlish import check
16+
1617

1718
##
1819

@@ -318,7 +319,7 @@ def __call__(self, texts: str | list[str] | Tensor) -> Tensor | tuple[Tensor, ..
318319
texts = [texts]
319320
check.isinstance(texts, (list, tuple), f'expected list of strings, got {type(texts).__name__}')
320321
tokens = Tensor.cat(
321-
*[Tensor(self.tokenizer.encode(text)) for text in texts], dim=0, # type: ignore[union-attr]
322+
*[Tensor(self.tokenizer.encode(text)) for text in texts], dim=0,
322323
)
323324
return self.transformer.text_model(tokens.reshape(len(texts), -1))
324325

@@ -345,7 +346,7 @@ def __call__(self, x: Tensor, attn_mask: Tensor | None = None) -> Tensor:
345346
t, b, c = x.shape
346347

347348
proj = x.linear(self.in_proj_weight.T, self.in_proj_bias)
348-
proj = proj.unflatten(-1, (3, c)).unsqueeze(0).transpose(0, -2) # type: ignore[arg-type]
349+
proj = proj.unflatten(-1, (3, c)).unsqueeze(0).transpose(0, -2)
349350

350351
q, k, v = [
351352
y.reshape(t, b * self.n_heads, self.d_head)
@@ -561,5 +562,5 @@ def __call__(self, texts: str | list[str] | Tensor) -> Tensor | tuple[Tensor, ..
561562
if isinstance(texts, str):
562563
texts = [texts]
563564
check.isinstance(texts, (list, tuple), f'expected list of strings, got {type(texts).__name__}')
564-
tokens = Tensor.cat(*[self.tokenize(text) for text in texts], dim=0) # type: ignore[union-attr]
565+
tokens = Tensor.cat(*[self.tokenize(text) for text in texts], dim=0)
565566
return self.embed_tokens(tokens)

0 commit comments

Comments
 (0)