OpenNMTTFConverter

class ctranslate2.converters.OpenNMTTFConverter

Converts OpenNMT-tf models.

Inherits from: ctranslate2.converters.Converter

Methods:

__init__(model)

Initializes the converter.

Parameters

model – An initialized and fully-built opennmt.models.Model instance.

convert(output_dir: str, vmap: Optional[str] = None, quantization: Optional[str] = None, force: bool = False) str

Converts the model to the CTranslate2 format.

Parameters
  • output_dir – Output directory where the CTranslate2 model is saved.

  • vmap – Optional path to a vocabulary mapping file that will be included in the converted model directory.

  • quantization – Weight quantization scheme (possible values are: int8, int8_float32, int8_float16, int8_bfloat16, int16, float16, bfloat16, float32).

  • force – Override the output directory if it already exists.

Returns

Path to the output directory.

Raises
  • RuntimeError – If the output directory already exists and force is not set.

  • NotImplementedError – If the converter cannot convert this model to the CTranslate2 format.

convert_from_args(args: Namespace) str

Helper function to call ctranslate2.converters.Converter.convert() with the parsed command line options.

Parameters

args – Namespace containing parsed arguments.

Returns

Path to the output directory.

static declare_arguments(parser: ArgumentParser) ArgumentParser

Adds common conversion options to the command line parser.

Parameters

parser – Command line argument parser.

classmethod from_config(config: Union[str, dict], auto_config: bool = False, checkpoint_path: Optional[str] = None, model: Optional[str] = None)

Creates the converter from the configuration.

Parameters
  • config – Path to the YAML configuration, or a dictionary with the loaded configuration.

  • auto_config – Whether the model automatic configuration values should be used.

  • checkpoint_path – Path to the checkpoint or checkpoint directory to load. If not set, the latest checkpoint from the model directory is loaded.

  • model – If the model instance cannot be resolved from the model directory, this argument can be set to either the name of the model in the catalog or the path to the model configuration.

Returns

A ctranslate2.converters.OpenNMTTFConverter instance.