__init__.py 1.1 KB
Newer Older
1
from text_generation.models.model import Model
2
from text_generation.models.causal_lm import CausalLM
3
from text_generation.models.bloom import BLOOM, BLOOMSharded
4
from text_generation.models.seq2seq_lm import Seq2SeqLM
5
from text_generation.models.galactica import Galactica, GalacticaSharded
6

7
__all__ = ["Model", "BLOOM", "BLOOMSharded", "CausalLM", "Seq2SeqLM", "get_model"]
8
9
10
11
12


def get_model(model_name: str, sharded: bool, quantize: bool) -> Model:
    if model_name.startswith("bigscience/bloom"):
        if sharded:
OlivierDehaene's avatar
OlivierDehaene committed
13
            return BLOOMSharded(model_name, quantize=quantize)
14
        else:
15
            return BLOOM(model_name, quantize=quantize)
16
17
18
19
20
    elif model_name.startswith("facebook/galactica"):
        if sharded:
            return GalacticaSharded(model_name, quantize=quantize)
        else:
            return Galactica(model_name, quantize=quantize)
21
    else:
22
23
        if sharded:
            raise ValueError("sharded is not supported for AutoModel")
24
        try:
OlivierDehaene's avatar
OlivierDehaene committed
25
            return CausalLM(model_name, quantize=quantize)
26
        except Exception as e:
OlivierDehaene's avatar
OlivierDehaene committed
27
            return Seq2SeqLM(model_name, quantize=quantize)