请问下ModelScope这个模型输出结果为什么都是换行符呢?,代码:import torch
from modelscope import AutoModel, AutoTokenizer
model_id = 'ZhipuAI/CodeGeeX2-6B'
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True,revision = 'v1.0.0')
model = AutoModel.from_pretrained(model_id, device_map={'': 'mps:0'}, # auto
torch_dtype=torch.float16, trust_remote_code=True,revision = 'v1.0.0')
model = model.eval()
prompt = "# language: python\n# write a bubble sort function\n"
inputs = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(inputs, max_length=256)
response = tokenizer.decode(outputs[0])
response
代码中您print一下model.device,看看mps是否可用,然后device_map="auto"或"cpu",torch.float16不要了。此回答整理自钉群 “魔搭ModelScope开发者联盟群 ①”