Skip to content

Commit 4c30942

Browse files
authored
Fixes to blocking cross-attention (#1087)
1 parent 01e2392 commit 4c30942

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ Note that Sockeye has checks in place to not translate with an old model that wa
1111

1212
Each version section may have subsections for: _Added_, _Changed_, _Removed_, _Deprecated_, and _Fixed_.
1313

14+
## [3.1.34]
15+
16+
### Fixed
17+
- Do not mask prepended tokens by default (for self-attention).
18+
- Do not require specifying `--end-of-prepending-tag` if it is already done when preparing the data.
19+
1420
## [3.1.33]
1521

1622
### Fixed

sockeye/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
# express or implied. See the License for the specific language governing
1212
# permissions and limitations under the License.
1313

14-
__version__ = '3.1.33'
14+
__version__ = '3.1.34'

sockeye/layers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def forward(self,
321321

322322

323323
def prepare_source_length_mask(lengths: pt.Tensor, heads: int, max_length: int, expand: bool = True,
324-
mask_prepended_tokens: bool = True) -> pt.Tensor:
324+
mask_prepended_tokens: bool = False) -> pt.Tensor:
325325
"""
326326
Prepare source length masks where positions of invalid tokens are marked as True.
327327

sockeye/train.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ def check_arg_compatibility(args: argparse.Namespace):
136136
# Length 1: expand the list to the appropriate length
137137
args.target_factors_share_embedding = args.target_factors_share_embedding * n_target_factors
138138

139-
# Check arguments used for blocking cross-attention between decoder and encoded prepended tokens
140-
if args.transformer_block_prepended_cross_attention:
141-
check_condition(args.end_of_prepending_tag is not None,
142-
'In order to block cross-attention between decoder and encoded prepended tokens, '
143-
'please specify the tag indicating the end of prepended text using --end-of-prepending-tag')
144-
145139
check_condition(not (args.amp and args.apex_amp), 'Use either --amp (safer) or --apex-amp (faster).')
146140

147141
if args.dtype != C.DTYPE_FP32:
@@ -305,8 +299,6 @@ def create_data_iters_and_vocabs(args: argparse.Namespace,
305299
C.TRAINING_ARG_PREPARED_DATA)
306300
if args.prepared_data is not None:
307301
utils.check_condition(args.source is None and args.target is None, either_raw_or_prepared_error_msg)
308-
if args.end_of_prepending_tag is not None:
309-
logger.warning("The end-of-prepending tag specified in the prepared data will be used.")
310302
if not resume_training:
311303
utils.check_condition(args.source_vocab is None and args.target_vocab is None,
312304
"You are using a prepared data folder, which is tied to a vocabulary. "
@@ -320,6 +312,15 @@ def create_data_iters_and_vocabs(args: argparse.Namespace,
320312
batch_type=args.batch_type,
321313
batch_sentences_multiple_of=args.batch_sentences_multiple_of)
322314

315+
# Check arguments used for blocking cross-attention between decoder and encoded prepended tokens
316+
if args.transformer_block_prepended_cross_attention:
317+
check_condition(data_config.eop_id != C.INVALID_ID,
318+
'In order to block cross-attention between decoder and encoded prepended tokens, '
319+
'please specify the tag indicating the end of prepended text when preparing the data using '
320+
'--end-of-prepending-tag')
321+
if args.end_of_prepending_tag is not None:
322+
logger.warning("The end-of-prepending tag specified in the prepared data will be used.")
323+
323324
check_condition(all([combine in [C.FACTORS_COMBINE_SUM, C.FACTORS_COMBINE_AVERAGE]
324325
for combine in args.source_factors_combine])
325326
or len(source_vocabs) == len(args.source_factors_num_embed) + 1,
@@ -356,6 +357,11 @@ def create_data_iters_and_vocabs(args: argparse.Namespace,
356357
else:
357358
utils.check_condition(args.prepared_data is None and args.source is not None and args.target is not None,
358359
either_raw_or_prepared_error_msg)
360+
# Check arguments used for blocking cross-attention between decoder and encoded prepended tokens
361+
if args.transformer_block_prepended_cross_attention:
362+
check_condition(args.end_of_prepending_tag is not None,
363+
'In order to block cross-attention between decoder and encoded prepended tokens, '
364+
'please specify the tag indicating the end of prepended text using --end-of-prepending-tag')
359365

360366
if resume_training:
361367
# Load the existing vocabs created when starting the training run.

0 commit comments

Comments
 (0)