Skip to content

Commit

Permalink
Add more checks before converting checkpoints to CTranslate2 (#2053)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumekln authored Apr 30, 2021
1 parent b1a4615 commit e4ab06c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions onmt/bin/release_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
import argparse
import torch

from onmt.modules.position_ffn import ActivationFunction


def get_ctranslate2_model_spec(opt):
"""Creates a CTranslate2 model specification from the model options."""
with_relative_position = getattr(opt, "max_relative_positions", 0) > 0
relu = ActivationFunction.relu
is_ct2_compatible = (
opt.encoder_type == "transformer"
and opt.decoder_type == "transformer"
and not getattr(opt, "aan_useffn", False)
and getattr(opt, "self_attn_type", "scaled-dot") == "scaled-dot"
and getattr(opt, "pos_ffn_activation_fn", relu) == relu
and ((opt.position_encoding and not with_relative_position)
or (with_relative_position and not opt.position_encoding)))
if not is_ct2_compatible:
Expand Down

0 comments on commit e4ab06c

Please sign in to comment.