2023-01-20 04:24:39 -07:00
|
|
|
import torch
|
|
|
|
|
2022-10-28 11:24:00 -06:00
|
|
|
from text_generation.models.model import Model
|
2022-11-04 07:22:47 -06:00
|
|
|
from text_generation.models.causal_lm import CausalLM
|
2022-12-08 10:49:33 -07:00
|
|
|
from text_generation.models.bloom import BLOOM, BLOOMSharded
|
2022-11-04 11:03:04 -06:00
|
|
|
from text_generation.models.seq2seq_lm import Seq2SeqLM
|
2022-12-01 11:31:54 -07:00
|
|
|
from text_generation.models.galactica import Galactica, GalacticaSharded
|
2023-01-20 04:24:39 -07:00
|
|
|
from text_generation.models.santacoder import SantaCoder
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
"Model",
|
|
|
|
"BLOOM",
|
|
|
|
"BLOOMSharded",
|
|
|
|
"CausalLM",
|
|
|
|
"Seq2SeqLM",
|
|
|
|
"SantaCoder",
|
|
|
|
"get_model",
|
|
|
|
]
|
|
|
|
|
|
|
|
# The flag below controls whether to allow TF32 on matmul. This flag defaults to False
|
|
|
|
# in PyTorch 1.12 and later.
|
|
|
|
torch.backends.cuda.matmul.allow_tf32 = True
|
2022-10-28 11:24:00 -06:00
|
|
|
|
2023-01-20 04:24:39 -07:00
|
|
|
# The flag below controls whether to allow TF32 on cuDNN. This flag defaults to True.
|
|
|
|
torch.backends.cudnn.allow_tf32 = True
|
2022-10-28 11:24:00 -06:00
|
|
|
|
|
|
|
|
|
|
|
def get_model(model_name: str, sharded: bool, quantize: bool) -> Model:
|
|
|
|
if model_name.startswith("bigscience/bloom"):
|
|
|
|
if sharded:
|
2022-11-07 04:53:56 -07:00
|
|
|
return BLOOMSharded(model_name, quantize=quantize)
|
2022-10-28 11:24:00 -06:00
|
|
|
else:
|
2022-12-08 10:49:33 -07:00
|
|
|
return BLOOM(model_name, quantize=quantize)
|
2022-12-01 11:31:54 -07:00
|
|
|
elif model_name.startswith("facebook/galactica"):
|
|
|
|
if sharded:
|
|
|
|
return GalacticaSharded(model_name, quantize=quantize)
|
|
|
|
else:
|
|
|
|
return Galactica(model_name, quantize=quantize)
|
2023-01-20 04:24:39 -07:00
|
|
|
elif "santacoder" in model_name:
|
|
|
|
return SantaCoder(model_name, quantize)
|
2022-10-28 11:24:00 -06:00
|
|
|
else:
|
2022-11-04 07:22:47 -06:00
|
|
|
if sharded:
|
|
|
|
raise ValueError("sharded is not supported for AutoModel")
|
2022-11-04 11:03:04 -06:00
|
|
|
try:
|
2022-11-07 04:53:56 -07:00
|
|
|
return CausalLM(model_name, quantize=quantize)
|
2023-01-17 01:10:22 -07:00
|
|
|
except Exception:
|
2022-11-07 04:53:56 -07:00
|
|
|
return Seq2SeqLM(model_name, quantize=quantize)
|