Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
add back default values to underspecified call sites (#3501)
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerp authored Mar 9, 2021
1 parent 394e568 commit 35e468a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
12 changes: 8 additions & 4 deletions parlai/agents/transformer/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ def __init__(
n_positions: Optional[int] = None,
n_segments: Optional[int] = None,
embeddings_scale: Optional[bool] = None,
dropout: Optional[float] = None,
activation: Optional[str] = None,
variant: Optional[str] = None,
output_scaling: Optional[float] = None,
):
super(TransformerEncoder, self).__init__()

Expand All @@ -325,9 +329,9 @@ def _default(val, default):
self.reduction_type = reduction_type
self.padding_idx = padding_idx
# this is --dropout, not --relu-dropout or --attention-dropout
self.dropout_frac = opt.get('dropout', 0.0)
self.dropout_frac = _default(dropout, opt.get('dropout', 0.0))
self.dropout = nn.Dropout(p=self.dropout_frac)
self.variant = opt.get('variant', 'aiayn')
self.variant = _default(variant, opt.get('variant', 'aiayn'))
self.n_segments = _default(n_segments, opt.get('n_segments', 0))

self.n_positions = _default(n_positions, get_n_positions_from_options(opt))
Expand Down Expand Up @@ -395,10 +399,10 @@ def _default(val, default):
relu_dropout=opt.get('relu_dropout', 0.0),
dropout=self.dropout_frac,
variant=self.variant,
activation=opt.get('activation', 'relu'),
activation=_default(activation, opt.get('activation', 'relu')),
)
)
self.output_scaling = opt.get('output_scaling', 1.0)
self.output_scaling = _default(output_scaling, opt.get('output_scaling', 1.0))

def forward_embedding(
self,
Expand Down
1 change: 1 addition & 0 deletions projects/image_chat/transresnet_multimodal/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def _build_context_encoder(self):
vocabulary_size=len(self.dictionary),
padding_idx=self.dictionary.tok2ind[self.dictionary.null_token],
embeddings_scale=False,
output_scaling=1.0,
)
if self.opt.get("load_context_encoder_from") is not None:
self._load_context_encoder_state()
Expand Down
1 change: 1 addition & 0 deletions projects/personality_captions/transresnet/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def _build_text_encoder(self, n_layers_text):
vocabulary_size=len(self.dictionary),
padding_idx=self.dictionary.tok2ind[self.dictionary.null_token],
embeddings_scale=False,
output_scaling=1.0,
)
if self.opt.get('load_encoder_from') is not None:
self._load_text_encoder_state()
Expand Down
6 changes: 6 additions & 0 deletions projects/self_feeding/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ def build_encoder(self, opt, embeddings):
embedding=embeddings,
vocabulary_size=self.vocab_size,
padding_idx=self.pad_idx,
dropout=0.0,
n_positions=1024,
n_segments=0,
activation='relu',
variant='aiayn',
output_scaling=1.0,
)

def build_head(self, opt, outdim=1, num_layers=1):
Expand Down

0 comments on commit 35e468a

Please sign in to comment.