Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanYashchuk committed Nov 27, 2024
1 parent 073d34e commit 3ac12fb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions thunder/tests/test_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,21 @@ def test_vjp_correctness_zeta_manual(op, device, dtype, executor, comp):
comp(grad_rhs, expected_grad[0], equal_nan=True)


@ops((get_opinfo("item"),), supported_dtypes=(dtypes.float64,))
def test_vjp_correctness_torch_item_manual(op, device, dtype, executor, comp):
from thunder.torch import item

for sample in op.sample_inputs(device, dtype, requires_grad=True, no_rhs_numbers=True):
out = op.torch_reference(*sample.args, **sample.kwargs)
flat_op, flat_args, spec = flatten_func(item, sample.args, sample.kwargs)
initial_trace = thunder.trace()(vjp(flat_op), flat_args, (None,))
actual_out, (grad_in,) = executor.make_callable(
initial_trace.python_callable(), disable_torch_autograd=True
)(flat_args, (None,))
assert grad_in is None, "grad_in should be None"
comp(actual_out, out, equal_nan=True)


@ops((get_opinfo("nll_loss"),), supported_dtypes=(dtypes.float64,))
def test_vjp_correctness_nll_loss_manual(op, device, dtype, executor, comp):
for sample in op.sample_inputs(device, dtype, requires_grad=True, no_rhs_numbers=True):
Expand Down

0 comments on commit 3ac12fb

Please sign in to comment.