forked from phodal/understand-prompt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeai.py
More file actions
15 lines (11 loc) · 698 Bytes
/
codeai.py
File metadata and controls
15 lines (11 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from transformers import AutoTokenizer, AutoModelForCausalLM
# 可以直接从服务器端下载
# tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen-6B-mono")
# model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen-6B-mono")
# 或者用下载到本地的版本
tokenizer = AutoTokenizer.from_pretrained("/Volumes/game/codeai/ai-research/diff-codegen-6b-v2")
model = AutoModelForCausalLM.from_pretrained("/Volumes/game/codeai/ai-research/diff-codegen-6b-v2")
text = "def hello_world():"
input_ids = tokenizer(text, return_tensors="pt").input_ids
generated_ids = model.generate(input_ids, max_length=128)
print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))