代码如下:
import torch
from modelscope import AutoModel, AutoTokenizer
model_id = 'ZhipuAI/codegeex2-6b'
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModel.from_pretrained(model_id, device_map={'': 'cuda:0'}, # auto
torch_dtype=torch.bfloat16, trust_remote_code=True)
model = model.eval()
prompt = "# language: SQL\n# Can you write SQL queries in PostgreSQL 14 that create a table 'customers' with the columns 'customer_id','username','email','join_date','last_purchase_date'. Include relevant constraints and index \n"
inputs = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(inputs, max_length=1024)
response = tokenizer.decode(outputs[0])
print(response)
输出如下:
Loading widget...
The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's attention_mask to obtain reliable results.
Setting pad_token_id to eos_token_id:2 for open-end generation.
language: SQL
Can you write SQL queries in PostgreSQL 14 that create a table 'customers' with the columns 'customer_id','username','email','join_date','last_purchase_date'. Include relevant constraints and index
代码如下: import torch from modelscope import AutoModel, AutoTokenizer
model_id = 'ZhipuAI/codegeex2-6b' tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True) model = AutoModel.from_pretrained(model_id, device_map={'': 'cuda:0'}, # auto torch_dtype=torch.bfloat16, trust_remote_code=True) model = model.eval() prompt = "# language: SQL\n# Can you write SQL queries in PostgreSQL 14 that create a table 'customers' with the columns 'customer_id','username','email','join_date','last_purchase_date'. Include relevant constraints and index \n" inputs = tokenizer.encode(prompt, return_tensors="pt").to(model.device) outputs = model.generate(inputs, max_length=1024) response = tokenizer.decode(outputs[0]) print(response)
输出如下: Loading widget... The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's
attention_mask
to obtain reliable results. Settingpad_token_id
toeos_token_id
:2 for open-end generation.language: SQL
Can you write SQL queries in PostgreSQL 14 that create a table 'customers' with the columns 'customer_id','username','email','join_date','last_purchase_date'. Include relevant constraints and index
是语句用的不对吗,代码没有出来,求教!