I want to know how to perform inference. I have made several attempts, including using the Transformers framework, but there are always issues.
here is my code. i always meet problem like 'Int8OPTDecoder' object has no attribute 'dropout'...if i change the version of transformers ,missing attribute will also change.
import torch
from transformers import AutoTokenizer
from smoothquant.opt import Int8OPTForCausalLM
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
def load_pretrained_int8_model():
# 官方提供的INT8模型
model_name = "/data/zyh/models/mit-han-lab/opt-125m-smoothquant"
tokenizer = AutoTokenizer.from_pretrained("/data/zyh/models/opt-125m")
# 直接加载INT8模型
model = Int8OPTForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
device_map="auto"
)
return model, tokenizer
def int8_inference_demo():
model, tokenizer = load_pretrained_int8_model()
# 推理
prompt = "The future of artificial intelligence is"
inputs = tokenizer(prompt, return_tensors="pt")
input_ids = inputs.input_ids.cuda()
with torch.no_grad():
outputs = model.generate(
input_ids,
max_new_tokens=50,
temperature=0.7,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(f"Generated: {generated_text}")
return generated_text
if name == "main":
int8_inference_demo()
I want to know how to perform inference. I have made several attempts, including using the Transformers framework, but there are always issues.
here is my code. i always meet problem like 'Int8OPTDecoder' object has no attribute 'dropout'...if i change the version of transformers ,missing attribute will also change.
import torch
from transformers import AutoTokenizer
from smoothquant.opt import Int8OPTForCausalLM
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
def load_pretrained_int8_model():
# 官方提供的INT8模型
model_name = "/data/zyh/models/mit-han-lab/opt-125m-smoothquant"
tokenizer = AutoTokenizer.from_pretrained("/data/zyh/models/opt-125m")
def int8_inference_demo():
model, tokenizer = load_pretrained_int8_model()
if name == "main":
int8_inference_demo()