move gradient.py to mixin/ [PR] (#16583)

This commit is contained in:
chenyu 2026-06-11 23:58:21 -04:00 committed by GitHub
commit 762f50bd52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 3 additions and 3 deletions

View file

@ -126,8 +126,8 @@ do_not_mutate = [
"tinygrad/viz/*",
"tinygrad/device.py",
"tinygrad/dtype.py",
"tinygrad/gradient.py",
"tinygrad/helpers.py",
"tinygrad/mixin/gradient.py",
"tinygrad/tensor.py",
]
tests_dir = ["test/test_tiny.py", "test/backend/test_ops.py"]

View file

@ -4,7 +4,7 @@ import torch
from tinygrad import Tensor
from tinygrad.dtype import dtypes
from tinygrad.uop.ops import UOp
from tinygrad.gradient import compute_gradient
from tinygrad.mixin.gradient import compute_gradient
class TestGradient(unittest.TestCase):
def _cmp_nan_okay(self, x, y):

View file

@ -460,7 +460,7 @@ class OpMixin(ElementwiseMixin, ReduceMixin):
"""
assert gradient is not None or self.shape == tuple(), "when no gradient is provided, backward must be called on a scalar tensor"
if not (self.is_floating_point() and all(t.is_floating_point() for t in targets)): raise RuntimeError("only float Tensors have gradient")
from tinygrad.gradient import compute_gradient
from tinygrad.mixin.gradient import compute_gradient
if gradient is None: gradient = self.const_like(1.0)
target_uops = [t._uop for t in targets]
grads = compute_gradient(self._uop, gradient._uop, set(target_uops))