This commit is contained in:
2023-03-11 11:41:34 -08:00
parent 3f08613a2a
commit d41ac5f5f1
3 changed files with 7 additions and 4 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ numpy_fxn_for_op: Dict[Op, Callable] = {**base_fxn_for_op, **{
UnaryOps.NOOP: np.ascontiguousarray, UnaryOps.EXP: np.exp, UnaryOps.LOG: np.log,
BinaryOps.MAX: np.maximum, BinaryOps.CMPEQ: lambda x,y: (x==y).astype(np.float32),
MovementOps.PERMUTE: lambda x, order: x.transpose(order), MovementOps.PAD: np.pad, MovementOps.EXPAND: np.broadcast_to,
MovementOps.STRIDE: lambda x, arg: x.__getitem__(tuple(slice(None, None, i) for i in arg)),
MovementOps.STRIDE: lambda x, arg: x[tuple(slice(None, None, i) for i in arg)],
FusedOps.MULACC: einsum_mulacc(lambda s,a,b: np.einsum(s, a.copy(), b.copy()), lambda x: x.strides, np.broadcast_to),
}}
+1 -1
View File
@@ -9,7 +9,7 @@ torch_fxn_for_op: Dict[Op, Callable] = {**base_fxn_for_op, **{
BinaryOps.MAX: torch.maximum, BinaryOps.CMPEQ: lambda x,y: (x==y).float(),
MovementOps.PAD: lambda x, padding: torch.nn.functional.pad(x, [item for sublist in padding[::-1] for item in sublist]),
FusedOps.MULACC: einsum_mulacc(lambda s,a,b: torch.einsum(s, a.float(), b.float()).type(a.dtype), lambda x: x.stride(), lambda x,s: x.expand(s)),
MovementOps.STRIDE: lambda x, arg: x.__getitem__(tuple(slice(None, None, abs(i)) for i in arg)).flip([i for i,a in enumerate(arg) if a < 0])
MovementOps.STRIDE: lambda x, arg: x[tuple(slice(None, None, abs(i)) for i in arg)].flip([i for i,a in enumerate(arg) if a < 0])
}}
device = torch.device("cuda:0" if torch.cuda.is_available() else ("mps" if getenv("MPS", 0) else "cpu"))
+5 -2
View File
@@ -63,6 +63,9 @@ class Tensor:
def __repr__(self):
return f"<Tensor {self.lazydata if self.lazydata.realized is None else self.lazydata.realized!r} with grad {(self.grad.lazydata if self.grad else None)!r}>"
# Python has a non moving GC, so this should be okay
def __hash__(self): return id(self)
@property
def shape(self) -> Tuple[int, ...]: return self.lazydata.shape
@@ -424,8 +427,8 @@ class Tensor:
def __le__(self, x) -> Tensor: return self.maximum(x).eq(x)
def __lt__(self, x) -> Tensor: return 1.0-(self>=x)
def __gt__(self, x) -> Tensor: return 1.0-(self<=x)
def __eq__(self, x) -> Tensor: return self.eq(x) # type: ignore
def __hash__(self): return id(self)
def __eq__(self, x) -> Tensor: return self.eq(x) # type: ignore # mypy things this should be a bool
# ***** functional nn ops *****
def linear(self, weight:Tensor, bias:Optional[Tensor]=None):