translate / convert_model.py
devusman's picture
update
3f9181a
raw
history blame contribute delete
787 Bytes
import os
from ct2_transformers import TransformerConverter
# 1. Define the source Hugging Face model
model_name = "Helsinki-NLP/opus-mt-tc-big-en-ar"
# 2. Define the output path for the converted model
output_dir = "en_ar_ct2_model"
# Create the output directory if it doesn't exist
if not os.path.exists(output_dir):
os.makedirs(output_dir)
print(f"Starting conversion of model: {model_name}")
print("This may take a few moments...")
# 3. Initialize the converter
converter = TransformerConverter(model_name)
# 4. Run the conversion and apply quantization for speed
converter.convert(output_dir, quantization="int8")
print(f"\nModel successfully converted and saved to the '{output_dir}' folder.")
print("You are now ready to upload this folder to your Hugging Face Space.")