————————————————————运行结果————————————————————————
#!/房的 post符 lim
涧数 hes multiableua ped ping cast ping符 able able ifawidget HTML]] able able ginger ref 旌 ableable集中的 #!/值的 ref是因為://也与 #!/您就可以 剪刀发展新
—————————————————————— 源码————————————————————————
import mindspore as ms
from mindformers import AutoConfig, AutoModel, AutoTokenizer
# 指定图模式,指定使用训练卡id
ms.set_context(mode=ms.GRAPH_MODE, device_target="Ascend", device_id=0)
tokenizer = AutoTokenizer.from_pretrained('./chatglm3-6b_ms')
# model = AutoModel.from_pretrained('./chatglm3-6b_ms')
# model的实例化有以下两种方式,选择其中一种进行实例化即可
# 1. 直接根据默认配置实例化
# # 2. 自定义修改配置后实例化
config = AutoConfig.from_pretrained('./chatglm3-6b_ms/run_glm3_6b.yaml')
config.use_past = True # 此处修改默认配置,开启增量推理能够加速推理性能
config.seq_length = 2048 # 根据需求自定义修改其余模型配置
config.checkpoint_name_or_path = "./chatglm3-6b_ms/glm3_6b.ckpt"
model = AutoModel.from_config(config) # 从自定义配置项中实例化模型
role="user"
inputs_list=["hello"]
for input_item in inputs_list:
history=[]
inputs = tokenizer.build_chat_input(input_item, history=history, role=role)
inputs = inputs['input_ids']
# 首次调用model.generate()进行推理将包含图编译时间,推理性能显示不准确,多次重复调用以获取准确的推理性能
outputs = model.generate(inputs, do_sample=False, top_k=1, max_length=2048)
response = tokenizer.decode(outputs)
for i, output in enumerate(outputs):
output = output[len(inputs[i]):]
response = tokenizer.decode(output)
print(response)
————————————————————运行结果————————————————————————
#!/房的 post符 lim
涧数 hes multiableua ped ping cast ping符 able able ifawidget HTML]] able able ginger ref 旌 ableable集中的 #!/值的 ref是因為://也与 #!/您就可以 剪刀发展新
—————————————————————— 源码————————————————————————
import mindspore as ms
from mindformers import AutoConfig, AutoModel, AutoTokenizer
# 指定图模式,指定使用训练卡id
ms.set_context(mode=ms.GRAPH_MODE, device_target="Ascend", device_id=0)
tokenizer = AutoTokenizer.from_pretrained('./chatglm3-6b_ms')
# model = AutoModel.from_pretrained('./chatglm3-6b_ms')
# model的实例化有以下两种方式,选择其中一种进行实例化即可
# 1. 直接根据默认配置实例化
# # 2. 自定义修改配置后实例化
config = AutoConfig.from_pretrained('./chatglm3-6b_ms/run_glm3_6b.yaml')
config.use_past = True # 此处修改默认配置,开启增量推理能够加速推理性能
config.seq_length = 2048 # 根据需求自定义修改其余模型配置
config.checkpoint_name_or_path = "./chatglm3-6b_ms/glm3_6b.ckpt"
model = AutoModel.from_config(config) # 从自定义配置项中实例化模型
role="user"
inputs_list=["hello"]
for input_item in inputs_list:
history=[]
inputs = tokenizer.build_chat_input(input_item, history=history, role=role)
inputs = inputs['input_ids']
# 首次调用model.generate()进行推理将包含图编译时间,推理性能显示不准确,多次重复调用以获取准确的推理性能
outputs = model.generate(inputs, do_sample=False, top_k=1, max_length=2048)
response = tokenizer.decode(outputs)
for i, output in enumerate(outputs):
output = output[len(inputs[i]):]
response = tokenizer.decode(output)
print(response)