🚀 Phind-CodeLlama-34B-v2
Phind-CodeLlama-34B-v2在Phind-CodeLlama-34B-v1的基础上,使用额外的15亿高质量编程相关数据进行微调,在HumanEval基准测试中达到了73.8%的pass@1准确率,是当前开源模型中的佼佼者。此外,该模型还按照Alpaca/Vicuna格式进行了指令微调,使用起来更加灵活方便。
🚀 快速开始
安装依赖
确保从主git分支安装Transformers库:
pip install git+https://github.com/huggingface/transformers.git
模型提示格式
此模型接受Alpaca/Vicuna指令格式。例如:
### System Prompt
You are an intelligent programming assistant.
### User Message
Implement a linked list in C++
### Assistant
...
✨ 主要特性
- 高精度:在HumanEval基准测试中达到73.8%的pass@1准确率,展现了出色的代码生成能力。
- 多语言支持:支持Python、C/C++、TypeScript、Java等多种编程语言。
- 指令微调:按照Alpaca/Vicuna格式进行指令微调,易于使用和控制。
📦 安装指南
确保从主git分支安装Transformers库:
pip install git+https://github.com/huggingface/transformers.git
💻 使用示例
基础用法
以下是如何使用该模型进行推理的示例:
from transformers import AutoTokenizer, LlamaForCausalLM
from human_eval.data import write_jsonl, read_problems
from tqdm import tqdm
model_path = "Phind/Phind-CodeLlama-34B-v2"
model = LlamaForCausalLM.from_pretrained(model_path, device_map="auto")
tokenizer = AutoTokenizer.from_pretrained(model_path)
def generate_one_completion(prompt: str):
tokenizer.pad_token = tokenizer.eos_token
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=4096)
generate_ids = model.generate(inputs.input_ids.to("cuda"), max_new_tokens=384, do_sample=True, top_p=0.75, top_k=40, temperature=0.1)
completion = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
completion = completion.replace(prompt, "").split("\n\n\n")[0]
return completion
problems = read_problems()
num_samples_per_task = 1
samples = [
dict(task_id=task_id, completion=generate_one_completion(problems[task_id]["prompt"]))
for task_id in tqdm(problems)
for _ in range(num_samples_per_task)
]
write_jsonl("samples.jsonl", samples)
📚 详细文档
模型详情
该模型基于Phind-CodeLlama-34B-v1进行微调,在HumanEval基准测试中达到了73.8%的pass@1准确率。Phind-CodeLlama-34B-v2支持多种语言,包括Python、C/C++、TypeScript、Java等。
数据集详情
我们使用了一个包含15亿高质量编程问题和解决方案的专有数据集进行微调。该数据集由指令-答案对组成,而不是代码补全示例,因此在结构上与HumanEval不同。我们没有使用LoRA,两个模型都是原生微调。我们使用DeepSpeed ZeRO 3和Flash Attention 2在32个A100-80GB GPU上用15小时训练了这些模型,序列长度为4096个标记。
复现HumanEval结果
要复现我们在HumanEval上的结果,请参考上述“使用示例”中的代码。
🔧 技术细节
训练硬件
- 硬件类型:32个A100-80GB GPU
- 使用时长:480 GPU小时
- 云服务提供商:AWS
- 计算区域:us-east-1
训练参数
📄 许可证
本模型使用Llama 2许可证。
⚠️ 重要提示
该模型仅经过了非常有限的测试,在实际应用之前,建议进行额外的安全测试。