Enable dict
inputs for torch.autograd.grad
and torch.autograd.backward
(usability for torch.func.functional_call
)
#126650
Labels
module: autograd
Related to torch.autograd, and the autograd engine in general
module: functorch
Pertaining to torch.func or pytorch/functorch
triaged
This issue has been looked at a team member, and triaged and prioritized into an appropriate module
馃殌 The feature, motivation and pitch
functorch
is deprecated in favor oftorch.func
in PyTorch 2.0. The APIfunctorch.make_functional
is replaced bytorch.func.functional_call
.The
torch.func.functional_call()
API takesdict[str, Tensor]
inputs for parameters and buffers, whiletorch.autograd.{grad,backward}
only supports tensor or tuple of tensors (Tensor | tuple[Tensor, ...]
) as input. Users need to do manual conversion betweentuple
anddict
. That is very inconvenient.This issue requests to support
dict[str, Tensor]
as inputs intorch.autograd.grad
andtorch.autograd.backward
.Code snippet for example case.
With
fmodel, params = functorch.make_functional(model)
,params
istuple[nn.Parameter, ...]
:With
torch.func.functional_call(model, params)
,params
isdict[str, nn.Parameter]
:Alternatives
No response
Additional context
No response
cc @ezyang @albanD @gqchen @pearu @nikitaved @soulitzer @lezcano @Varal7 @zou3519 @Chillee @samdow @kshitij12345 @janeyx99
The text was updated successfully, but these errors were encountered: