__init__.py 844 Bytes
Newer Older
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
import os
from typing import Optional, Union
import infinicore

__all__ = ["AutoLlamaModel"]


class AutoLlamaModel:
    @classmethod
    def from_pretrained(
        cls,
        model_path: Optional[Union[str, os.PathLike]],
        device: infinicore.device,
        dtype=infinicore.dtype,
        backend="python",
    ):
        if backend == "python":
            from . import modeling_llama

            return modeling_llama.LlamaForCausalLM.from_pretrained(
                model_path,
                device=device,
                dtype=dtype,
            )

        elif backend == "cpp":
            from .backends import cpp

            return cpp.LlamaForCausalLM.from_pretrained(
                model_path,
                device=device,
                dtype=dtype,
            )

        raise KeyError("invalid backend")