feat: 实现模型动态注册机制
This commit is contained in:
@@ -2,24 +2,32 @@ from pathlib import Path
|
||||
|
||||
import torch
|
||||
|
||||
from astrai.config.param_config import ModelParameter
|
||||
from astrai.inference import InferenceEngine
|
||||
from astrai.model import AutoModel
|
||||
from astrai.tokenize import AutoTokenizer
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
||||
PARAMETER_ROOT = Path(PROJECT_ROOT, "params")
|
||||
|
||||
|
||||
def generate_text():
|
||||
param = ModelParameter.load(PARAMETER_ROOT, disable_init=True)
|
||||
param.to(device="cuda", dtype=torch.bfloat16)
|
||||
# Load model from pretrained
|
||||
model = AutoModel.from_pretrained(PARAMETER_ROOT)
|
||||
model.to(device="cuda", dtype=torch.bfloat16)
|
||||
|
||||
# Load tokenizer from pretrained
|
||||
tokenizer = AutoTokenizer.from_pretrained(PARAMETER_ROOT / "tokenizer")
|
||||
|
||||
query = input(">> ")
|
||||
|
||||
engine = InferenceEngine(param)
|
||||
engine = InferenceEngine(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
)
|
||||
response = engine.generate(
|
||||
prompt=query,
|
||||
stream=False,
|
||||
max_tokens=param.config.max_len,
|
||||
max_tokens=2048,
|
||||
temperature=0.8,
|
||||
top_p=0.95,
|
||||
top_k=50,
|
||||
|
||||
Reference in New Issue
Block a user