Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions test/cpp/api/transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,26 +442,20 @@ TEST_F(TransformerTest, TransformerDecoderLayer_gelu_CUDA) {
TEST_F(TransformerTest, PrettyPrintTransformerDecoderLayer) {
ASSERT_EQ(
c10::str(TransformerDecoderLayer(4, 2)),
"(\n"
"torch::nn::TransformerDecoderLayerImpl(\n"
" (self_attn): torch::nn::MultiheadAttention(\n"
" (out_proj): torch::nn::Linear("
"in_features=4, out_features=4, bias=true)\n"
" (out_proj): torch::nn::Linear(in_features=4, out_features=4, bias=true)\n"
" )\n"
" (dropout1): torch::nn::Dropout(p=0.1, inplace=false)\n"
" (norm1): torch::nn::LayerNorm([4], eps=1e-05,"
" elementwise_affine=true)\n"
" (norm1): torch::nn::LayerNorm([4], eps=1e-05, elementwise_affine=true)\n"
" (multihead_attn): torch::nn::MultiheadAttention(\n"
" (out_proj): torch::nn::Linear("
"in_features=4, out_features=4, bias=true)\n"
" (out_proj): torch::nn::Linear(in_features=4, out_features=4, bias=true)\n"
" )\n"
" (dropout2): torch::nn::Dropout(p=0.1, inplace=false)\n"
" (norm2): torch::nn::LayerNorm([4], eps=1e-05, "
"elementwise_affine=true)\n"
" (linear1): torch::nn::Linear("
"in_features=4, out_features=2048, bias=true)\n"
" (norm2): torch::nn::LayerNorm([4], eps=1e-05, elementwise_affine=true)\n"
" (linear1): torch::nn::Linear(in_features=4, out_features=2048, bias=true)\n"
" (dropout): torch::nn::Dropout(p=0.1, inplace=false)\n"
" (linear2): torch::nn::Linear("
"in_features=2048, out_features=4, bias=true)\n"
" (linear2): torch::nn::Linear(in_features=2048, out_features=4, bias=true)\n"
" (dropout3): torch::nn::Dropout(p=0.1, inplace=false)\n"
" (norm3): torch::nn::LayerNorm([4], eps=1e-05, elementwise_affine=true)\n"
")");
Expand Down
3 changes: 0 additions & 3 deletions torch/csrc/api/include/torch/nn/modules/transformerlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ class TORCH_API TransformerDecoderLayerImpl : public Cloneable<TransformerDecode

void reset_parameters();

/// Pretty prints the `TransformerDecoderLayer` module into the given `stream`.
void pretty_print(std::ostream& stream) const override;

/// Pass the inputs (and mask) through the decoder layer.
///Args:
/// tgt: the sequence to the decoder layer (required).
Expand Down
22 changes: 0 additions & 22 deletions torch/csrc/api/src/nn/modules/transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,28 +153,6 @@ void TransformerDecoderLayerImpl::reset_parameters() {
norm3->reset_parameters();
}

// By default contained sub-modules are printed.
// TODO: The pretty print needs to be implemented along with python
// implementation, currently using the default print.
void TransformerDecoderLayerImpl::pretty_print(std::ostream& stream) const {
// stream << "(d_model=" << options.d_model()
// << ", nhead=" << options.nhead()
// << ", dim_feedforward=" << options.dim_feedforward()
// << ", dropout=" << options.dropout()
// << ", self_attn=torch::nn::MultiheadAttention()"
// << ", dropout1=torch::nn::Dropout()"
// << ", norm1=torch::nn::LayerNorm()"
// << ", multihead_attn=torch::nn::MultiheadAttention()"
// << ", dropout2=torch::nn::Dropout()"
// << ", norm2=torch::nn::LayerNorm()"
// << ", linear1=torch::nn::Linear()"
// << ", dropout=torch::nn::Dropout()"
// << ", linear2=torch::nn::Linear()"
// << ", dropout3=torch::nn::Dropout()"
// << ", norm3=torch::nn::LayerNorm()"
// << ")";
}

///Pass the inputs (and mask) through the decoder layer.
Tensor TransformerDecoderLayerImpl::forward(Tensor tgt, const Tensor& memory,
const Tensor& tgt_mask,
Expand Down