fixed relative path
Browse files- modeling_ablang2paired.py +23 -4
modeling_ablang2paired.py
CHANGED
|
@@ -4,13 +4,32 @@ from torch import nn
|
|
| 4 |
from transformers import PreTrainedModel
|
| 5 |
|
| 6 |
# Import logic to handle the nested directory structure
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
try:
|
| 8 |
-
# Try the relative import first (for Hugging Face Hub loading)
|
| 9 |
-
from .ablang2.models.ablang2.ablang import AbLang as AbLang2
|
| 10 |
from .configuration_ablang2paired import AbLang2PairedConfig
|
| 11 |
except ImportError:
|
| 12 |
-
# Fallback for local development
|
| 13 |
-
from ablang2.models.ablang2.ablang import AbLang as AbLang2
|
| 14 |
from ablang2.configuration_ablang2paired import AbLang2PairedConfig
|
| 15 |
|
| 16 |
class AbLang2PairedHFModel(PreTrainedModel):
|
|
|
|
| 4 |
from transformers import PreTrainedModel
|
| 5 |
|
| 6 |
# Import logic to handle the nested directory structure
|
| 7 |
+
import importlib.util
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
def load_ablang_module():
|
| 11 |
+
"""Load the AbLang module from the nested directory structure."""
|
| 12 |
+
# Try to find the ablang.py file in the nested directory
|
| 13 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 14 |
+
ablang_path = os.path.join(current_dir, "ablang2", "models", "ablang2", "ablang.py")
|
| 15 |
+
|
| 16 |
+
if os.path.exists(ablang_path):
|
| 17 |
+
spec = importlib.util.spec_from_file_location("ablang", ablang_path)
|
| 18 |
+
ablang_module = importlib.util.module_from_spec(spec)
|
| 19 |
+
spec.loader.exec_module(ablang_module)
|
| 20 |
+
return ablang_module.AbLang
|
| 21 |
+
else:
|
| 22 |
+
# Fallback to absolute import
|
| 23 |
+
from ablang2.models.ablang2.ablang import AbLang
|
| 24 |
+
return AbLang
|
| 25 |
+
|
| 26 |
+
# Load the AbLang class
|
| 27 |
+
AbLang2 = load_ablang_module()
|
| 28 |
+
|
| 29 |
+
# Import configuration
|
| 30 |
try:
|
|
|
|
|
|
|
| 31 |
from .configuration_ablang2paired import AbLang2PairedConfig
|
| 32 |
except ImportError:
|
|
|
|
|
|
|
| 33 |
from ablang2.configuration_ablang2paired import AbLang2PairedConfig
|
| 34 |
|
| 35 |
class AbLang2PairedHFModel(PreTrainedModel):
|