Loading fairseq/distributed_utils.py +0 −1 Changes for fairseq/distributed_utils.py: 0 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ # the root directory of this source tree. An additional grant of patent rights # can be found in the PATENTS file in the same directory. import math import pickle import torch.distributed Loading fairseq/fp16_trainer.py +0 −2 Changes for fairseq/fp16_trainer.py: 0 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -9,8 +9,6 @@ Train a network on multiple GPUs. """ import math import torch from fairseq import optim Loading fairseq/models/fconv.py +13 −17 Changes for fairseq/models/fconv.py: 13 added lines, 17 removed lines. Original line number Diff line number Diff line Loading @@ -357,6 +357,19 @@ class FConvDecoder(FairseqIncrementalDecoder): return x, avg_attn_scores def reorder_incremental_state(self, incremental_state, new_order): super().reorder_incremental_state(incremental_state, new_order) encoder_out = utils.get_incremental_state(self, incremental_state, 'encoder_out') if encoder_out is not None: encoder_out = tuple(eo.index_select(0, new_order) for eo in encoder_out) utils.set_incremental_state(self, incremental_state, 'encoder_out', encoder_out) def reorder_encoder_out(self, encoder_out_dict, new_order): if encoder_out_dict['encoder_padding_mask'] is not None: encoder_out_dict['encoder_padding_mask'] = \ encoder_out_dict['encoder_padding_mask'].index_select(0, new_order) return encoder_out_dict def max_positions(self): """Maximum output length supported by the decoder.""" return self.embed_positions.max_positions() Loading Loading @@ -401,23 +414,6 @@ class FConvDecoder(FairseqIncrementalDecoder): return x def reorder_incremental_state(self, incremental_state, new_order): super().reorder_incremental_state(incremental_state, new_order) encoder_out = utils.get_incremental_state(self, incremental_state, 'encoder_out') if encoder_out is not None: def update_enc_out(enc_out): return enc_out.index_select(0, new_order) encoder_out = tuple([update_enc_out(eo) for eo in encoder_out]) utils.set_incremental_state(self, incremental_state, 'encoder_out', encoder_out) def reorder_encoder_out(self, encoder_out_dict, new_order): if encoder_out_dict['encoder_padding_mask'] is not None: encoder_out_dict['encoder_padding_mask'] = encoder_out_dict['encoder_padding_mask'].index_select(0, new_order) return encoder_out_dict def Embedding(num_embeddings, embedding_dim, padding_idx): m = nn.Embedding(num_embeddings, embedding_dim, padding_idx=padding_idx) m.weight.data.normal_(0, 0.1) Loading fairseq/models/lstm.py +6 −4 Changes for fairseq/models/lstm.py: 6 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -373,6 +373,7 @@ class LSTMDecoder(FairseqIncrementalDecoder): return x, attn_scores def reorder_incremental_state(self, incremental_state, new_order): super().reorder_incremental_state(incremental_state, new_order) cached_state = utils.get_incremental_state(self, incremental_state, 'cached_state') if cached_state is None: return Loading @@ -382,16 +383,17 @@ class LSTMDecoder(FairseqIncrementalDecoder): return [reorder_state(state_i) for state_i in state] return state.index_select(0, new_order) if not isinstance(new_order, Variable): new_order = Variable(new_order) new_state = tuple(map(reorder_state, cached_state)) utils.set_incremental_state(self, incremental_state, 'cached_state', new_state) def reorder_encoder_out(self, encoder_out_dict, new_order): encoder_out_dict['encoder_out'] = tuple( eo.index_select(1, new_order) for eo in encoder_out_dict['encoder_out']) eo.index_select(1, new_order) for eo in encoder_out_dict['encoder_out'] ) if encoder_out_dict['encoder_padding_mask'] is not None: encoder_out_dict['encoder_padding_mask'] = encoder_out_dict['encoder_padding_mask'].index_select(1, new_order) encoder_out_dict['encoder_padding_mask'] = \ encoder_out_dict['encoder_padding_mask'].index_select(1, new_order) return encoder_out_dict def max_positions(self): Loading fairseq/models/transformer.py +7 −9 Changes for fairseq/models/transformer.py: 7 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ # can be found in the PATENTS file in the same directory. import math import torch import torch.nn as nn import torch.nn.functional as F Loading @@ -15,7 +16,6 @@ from fairseq.modules import ( LearnedPositionalEmbedding, MultiheadAttention, SinusoidalPositionalEmbedding, ) from fairseq import utils from . import ( FairseqIncrementalDecoder, FairseqEncoder, FairseqModel, Loading Loading @@ -220,6 +220,12 @@ class TransformerDecoder(FairseqIncrementalDecoder): return x, attn def reorder_encoder_out(self, encoder_out_dict, new_order): if encoder_out_dict['encoder_padding_mask'] is not None: encoder_out_dict['encoder_padding_mask'] = \ encoder_out_dict['encoder_padding_mask'].index_select(0, new_order) return encoder_out_dict def max_positions(self): """Maximum output length supported by the decoder.""" return self.embed_positions.max_positions() Loading @@ -233,11 +239,6 @@ class TransformerDecoder(FairseqIncrementalDecoder): return state_dict def reorder_encoder_out(self, encoder_out, new_order): if encoder_out['encoder_padding_mask'] is not None: encoder_out['encoder_padding_mask'] = encoder_out['encoder_padding_mask'].index_select(0, new_order) return encoder_out class TransformerEncoderLayer(nn.Module): """Encoder layer block. Loading Loading @@ -312,7 +313,6 @@ class TransformerDecoderLayer(nn.Module): def forward(self, x, encoder_out, encoder_padding_mask, incremental_state): residual = x x = self.maybe_layer_norm(0, x, before=True) x, _ = self.self_attn( query=x, key=x, Loading @@ -327,7 +327,6 @@ class TransformerDecoderLayer(nn.Module): residual = x x = self.maybe_layer_norm(1, x, before=True) x, attn = self.encoder_attn( query=x, key=encoder_out, Loading @@ -336,7 +335,6 @@ class TransformerDecoderLayer(nn.Module): incremental_state=incremental_state, static_kv=True, ) x = F.dropout(x, p=self.dropout, training=self.training) x = residual + x x = self.maybe_layer_norm(1, x, after=True) Loading Loading
fairseq/distributed_utils.py +0 −1 Changes for fairseq/distributed_utils.py: 0 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -5,7 +5,6 @@ # the root directory of this source tree. An additional grant of patent rights # can be found in the PATENTS file in the same directory. import math import pickle import torch.distributed Loading
fairseq/fp16_trainer.py +0 −2 Changes for fairseq/fp16_trainer.py: 0 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -9,8 +9,6 @@ Train a network on multiple GPUs. """ import math import torch from fairseq import optim Loading
fairseq/models/fconv.py +13 −17 Changes for fairseq/models/fconv.py: 13 added lines, 17 removed lines. Original line number Diff line number Diff line Loading @@ -357,6 +357,19 @@ class FConvDecoder(FairseqIncrementalDecoder): return x, avg_attn_scores def reorder_incremental_state(self, incremental_state, new_order): super().reorder_incremental_state(incremental_state, new_order) encoder_out = utils.get_incremental_state(self, incremental_state, 'encoder_out') if encoder_out is not None: encoder_out = tuple(eo.index_select(0, new_order) for eo in encoder_out) utils.set_incremental_state(self, incremental_state, 'encoder_out', encoder_out) def reorder_encoder_out(self, encoder_out_dict, new_order): if encoder_out_dict['encoder_padding_mask'] is not None: encoder_out_dict['encoder_padding_mask'] = \ encoder_out_dict['encoder_padding_mask'].index_select(0, new_order) return encoder_out_dict def max_positions(self): """Maximum output length supported by the decoder.""" return self.embed_positions.max_positions() Loading Loading @@ -401,23 +414,6 @@ class FConvDecoder(FairseqIncrementalDecoder): return x def reorder_incremental_state(self, incremental_state, new_order): super().reorder_incremental_state(incremental_state, new_order) encoder_out = utils.get_incremental_state(self, incremental_state, 'encoder_out') if encoder_out is not None: def update_enc_out(enc_out): return enc_out.index_select(0, new_order) encoder_out = tuple([update_enc_out(eo) for eo in encoder_out]) utils.set_incremental_state(self, incremental_state, 'encoder_out', encoder_out) def reorder_encoder_out(self, encoder_out_dict, new_order): if encoder_out_dict['encoder_padding_mask'] is not None: encoder_out_dict['encoder_padding_mask'] = encoder_out_dict['encoder_padding_mask'].index_select(0, new_order) return encoder_out_dict def Embedding(num_embeddings, embedding_dim, padding_idx): m = nn.Embedding(num_embeddings, embedding_dim, padding_idx=padding_idx) m.weight.data.normal_(0, 0.1) Loading
fairseq/models/lstm.py +6 −4 Changes for fairseq/models/lstm.py: 6 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -373,6 +373,7 @@ class LSTMDecoder(FairseqIncrementalDecoder): return x, attn_scores def reorder_incremental_state(self, incremental_state, new_order): super().reorder_incremental_state(incremental_state, new_order) cached_state = utils.get_incremental_state(self, incremental_state, 'cached_state') if cached_state is None: return Loading @@ -382,16 +383,17 @@ class LSTMDecoder(FairseqIncrementalDecoder): return [reorder_state(state_i) for state_i in state] return state.index_select(0, new_order) if not isinstance(new_order, Variable): new_order = Variable(new_order) new_state = tuple(map(reorder_state, cached_state)) utils.set_incremental_state(self, incremental_state, 'cached_state', new_state) def reorder_encoder_out(self, encoder_out_dict, new_order): encoder_out_dict['encoder_out'] = tuple( eo.index_select(1, new_order) for eo in encoder_out_dict['encoder_out']) eo.index_select(1, new_order) for eo in encoder_out_dict['encoder_out'] ) if encoder_out_dict['encoder_padding_mask'] is not None: encoder_out_dict['encoder_padding_mask'] = encoder_out_dict['encoder_padding_mask'].index_select(1, new_order) encoder_out_dict['encoder_padding_mask'] = \ encoder_out_dict['encoder_padding_mask'].index_select(1, new_order) return encoder_out_dict def max_positions(self): Loading
fairseq/models/transformer.py +7 −9 Changes for fairseq/models/transformer.py: 7 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ # can be found in the PATENTS file in the same directory. import math import torch import torch.nn as nn import torch.nn.functional as F Loading @@ -15,7 +16,6 @@ from fairseq.modules import ( LearnedPositionalEmbedding, MultiheadAttention, SinusoidalPositionalEmbedding, ) from fairseq import utils from . import ( FairseqIncrementalDecoder, FairseqEncoder, FairseqModel, Loading Loading @@ -220,6 +220,12 @@ class TransformerDecoder(FairseqIncrementalDecoder): return x, attn def reorder_encoder_out(self, encoder_out_dict, new_order): if encoder_out_dict['encoder_padding_mask'] is not None: encoder_out_dict['encoder_padding_mask'] = \ encoder_out_dict['encoder_padding_mask'].index_select(0, new_order) return encoder_out_dict def max_positions(self): """Maximum output length supported by the decoder.""" return self.embed_positions.max_positions() Loading @@ -233,11 +239,6 @@ class TransformerDecoder(FairseqIncrementalDecoder): return state_dict def reorder_encoder_out(self, encoder_out, new_order): if encoder_out['encoder_padding_mask'] is not None: encoder_out['encoder_padding_mask'] = encoder_out['encoder_padding_mask'].index_select(0, new_order) return encoder_out class TransformerEncoderLayer(nn.Module): """Encoder layer block. Loading Loading @@ -312,7 +313,6 @@ class TransformerDecoderLayer(nn.Module): def forward(self, x, encoder_out, encoder_padding_mask, incremental_state): residual = x x = self.maybe_layer_norm(0, x, before=True) x, _ = self.self_attn( query=x, key=x, Loading @@ -327,7 +327,6 @@ class TransformerDecoderLayer(nn.Module): residual = x x = self.maybe_layer_norm(1, x, before=True) x, attn = self.encoder_attn( query=x, key=encoder_out, Loading @@ -336,7 +335,6 @@ class TransformerDecoderLayer(nn.Module): incremental_state=incremental_state, static_kv=True, ) x = F.dropout(x, p=self.dropout, training=self.training) x = residual + x x = self.maybe_layer_norm(1, x, after=True) Loading