蚂蚁集团开源代码大模型CodeFuse!(含魔搭体验和最佳实践)

本文涉及的产品
模型训练 PAI-DLC,5000CU*H 3个月
交互式建模 PAI-DSW,5000CU*H 3个月
模型在线服务 PAI-EAS,A10/V100等 500元 1个月
简介: 蚂蚁集团在刚刚结束的2023外滩大会上开源了代码大模型CodeFuse,目前在魔搭社区可下载、体验。

导读


蚂蚁集团在刚刚结束的2023外滩大会上开源了代码大模型CodeFuse,目前在魔搭社区可下载、体验。


CodeFuse是蚂蚁集团自研的代码生成模型,能提供智能建议和实时支持,帮助开发者自动生成代码、注释、测试用例等,提高研发效率。在评测中,CodeFuse的得分超过了GPT-4和WizardCoder-34B。开源内容包括代码框架和模型。代码框架支持多任务微调,包括代码生成、翻译、测试用例生成等任务。


模型包括 CodeFuse13B-4K CodeFuse-CodeLlaMa34B-MFT。CodeFuse早在6月开始内测,可用于开发助手、IDE插件等应用场景。



模型体验


CodeFuse-CodeLlaMa34B-MFT已经上线魔搭社区创空间,开发者们可以在创空间直接体验模型的代码生成效果。


创空间链接:

https://modelscope.cn/studios/codefuse-ai/CodeFuse-CodeLlama34B-MFT-Demo/summary




模型链接及下载


CodeFuse系列模型现已在ModelScope社区开源,包括:


CodeFuse-13B模型:

https://modelscope.cn/models/codefuse-ai/CodeFuse-13B/summary

from modelscope.hub.snapshot_download import snapshot_download
model_dir = snapshot_download('codefuse-ai/CodeFuse-13B', revision='v1.0.0')


CodeFuse-CodeLlama-34B模型:

https://modelscope.cn/models/codefuse-ai/CodeFuse-CodeLlama-34B/summary

from modelscope.hub.snapshot_download import snapshot_download
model_dir = snapshot_download('codefuse-ai/CodeFuse-CodeLlama-34B', revision='v1.0.0')



模型推理


CodeFuse-13B的推理代码

import torch
from modelscope import AutoModelForCausalLM, AutoTokenizer, snapshot_download
model_dir = snapshot_download('codefuse-ai/CodeFuse-13B', revision='v1.0.0')
tokenizer = AutoTokenizer.from_pretrained(model_dir)
model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", torch_dtype=torch.float16).eval()
input_ids = tokenizer.encode("# language: Python\ndef quick_sort(array):\n", return_tensors="pt").to("cuda")
output_ids = model.generate(input_ids, max_new_tokens=200)
print(tokenizer.decode(output_ids[0]))
"""Out[0]
# language: Python
def quick_sort(array):
    if len(array) <= 1:
        return array
    else:
        pivot = array[0]
        less_than_pivot = [i for i in array[1:] if i <= pivot]
        greater_than_pivot = [i for i in array[1:] if i > pivot]
        return quick_sort(less_than_pivot) + [pivot] + quick_sort(greater_than_pivot)
# Test the function
print(quick_sort([3,6,8,10,1,2,1]))<|endoftext|>
"""


CodeFuse-CodeLlama-34B的推理代码

import torch
from modelscope import AutoTokenizer, AutoModelForCausalLM, snapshot_download
model_dir = snapshot_download('codefuse-ai/CodeFuse-CodeLlama-34B', revision='v1.0.0')
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True, use_fast=False, legacy=False)
tokenizer.padding_side = "left"
tokenizer.pad_token_id = tokenizer.convert_tokens_to_ids("<unk>")
tokenizer.eos_token_id = tokenizer.convert_tokens_to_ids("</s>")
model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True, 
                                             device_map='auto', 
                                             torch_dtype=torch.bfloat16)
HUMAN_ROLE_START_TAG = "<|role_start|>human<|role_end|>"
BOT_ROLE_START_TAG = "<|role_start|>bot<|role_end|>"
text = f"{HUMAN_ROLE_START_TAG}write a python function of quick sort.{BOT_ROLE_START_TAG}" 
inputs = tokenizer(text, return_tensors='pt', padding=True, add_special_tokens=False).to("cuda")
outputs = model.generate(
        inputs=inputs["input_ids"],
        attention_mask=inputs["attention_mask"],
        max_new_tokens=512,
        top_p=0.95,
        temperature=0.1,
        do_sample=True,
        eos_token_id=tokenizer.eos_token_id,
        pad_token_id=tokenizer.pad_token_id
    )
