Downloads · 30 days
39
7% of all-time downloads
HIT-SCIR/Abacus-gguf
Abacus-gguf is a machine learning model from HIT-SCIR. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
<div align="center" <img src="./picture/1.PNG" width="40%" alt="Abacus" / </div <hr <div align="center" style="line-height: 1;" <img alt="Homepage" src="https://img.shields.io/badge/Abacus-Homepage-blue?style=flat-squ…
Downloads · 30 days
39
7% of all-time downloads
All-time downloads
572
Public
Repo size
4.7 GB
Likes
0
Public
Click a slice to open those files.
.gguf4.7 GB · 100%
From the Hugging Face model README
从DeepMind发布的AlphaCode在竞赛级编程能力上超越人类平均水平之日起,代码大模型便广受关注。与此同时,OpenAI发布的CodeX更是展示出了代码大模型具有超越传统编程范畴的数值推理、逻辑推断、工具调用等高阶能力,进一步引爆了对该领域的研究与讨论。以BigCode StarCoder为代表的开源项目对完善该领域的研究生态做出了卓越的贡献。然而,目前开源代码大模型提升编程能力的同时会严重损害通用语言能力。为此,哈尔滨工业大学社会计算与信息检索研究中心(HIT-SCIR)推出了<strong>“珠算”代码大模型</strong>,其以2.7B参数在代码与通用语言平均性能上均超越了DeepSeek-Coder-1.3B、Yi-Coder-1.5B、Stable Code-3B、Granite-3B-Code等参数量3B及以下的代码大模型,希望通过开放权重、训练细节以及配套的微调适配平台与插件,助力开源社区的发展。
<p align="center"> <img width="60%" src="picture/3-1.png"> </p>| 模型名称 | 文件大小 | 下载地址 | 备注 |
|---|---|---|---|
| Abacus | 5GB | 🤗HuggingFace<br>ModelScope | Abacus完整模型 |
| Abacus-gguf | 1.7GB(Q4_K_M)<br>2.7GB(Q8_0) | 🤗HuggingFace<br>ModelScope | 珠算GGUF版本,适用于llama.cpp、Ollama等推理框架 |
模型代码生成能力的评估主要基于以下评测基准:
| 模型名称 | HumanEval | HumanEval+ | MBPP(sanitized) | MBPP+ | LiveCodeBench | AVG |
|---|---|---|---|---|---|---|
| Granite-3B-Code-Instruct | 45.73 | 39.63 | 53.70 | 41.10 | 7.46 | 37.52 |
| Stable-Code-Instruct-3B | 67.07 | 56.71 | 57.20 | 37.59 | 11.43 | 46.00 |
| Yi-Coder-1.5B-Chat | 67.68 | 60.37 | 61.87 | 48.37 | 8.22 | 49.30 |
| DeepSeek-Coder-1.3B-Instruct | 65.24 | 59.15 | 56.03 | 45.36 | 7.00 | 46.56 |
| 珠算 | 71.95 | 65.85 | 57.98 | 43.36 | 9.06 | 49.64 |
在国内外3B以下代码大模型中,珠算大模型在五个主流代码评测基准上的综合表现达到最佳,各项指标均处于领先水平。其中,在Humaneval和Humaneval+基准上的表现尤为突出;在MBPP(sanitized)和MBPP+基准上的表现略逊于最新发布的Yi-Coder-1.5B-chat;而在LiveCodeBench基准上的表现仅次于Stable-Code-Instruct-3B。
通用语言能力的评估主要基于以下评测基准:
| 模型名称 | MMLU | HellaSwag | ARC-e | BBH | C-Eval | CMMLU | GSM8K | AVG |
|---|---|---|---|---|---|---|---|---|
| Granite-3B-Code-Instruct | 29.95 | 26.82 | 47.62 | 35.87 | 32.30 | 30.77 | 56.48 | 37.12 |
| Stable-Code-Instruct-3B | 29.34 | 32.15 | 34.74 | 21.69 | 28.61 | 29.18 | 15.92 | 27.37 |
| Yi-Coder-1.5B-Chat | 33.98 | 28.52 | 40.04 | 34.40 | 31.88 | 31.88 | 10.16 | 30.12 |
| DeepSeek-Coder-1.3B-Instruct | 26.68 | 25.25 | 27.69 | 7.48 | 25.61 | 26.88 | 9.63 | 21.32 |
| 珠算 | 40.18 | 53.23 | 66.67 | 36.08 | 36.00 | 36.84 | 46.32 | 45.05 |
在国内外3B以下代码大模型中,珠算大模型在七个主流通用语言评测基准上的综合表现达到最佳,且具有明显优势。除在数学推理GSM8K基准上低于Granite-3B-Code-Instruct,其余各项指标均达到最优;通用语言能力与通用大模型MiniCPM-2B-sft-bf16还有一定差距,后续版本将对此进行强化,以此带来更自然、更流畅的对话,以及对用户需求更充分的理解,最终在自动化编程辅助、代码智能体领域有更加广阔的应用前景。
微调数据处理:我们提出了Semi-Instruct,结合了Natural-Instruct(自动收集)和Self-Instruct(模型合成)两种方式。首先,通过类似Self-Instruct的方法,修复Natural-Instruct代码的规范性问题并补充缺失的指令。同时,生成测试用例的输入,利用原始代码的正确性,执行原始代码获得输出。然后,利用完整的测试样例验证新代码的正确性。最终,为去除不同来源的数据之间的重复样本,我们借助基于句子嵌入的SemDeDup方法对数据整体进行了深层语义去重,确保了微调数据的多样性。
微调策略:为充分激发模型预训练阶段习得的能力,微调阶段的数据配比与超参数设置训练尽可能地与预训练退火阶段保持了对齐,以减小两者之间的差距。具体而言,微调数据量约80万条,共训练3个epoch。学习率(1.6e-4)、数据配比与退火阶段保持一致。数据来源上,Code数据主要来自一些高质量的开源Code数据,NL数据我们则使用了Infinity-Instruct-7M数据中的Math、Commonsense和Subjective3个类别的数据。## 1.模型介绍
预训练数据组成:
珠算大模型将packing策略(即将不同长度的样本拼接后整体作为一条训练数据)优化为了Block Attention Mask,将训练数据内部每个样本的注意力机制范围限制在自身,避免了样本间的污染,如下图所示。
下载Ollama并启动Ollama service:
ollama serve
运行珠算大模型:
ollama run HIT-SCIR/abacus
transformers支持为tokenizer添加聊天模板,并支持流式生成。示例代码如下:
# example/transformers-stream/stream.py
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
model_id = "HIT-SCIR/abacus"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
)
chat = [
{"role": "user", "content": "请你用python写一段快速排序的代码"},
]
inputs = tokenizer.apply_chat_template(
chat,
tokenize=True,
add_generation_prompt=True,
return_tensors="pt",
).to(0)
stream_output = model.generate(
inputs,
streamer=TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True),
temperature=0.8,
top_p=0.9,
max_new_tokens=2048,
)
</details>
ModelScope的接口与Transformers非常相似,只需将transformers替换为modelscope即可:
# example/modelscope-generate/generate.py
import torch
from modelscope import AutoTokenizer, AutoModelForCausalLM
model_id = "HIT-SCIR/abacus"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
)
text = "<用户>请你用python写一段快速排序的代码<AI>"
inputs = tokenizer(text, return_tensors="pt").to(0)
outputs = model.generate(
**inputs,
temperature=0.8,
top_p=0.9,
max_new_tokens=2048,
)
print(tokenizer.decode(outputs[0], skip_special_tokens=False))
</details>
珠算支持通过vLLM实现推理加速,示例代码如下:
# example/vllm-generate/generate.py
from vllm import LLM, SamplingParams
llm = LLM(
model="HIT-SCIR/abacus",
tensor_parallel_size=1,
trust_remote_code=True,
)
sampling_params = SamplingParams(
temperature=0.8, top_p=0.95, max_tokens=2048
)
prompts = [
"<用户>请你用python写一段快速排序的代码<AI>",
]
outputs = llm.generate(prompts, sampling_params)
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(generated_text)
</details>
GGUF格式旨在快速加载和保存模型,由llama.cpp团队推出,适用于llama.cpp、Ollama等框架。您可以手动将HuggingFace格式的珠算转换到GGUF格式。下面介绍使用llama.cpp转GGUF的方法和部署步骤。
首先需要下载llama.cpp的源码。
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
然后需要进行编译,推荐使用cmake。根据您的硬件平台,编译命令有细微差异:
# cpu
cmake -B build_cpu
cmake --build build_cpu --config Release
# cuda
cmake -B build_cuda -DGGML_CUDA=ON
cmake --build build_cuda --config Release -j 12
以下命令需要在llama.cpp/目录下:
转换为GGUF格式
python convert.py --outfile /path/to/Abacus.gguf /path/to/Abacus
进行GGUF格式的Q4_K_M量化,以下命令需要在llama.cpp/build_cpu/bin或者llama.cpp/build_cuda/bin目录下(依赖于编译的平台):
./llama-quantize /path/to/Abacus.gguf /path/to/Abacus-Q4_K_M.gguf Q4_K_M
以下命令需要在llama.cpp/build_cpu/bin或者llama.cpp/build_cuda/bin目录下(依赖于编译的平台):
./llama-cli -m /path/to/Abacus.gguf -p "<用户>帮我写一个快速排序代码<AI>" -n 128
关于main的更多参数,可以参考llama.cpp的官方文档。
GGUF格式模型同样可以使用Ollama部署。下面介绍简要步骤。
这里使用仓库release的压缩包来免root安装,更多安装方法可以参考Ollama官方的安装教程。
wget https://github.com/ollama/ollama/releases/download/v0.3.10/ollama-linux-amd64.tgz
tar -C /path/to/ollama -xzf /path/to/ollama-linux-amd64.tgz
cd /path/to/ollama/bin
构建Modelfile,指定导入GGUF模型路径,其内容示例如下,更多参数设置可参考官方文档。
FROM /path/to/Abacus.gguf
Ollama创建模型
./ollama create Abacus -f path/to/Modelfile
同样在path/to/ollama/bin路径下:
./ollama run Abacus
>>> <用户>帮我写一个快速排序代码<AI>
</details>
基于珠算大模型的编程能力,我们面向VSCode平台构建了编程辅助插件。插件可以一键式安装,支持代码生成、代码补全、代码摘要等功能,根据用户已经输入的内容预测后续的代码或注释,有效提高开发效率。
<p align="center"> <img width="100%" src="./picture/4-5.gif"> </p> 由于珠算大模型具有良好的中文理解能力,用户可以直接用中文写注释来表达需求。 <p align="center"> <img width="100%" src="./picture/4-6.gif"> </p> 插件将于测试完毕后在VSCode应用市场发布。对本仓库源码的使用遵循开源许可协议 Apache 2.0。
珠算支持商用。如果将珠算模型或其衍生品用作商业用途,请您按照如下方式联系许可方,以进行登记并向许可方申请书面授权:联系邮箱:[email protected]。