Salesforce AI发布CodeGen 2.5,一个小型的代码生成模型。
– 与两倍大小的型号相当
– 在 1.5T 代币上进行训练
– 具有快速填充采样功能
消息
2023 年 7 月
CodeGen2.5发布的参数模型仅7B,性能优于16B。
2023年5月
CodeGen2.0发布,具有强大的填充采样能力。
March 2022 2022 年 3 月
CodeGen1.0 与当时的 OpenAI Codex 齐名发布。
用法
这些模型可在 HuggingFace Hub 上找到。
CodeGen1.0
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen-2B-mono")
model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen-2B-mono")
inputs = tokenizer("# this function prints hello world", return_tensors="pt")
sample = model.generate(**inputs, max_length=128)
print(tokenizer.decode(sample[0], truncate_before_pattern=[r"\n\n^#", "^'''", "\n\n\n"]))
CodeGen2.0
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen2-7B")
model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen2-7B", trust_remote_code=True, revision="main")
inputs = tokenizer("# this function prints hello world", return_tensors="pt")
sample = model.generate(**inputs, max_length=128)
print(tokenizer.decode(sample[0], truncate_before_pattern=[r"\n\n^#", "^'''", "\n\n\n"]))
CodeGen2.5
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen25-7b-mono", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen25-7b-mono")
inputs = tokenizer("# this function prints hello world", return_tensors="pt")
sample = model.generate(**inputs, max_length=128)
print(tokenizer.decode(sample[0]))
训练
用于数据预处理、训练和微调 CodeGen 模型的 Jaxformer 库可以在此处找到:
https://github.com/salesforce/jaxformer
项目链接
https://github.com/salesforce/CodeGen
https://huggingface.co/models?search=salesforce+codegen
原创文章,作者:校长,如若转载,请注明出处:https://www.yundongfang.com/Yun267424.html