diff --git a/examples/stable_diffusion.py b/examples/stable_diffusion.py index 3389259ac5..9a30c5a76c 100644 --- a/examples/stable_diffusion.py +++ b/examples/stable_diffusion.py @@ -529,7 +529,7 @@ def bytes_to_unicode(): cs = [chr(n) for n in cs] return dict(zip(bs, cs)) -class ClipTokenizer(object): +class ClipTokenizer: def __init__(self, bpe_path: str = default_bpe()): self.byte_encoder = bytes_to_unicode() merges = gzip.open(bpe_path).read().decode("utf-8").split('\n') diff --git a/tinygrad/shapetracker.py b/tinygrad/shapetracker.py index 01a13c320c..18dc4576bb 100644 --- a/tinygrad/shapetracker.py +++ b/tinygrad/shapetracker.py @@ -64,7 +64,7 @@ def strides_for_shape(shape:Tuple[int, ...]) -> Tuple[int, ...]: @functools.lru_cache(maxsize=None) def view_from_shape(shape:Tuple[int, ...]) -> View: - assert all([isinstance(x, int) for x in shape]) and len(shape) != 0 + assert all(isinstance(x, int) for x in shape) and len(shape) != 0 return View(tuple(shape), strides_for_shape(shape)) class ShapeTracker: @@ -100,7 +100,7 @@ class ShapeTracker: self.views.append(view) def reshape(self, *new_shape): - assert all([isinstance(x, int) for x in new_shape]) + assert all(isinstance(x, int) for x in new_shape) assert prod(self.shape) == prod(new_shape), f"can't reshape {self.shape} -> {new_shape}" # check if this is adding or removing 1s (only) @@ -117,7 +117,7 @@ class ShapeTracker: self.views.append(view) def permute(self, *axis): - assert all([isinstance(x, int) and x >= 0 and x < len(self.shape) for x in axis]) + assert all(isinstance(x, int) and x >= 0 and x < len(self.shape) for x in axis) assert len(set(axis)) == len(axis) and len(axis) == len(self.shape), f"can't permute {self.shape} with {axis}" self.views[-1] = View([self.shape[a] for a in axis], [self.strides[a] for a in axis], self.offset) @@ -143,14 +143,14 @@ class ShapeTracker: self.views += [zeroview, View(self.shape, strides_for_shape(self.shape))] def expand(self, *new_shape): - assert all([isinstance(x, int) for x in new_shape]) - assert all([x == y or x == 1 for x,y in zip(self.shape, new_shape)]), f"can't expand {self.shape} into {new_shape}" + assert all(isinstance(x, int) for x in new_shape) + assert all(x == y or x == 1 for x,y in zip(self.shape, new_shape)), f"can't expand {self.shape} into {new_shape}" strides = [s if x == y else 0 for s,(x,y) in zip(self.strides, zip(self.shape, new_shape))] self.views[-1] = View(new_shape, strides, self.offset) # TODO: combine with slice? this doesn't require a ZeroView, though slice shouldn't always either def stride(self, *mul): - assert all([isinstance(x, int) for x in mul]) + assert all(isinstance(x, int) for x in mul) strides = [z*m for z,m in zip(self.strides, mul)] new_shape = [(s+(abs(m)-1))//abs(m) for s,m in zip(self.shape, mul)] offset = sum([(s-1)*z for s,z,m in zip(self.shape, self.strides, mul) if m < 0]) diff --git a/tinygrad/tensor.py b/tinygrad/tensor.py index 82e6ecf4f3..447de56d05 100644 --- a/tinygrad/tensor.py +++ b/tinygrad/tensor.py @@ -321,7 +321,7 @@ class Function: def __init__(self, device:str, *tensors:Tensor): self.device, self.parents = device, tensors self.needs_input_grad = [t.requires_grad for t in self.parents] - self.requires_grad = True if any(self.needs_input_grad) else (None if any([x is None for x in self.needs_input_grad]) else False) + self.requires_grad = True if any(self.needs_input_grad) else (None if any(x is None for x in self.needs_input_grad) else False) self.saved_tensors : List[Tensor] = [] def forward(self, *args, **kwargs): raise NotImplementedError(f"forward not implemented for {type(self)}") @@ -356,4 +356,4 @@ def register_op(name, fxn): setattr(Tensor, f"__i{name}__", lambda self,x: self.assign(fxn(self,x))) setattr(Tensor, f"__r{name}__", lambda self,x: fxn(x,self)) for name in ['add', 'sub', 'mul', 'pow', 'matmul', 'truediv']: - register_op(name, getattr(Tensor, name if name != 'truediv' else 'div')) \ No newline at end of file + register_op(name, getattr(Tensor, name if name != 'truediv' else 'div'))