OpenAIGPT2Converter

class ctranslate2.converters.OpenAIGPT2Converter

Converts GPT-2 models from https://github.com/openai/gpt-2.

Inherits from: ctranslate2.converters.Converter

Methods:

__init__(model_dir: str)

Initializes the OpenAI GPT-2 converter.

Parameters

model_dir – Path to the OpenAI GPT-2 model directory.

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.