File size: 1,712 Bytes
8889bbb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

from .base_engine import BaseEngine

BACKENDS = [
    "mlx", 
    "vllm", 
    "transformers",
    "llama_cpp",
    # "llava_llama_cpp",
    "debug",
    "sealmmm_transformers",
]

ENGINE_LOADED = False

def load_multipurpose_chatbot_engine(backend: str):
    # ! lazy import other engines
    global ENGINE_LOADED
    assert backend in BACKENDS, f'{backend} not in {BACKENDS}'
    if ENGINE_LOADED:
        raise RuntimeError(f'{ENGINE_LOADED=} this means load_multipurpose_chatbot_engine has already been called! Check your codes.')
    print(f'Load model from {backend}')
    if backend == "mlx":
        from .mlx_engine import MlxEngine
        model_engine = MlxEngine()
    elif backend == 'vllm':
        from .vllm_engine import VllmEngine
        model_engine = VllmEngine()
    elif backend == 'transformers':
        from .transformers_engine import TransformersEngine
        model_engine = TransformersEngine()
    elif backend == 'llama_cpp':
        from .llama_cpp_engine import LlamaCppEngine
        model_engine = LlamaCppEngine()
    # ! llava_llama_cpp currently not done due to bugs
    # elif backend == 'llava_llama_cpp':
    #     from .llava_llama_cpp_engine import LlavaLlamaCppEngine
    #     model_engine = LlavaLlamaCppEngine()
    elif backend == 'debug':
        from .debug_engine import DebugEngine
        model_engine = DebugEngine()
    elif backend == 'sealmmm_transformers':
        from .sealmmm_engine import SeaLMMMv0Engine
        model_engine = SeaLMMMv0Engine()
    else:
        raise ValueError(f'backend invalid: {BACKENDS} vs {backend}')

    model_engine.load_model()
    ENGINE_LOADED = True
    return model_engine
    # ! add more llama.cpp engine here.