gen_text = tokenizer.batch_decode(outputs[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(gen_text[0])
"""Out[0]
Here is a Python function for quick sort:
```python
def quick_sort(arr):
    if len(arr) <= 1:
        return arr
    else:
        pivot = arr[0]
        less = [i for i in arr[1:] if i <= pivot]
        greater = [i for i in arr[1:] if i > pivot]
        return quick_sort(less) + [pivot] + quick_sort(greater)
```
This function works by selecting the first element of the array as the pivot, and then partitioning the rest of the array into two parts: one with elements less than the pivot, and one with elements greater than the pivot. It then recursively sorts the two parts, and concatenates them with the pivot in the middle. It continues this process until the array is sorted.
Please note that this is a simple implementation of quick sort and may not be the most efficient for large lists. For large lists, a more complex version of quick sort that uses a partition function and swaps elements in place would be more efficient.
"""



数据集开源


同时,CodeFuse项目开源了两个数据集,CodeExercise-Python-27kEvol-instruction-66k


CodeExercise-Python-27k由2.7万道Python编程练习题(英文)组成,覆盖基础语法与数据结构、算法应用、数据库查询、机器学习等数百个Python相关知识点。


CodeExercise-Python-27k 数据集链接:https://modelscope.cn/datasets/codefuse-ai/CodeExercise-Python-27k/summary


Evol-instruction-66k是根据论文《WizardCoder: Empowering Code Large Language Models with Evol-Instruct》中提到的方法,通过添加复杂的代码指令来增强预训练代码大模型的微调效果。 该数据是在开源数据集Evol-Instruct-Code-80k-v1基础上对数据进行了一系列处理,包括低质量过滤、HumanEval评测相似数据过滤等,从原始80k数据筛选后得到66k高质量训练微调数据。


Evol-instruction-66k数据集链接:https://modelscope.cn/datasets/codefuse-ai/Evol-instruction-66k/summary


体验链接:

https://modelscope.cn/studios/codefuse-ai/CodeFuse-CodeLlama34B-MFT-Demo/summary


相关文章
|
4月前
|
人工智能 达摩院 自然语言处理
超好用的开源模型平台,ModelScope阿里达摩院
超好用的开源模型平台,ModelScope阿里达摩院
328 1
|
4月前
|
物联网 机器人 Swift
|
4月前
|
存储 人工智能 自然语言处理
社区供稿 | 开放开源!蚂蚁集团浙江大学联合发布开源大模型知识抽取框架OneKE
OneKE 是由蚂蚁集团和浙江大学联合研发的大模型知识抽取框架,具备中英文双语、多领域多任务的泛化知识抽取能力,并提供了完善的工具链支持。OneKE 以开源形式贡献给 OpenKG 开放知识图谱社区。
|
6天前
|
机器学习/深度学习 人工智能 自然语言处理
社区供稿 | 元象发布255B大规模MoE开源大模型,落地应用登顶港台榜
元象XVERSE发布 中国最大MoE开源模型:XVERSE-MoE-A36B,加速AI应用低成本部署,将国产开源提升至国际领先水平。
社区供稿 | 元象发布255B大规模MoE开源大模型,落地应用登顶港台榜
|
2月前
|
人工智能 JSON 文字识别
开源VLM新标杆 InternVL 2.0 怎么用?部署、微调尽在魔搭社区!
7月4日下午,世界人工智能大会科学前沿论坛,上海人工智能实验室OpenGVLab发布了InternVL 2.0 版本,中文名书生·万象。
|
4月前
|
数据采集 机器学习/深度学习 存储
性能提升30%!中国电信进一步开源12B星辰大模型TeleChat-12B!魔搭社区最佳实践来啦!
中国电信人工智能研究院开源12B参数规模星辰语义大模型TeleChat-12B,相较1月开源7B版本,内容、性能和应用等方面整体效果提升30%,其中,多轮推理、安全问题等领域提升超40%。在C-eval、MMLU、AGIEVAL等国际权威榜单上,排名处于国内同级别参数开源模型的前列,进一步促进大模型开源生态繁荣,助力AI产业加速高质量发展。另据悉,中国电信人工智能研究院将于年内开源千亿级参数大模型。
|
4月前
|
人工智能 文字识别 物联网
新一代端侧模型,面壁 MiniCPM 2.0开源,魔搭社区最佳实践
MiniCPM-V 2.0 不仅带来优秀端侧多模态通用能力,更带来惊艳的 OCR 表现。通过自研的高清图像解码技术,可以突破传统困境,让更为精准地识别充满纷繁细节的街景、长图在端侧成为可能。
|
4月前
|
人工智能 自然语言处理 数据可视化
书生·浦语 2.0 开源!回归语言建模本质,综合性能领先开源社区,魔搭最佳实践来啦!
1月17日,上海人工智能实验室与商汤科技联合香港中文大学和复旦大学正式发布新一代大语言模型书生·浦语2.0(InternLM2),模型开源可商用,魔搭社区作为首发平台,支持大家第一时间下载体验。
|
4月前
|
机器学习/深度学习 人工智能 分布式计算
外滩大会蚂蚁开源大规模图学习系统AGL
AGL 将持续的系统优化和能力创新,并将优秀的系统和算法实践开放到社区,本次开源为 AGL v0.1 版本。
外滩大会蚂蚁开源大规模图学习系统AGL
|
11月前
|
人工智能 JavaScript IDE
蚂蚁智能研发助手CodeFuse来了!支持40余种编程语言
祝各位开发者节日快乐!今天,在这个特殊的日子里,我为大家带来一份小礼物——蚂蚁出品的智能研发助手 CodeFuse~
367 0
蚂蚁智能研发助手CodeFuse来了!支持40余种编程语言