Shortcuts

Class TransformerEncoderImpl

Inheritance Relationships

Base Type

Class Documentation

class TransformerEncoderImpl : public torch::nn::Cloneable<TransformerEncoderImpl>

TransformerEncoder module.

See https://pytorch.org/docs/main/generated/torch.nn.TransformerEncoder.html to learn abouut the exact behavior of this encoder layer module.

See the documentation for torch::nn::TransformerEncoder class to learn what constructor arguments are supported for this encoder module.

Example:

TransformerEncoderLayer encoderLayer(TransformerEncoderLayerOptions(512,
8).dropout(0.1)); TransformerEncoder
encoder(TransformerEncoderOptions(encoderLayer,
6).norm(LayerNorm(LayerNormOptions({2}))));

Public Functions

inline TransformerEncoderImpl(TransformerEncoderLayer encoder_layer, int64_t num_layers)
explicit TransformerEncoderImpl(TransformerEncoderOptions options_)
Tensor forward(const Tensor &src, const Tensor &src_mask = {}, const Tensor &src_key_padding_mask = {})
virtual void reset() override

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

void reset_parameters()

Public Members

TransformerEncoderOptions options

options with which this TransformerEncoder was constructed

ModuleList layers = nullptr

module list that contains all the encoder layers

AnyModule norm

optional normalization module

Protected Functions

inline virtual bool _forward_has_default_args() override

The following three functions allow a module with default arguments in its forward method to be used in a Sequential module.

You should NEVER override these functions manually. Instead, you should use the FORWARD_HAS_DEFAULT_ARGS macro.

inline virtual unsigned int _forward_num_required_args() override
inline std::vector<torch::nn::AnyValue> _forward_populate_default_args(std::vector<torch::nn::AnyValue> &&arguments) override

Friends

friend struct torch::nn::AnyModuleHolder

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