On this page
torch.nn.utils.stateless.functional_call
torch.nn.utils.stateless.functional_call(module, parameters_and_buffers, args, kwargs=None)
[source]-
Performs a functional call on the module by replacing the module parameters and buffers with the provided ones.
Note
If the module has active parametrizations, passing a value in the
parameters_and_buffers
argument with the name set to the regular parameter name will completely disable the parametrization. If you want to apply the parametrization function to the value passed please set the key as{submodule_name}.parametrizations.{parameter_name}.original
.Note
If the module performs in-place operations on parameters/buffers, these will be reflected in the
parameters_and_buffers
input.Example:
>>> a = {'foo': torch.zeros(())} >>> mod = Foo() # does self.foo = self.foo + 1 >>> print(mod.foo) # tensor(0.) >>> functional_call(mod, a, torch.ones(())) >>> print(mod.foo) # tensor(0.) >>> print(a['foo']) # tensor(1.)
- Parameters:
-
- module (torch.nn.Module) – the module to call
- parameters_and_buffers (dict of str and Tensor) – the parameters that will be used in the module call.
- args (tuple) – arguments to be passed to the module call
- kwargs (dict) – keyword arguments to be passed to the module call
- Returns:
-
the result of calling
module
. - Return type:
-
Any
© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/1.13/generated/torch.nn.utils.stateless.functional_call.html