MCPcopy Create free account
hub / github.com/modelscope/modelscope / Seq2SeqModelOutput

Class Seq2SeqModelOutput

modelscope/outputs/nlp_outputs.py:71–151  ·  view source on GitHub ↗

Base class for model encoder's outputs that also contains : pre-computed hidden states that can speed up sequential decoding. Args: last_hidden_state (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`): Sequence of hidden-states at th

Source from the content-addressed store, hash-verified

69
70@dataclass
71class Seq2SeqModelOutput(ModelOutputBase):
72 """
73 Base class for model encoder's outputs that also contains : pre-computed
74 hidden states that can speed up sequential decoding.
75
76 Args:
77 last_hidden_state (`torch.FloatTensor` of shape `(batch_size,
78 sequence_length, hidden_size)`):
79 Sequence of hidden-states at the output of the last layer of the
80 decoder of the model.
81
82 If `past_key_values` is used only the last hidden-state of the
83 sequences of shape `(batch_size, 1, hidden_size)` is output.
84 past_key_values (`tuple(tuple(torch.FloatTensor))`, *optional*, returned
85 when `use_cache=True` is passed or when `config.use_cache=True`):
86 Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`,
87 with each tuple having 2 tensors of shape `(batch_size, num_heads,
88 sequence_length, embed_size_per_head)`) and 2 additional tensors of
89 shape `(batch_size, num_heads, encoder_sequence_length,
90 embed_size_per_head)`.
91
92 Contains pre-computed hidden-states (key and values in the
93 self-attention blocks and in the cross-attention blocks) that can be
94 used (see `past_key_values` input) to speed up sequential decoding.
95 decoder_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned
96 when `output_hidden_states=True` is passed or when
97 `config.output_hidden_states=True`):
98 Tuple of `torch.FloatTensor` (one for the output of the embeddings,
99 if the model has an embedding layer, + one for the output of each
100 layer) of shape `(batch_size, sequence_length, hidden_size)`.
101
102 Hidden-states of the decoder at the output of each layer plus the
103 optional initial embedding outputs.
104 decoder_attentions (`tuple(torch.FloatTensor)`, *optional*, returned
105 when `output_attentions=True` is passed or when
106 `config.output_attentions=True`):
107 Tuple of `torch.FloatTensor` (one for each layer) of shape
108 `(batch_size, num_heads, sequence_length, sequence_length)`.
109
110 Attentions weights of the decoder, after the attention softmax, used
111 to compute the weighted average in the self-attention heads.
112 cross_attentions (`tuple(torch.FloatTensor)`, *optional*, returned when
113 `output_attentions=True` is passed or when
114 `config.output_attentions=True`):
115 Tuple of `torch.FloatTensor` (one for each layer) of shape
116 `(batch_size, num_heads, sequence_length, sequence_length)`.
117
118 Attentions weights of the decoder's cross-attention layer, after the
119 attention softmax, used to compute the weighted average in the
120 cross-attention heads.
121 encoder_last_hidden_state (`torch.FloatTensor` of shape `(batch_size,
122 sequence_length, hidden_size)`, *optional*):
123 Sequence of hidden-states at the output of the last layer of the
124 encoder of the model.
125 encoder_hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned
126 when `output_hidden_states=True` is passed or when
127 `config.output_hidden_states=True`):
128 Tuple of `torch.FloatTensor` (one for the output of the embeddings,

Callers 1

forwardMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…