ablang2 / test_module_loading.py
hemantn's picture
Add ablang.py and encoderblock.py to root directory for Hugging Face compatibility
7ebbadf
raw
history blame
706 Bytes
import sys
import os
import numpy as np
from transformers import AutoModel, AutoTokenizer
from transformers.utils import cached_file
# Load model and tokenizer from Hugging Face Hub
model = AutoModel.from_pretrained("hemantn/ablang2", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("hemantn/ablang2", trust_remote_code=True)
# Find the cached model directory and import adapter
adapter_path = cached_file("hemantn/ablang2", "adapter.py")
cached_model_dir = os.path.dirname(adapter_path)
sys.path.insert(0, cached_model_dir)
# Import and create the adapter
from adapter import AbLang2PairedHuggingFaceAdapter
ablang = AbLang2PairedHuggingFaceAdapter(model=model, tokenizer=tokenizer)