Rate this Page

torch.__future__#

Created On: Feb 05, 2024 | Last Updated On: Jun 12, 2025

torch.__future__.set_overwrite_module_params_on_conversion(value)[source]#

Sets whether to assign new tensors to the parameters instead of changing theexisting parameters in-place when converting annn.Module.

When enabled, the following methods will assign new parameters to the module:

  1. module.{device}() (e.g.nn.Module.cuda()) for moving a module between devices

  2. module.{dtype}() (e.g.nn.Module.float()) for converting a module to a different dtype

  3. nn.Module.to()

  4. nn.Module.to_empty()

Parameters:

value (bool) – Whether to assign new tensors or not.

torch.__future__.get_overwrite_module_params_on_conversion()[source]#

Returns whether to assign new tensors to the parameters instead of changing theexisting parameters in-place when converting antorch.nn.Module. Defaults toFalse.

Seeset_overwrite_module_params_on_conversion() for more information.

Return type:

bool

torch.__future__.set_swap_module_params_on_conversion(value)[source]#

Sets whether to useswap_tensors() instead of setting.data tochange the existing parameters in-place when converting annn.Module and insteadofparam.copy_(state_dict[key]) when loading a state dict into annn.Module.

Note

This function takes precedence overget_overwrite_module_params_on_conversion()

When enabled, the following methods will swap the existing parameters in-place:

  1. module.{device}() (e.g.nn.Module.cuda()) for moving a module between devices

  2. module.{dtype}() (e.g.nn.Module.float()) for converting a module to a different dtype

  3. nn.Module.to()

  4. nn.Module.to_empty()

  5. nn.Module.load_state_dict()

The semantics forload_state_dict() when this is set are as follows:

  1. For each parameter/buffer, its correspondingstate_dict['key'] is transformed viamodule_load() (i.e.res=param.module_load(state_dict['key']))

  2. If necessary,res will be wrapped in anParameter

  3. The parameter/buffer in the module will be swapped viaswap_tensors()withres

Parameters:

value (bool) – Whether to useswap_tensors() or not.

torch.__future__.get_swap_module_params_on_conversion()[source]#

Returns whether to useswap_tensors() instead of setting .data tochange the existing parameters in-place when converting annn.Module. Defaults toFalse.

Seeset_swap_module_params_on_conversion() for more information.

Return type:

bool