Shortcuts

Template Class Cloneable

Inheritance Relationships

Base Type

Derived Types

Class Documentation

template<typename Derived>
class Cloneable : public torch::nn::Module

The clone() method in the base Module class does not have knowledge of the concrete runtime type of its subclasses.

Therefore, clone() must either be called from within the subclass, or from a base class that has knowledge of the concrete type. Cloneable uses the CRTP to gain knowledge of the subclass’ static type and provide an implementation of the clone() method. We do not want to use this pattern in the base class, because then storing a module would always require templatizing it.

Subclassed by torch::nn::AdaptiveAvgPoolImpl< 1, ExpandingArray< 1 >, AdaptiveAvgPool1dImpl >, torch::nn::AdaptiveAvgPoolImpl< 3, ExpandingArrayWithOptionalElem< 3 >, AdaptiveAvgPool3dImpl >, torch::nn::AdaptiveAvgPoolImpl< 2, ExpandingArrayWithOptionalElem< 2 >, AdaptiveAvgPool2dImpl >, torch::nn::AdaptiveMaxPoolImpl< 1, ExpandingArray< 1 >, AdaptiveMaxPool1dImpl >, torch::nn::AdaptiveMaxPoolImpl< 2, ExpandingArrayWithOptionalElem< 2 >, AdaptiveMaxPool2dImpl >, torch::nn::AdaptiveMaxPoolImpl< 3, ExpandingArrayWithOptionalElem< 3 >, AdaptiveMaxPool3dImpl >, torch::nn::AvgPoolImpl< 2, AvgPool2dImpl >, torch::nn::AvgPoolImpl< 3, AvgPool3dImpl >, torch::nn::AvgPoolImpl< 1, AvgPool1dImpl >, torch::nn::ConstantPadImpl< 1, ConstantPad1dImpl >, torch::nn::ConstantPadImpl< 2, ConstantPad2dImpl >, torch::nn::ConstantPadImpl< 3, ConstantPad3dImpl >, torch::nn::ConvNdImpl< 1, Conv1dImpl >, torch::nn::ConvNdImpl< 3, Conv3dImpl >, torch::nn::ConvNdImpl< 2, Conv2dImpl >, torch::nn::LPPoolImpl< 3, LPPool3dImpl >, torch::nn::LPPoolImpl< 2, LPPool2dImpl >, torch::nn::LPPoolImpl< 1, LPPool1dImpl >, torch::nn::MaxPoolImpl< 1, MaxPool1dImpl >, torch::nn::MaxPoolImpl< 2, MaxPool2dImpl >, torch::nn::MaxPoolImpl< 3, MaxPool3dImpl >, torch::nn::MaxUnpoolImpl< 1, MaxUnpool1dImpl >, torch::nn::MaxUnpoolImpl< 2, MaxUnpool2dImpl >, torch::nn::MaxUnpoolImpl< 3, MaxUnpool3dImpl >, torch::nn::NormImplBase< D, Derived, BatchNormOptions >, torch::nn::NormImplBase< D, Derived, InstanceNormOptions >, torch::nn::ReflectionPadImpl< 3, ReflectionPad3dImpl >, torch::nn::ReflectionPadImpl< 2, ReflectionPad2dImpl >, torch::nn::ReflectionPadImpl< 1, ReflectionPad1dImpl >, torch::nn::ReplicationPadImpl< 3, ReplicationPad3dImpl >, torch::nn::ReplicationPadImpl< 2, ReplicationPad2dImpl >, torch::nn::ReplicationPadImpl< 1, ReplicationPad1dImpl >, torch::nn::ZeroPadImpl< 1, ZeroPad1dImpl >, torch::nn::ZeroPadImpl< 2, ZeroPad2dImpl >, torch::nn::ZeroPadImpl< 3, ZeroPad3dImpl >, torch::nn::detail::RNNCellImplBase< GRUCellImpl >, torch::nn::detail::RNNCellImplBase< LSTMCellImpl >, torch::nn::detail::RNNCellImplBase< RNNCellImpl >, torch::nn::detail::RNNImplBase< RNNImpl >, torch::nn::detail::RNNImplBase< LSTMImpl >, torch::nn::detail::RNNImplBase< GRUImpl >, torch::nn::detail::_DropoutNd< AlphaDropoutImpl >, torch::nn::detail::_DropoutNd< FeatureAlphaDropoutImpl >, torch::nn::detail::_DropoutNd< DropoutImpl >, torch::nn::detail::_DropoutNd< Dropout3dImpl >, torch::nn::detail::_DropoutNd< Dropout2dImpl >, torch::nn::AdaptiveAvgPoolImpl< D, output_size_t, Derived >, torch::nn::AdaptiveMaxPoolImpl< D, output_size_t, Derived >, torch::nn::AvgPoolImpl< D, Derived >, torch::nn::ConstantPadImpl< D, Derived >, torch::nn::ConvNdImpl< D, Derived >, torch::nn::LPPoolImpl< D, Derived >, torch::nn::MaxPoolImpl< D, Derived >, torch::nn::MaxUnpoolImpl< D, Derived >, torch::nn::NormImplBase< D, Derived, DerivedOptions >, torch::nn::ReflectionPadImpl< D, Derived >, torch::nn::ReplicationPadImpl< D, Derived >, torch::nn::ZeroPadImpl< D, Derived >, torch::nn::detail::RNNCellImplBase< Derived >, torch::nn::detail::RNNImplBase< Derived >, torch::nn::detail::_DropoutNd< Derived >

Public Functions

virtual void reset() = 0

reset() must perform initialization of all members with reference semantics, most importantly parameters, buffers and submodules.

inline virtual std::shared_ptr<Module> clone(const std::optional<Device> &device = nullopt) const override

Performs a recursive “deep copy” of the Module, such that all parameters and submodules in the cloned module are different from those in the original module.

explicit Module(std::string name)

Tells the base Module about the name of the submodule.

Module()

Constructs the module without immediate knowledge of the submodule’s name.

The name of the submodule is inferred via RTTI (if possible) the first time .name() is invoked.

Module(const Module&) = default
Module(Module&&) noexcept = default

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources