phorknorak/English-Khmer-translation
Viewer • Updated • 200k • 27
# pip install sentencepiece
# pip install --no-deps "transformers @ git+https://github.com/huggingface/transformers@92cd495f2720c064bc78eb2d93e28704c5bce51f" "tokenizers>=0.23.1,<0.24" "safetensors>=0.8.0"
# (restart the runtime after installing)
import torch
from transformers import AutoModel
# Check if CUDA (GPU) is available, otherwise default to CPU
device = "cuda" if torch.cuda.is_available() else "cpu"
# Load the model with appropriate dtype and move to the device
model = AutoModel.from_pretrained(
"cheahour/khmer-translation-v2.2",
trust_remote_code=True,
torch_dtype=torch.float16 if device == "cuda" else torch.float32
).to(device)
print(model.translate("Where is the nearest hospital?", to="km")) # English -> Khmer
print(model.translate("សូមអរគុណច្រើន។", to="en")) # Khmer -> English
No unsloth, peft or bitsandbytes needed. A GPU is recommended (a free Colab T4 works).