File size: 1,000 Bytes
35c1cfd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from slam_llm.utils.dataset_utils import load_module_from_py_file
from pathlib import Path

def get_custom_model_factory(model_config):
    costom_model_path = model_config.get(
        "file", None
    )
    if costom_model_path is None:
        from slam_llm.models.slam_model import model_factory
        return model_factory

    if ":" in costom_model_path:
        module_path, func_name = costom_model_path.split(":")
    else:
        module_path, func_name = costom_model_path, "model_factory"

    if not module_path.endswith(".py"):
        raise ValueError(f"Dataset file {module_path} is not a .py file.")
    
    module_path = Path(module_path)
    if not module_path.is_file():
        raise FileNotFoundError(f"Dataset py file {module_path.as_posix()} does not exist or is not a file.")

    module = load_module_from_py_file(module_path.as_posix())
    try:
        return getattr(module, func_name)
    except AttributeError as e:
        raise e