CodeFuse-CodeLlama-34B-4bits is the 4-bit quantized version of CodeFuse-CodeLlama-34B, which is a 34B Code-LLM fine-tuned over multiple code tasks(600k instrunctions/answers)on the base model CodeLlama-34b-Python.
After undergoing 4-bit quantization, the CodeFuse-CodeLlama-34B-4bits model can be loaded on either a single A10 (24GB VRAM) or a RTX 4090 (24GB VRAM). Moreover, the quantized model still achives an impressive accuracy of 73.8% on the Humaneval pass@1 metric.
News and Updates
🔥🔥🔥 2023-09-26 We are pleased to announce the release of the 4-bit quantized version of CodeFuse-CodeLlama-34B. Despite the quantization process, the model still achieves a remarkable 73.8% accuracy (greedy decoding) on the HumanEval pass@1 metric.
🔥🔥🔥 2023-09-11 CodeFuse-CodeLlama34B has achieved 74.4% of pass@1 (greedy decoding) on HumanEval, which is SOTA results for openspurced LLMs at present.
If you wish to see a demo of the model, you can visit ✨
CodeFuse Demo
✨✨
Performance
Model
HumanEval(pass@1)
Date
CodeFuse-CodeLlama-34B
74.4%
2023.9
CodeFuse-CodeLlama-34B-4bits
73.8%
2023.9
WizardCoder-Python-34B-V1.0
73.2%
2023.8
GPT-4(zero-shot)
67.0%
2023.3
PanGu-Coder2 15B
61.6%
2023.8
CodeLlama-34b-Python
53.7%
2023.8
CodeLlama-34b
48.8%
2023.8
GPT-3.5(zero-shot)
48.1%
2022.11
OctoCoder
46.2%
2023.8
StarCoder-15B
33.6%
2023.5
LLaMA 2 70B(zero-shot)
29.9%
2023.7
GPU Memory Usage
We measured the GPU memory usage after loading the model, as well as the memory usage when encoding 2048/1024 tokens and generating 1024/2048 tokens. The results are presented in the table below.
Precision
Idle Model
Encoding 2048 tokens and Generating 1024 tokens
Encoding 1024 tokens and Generating 2048 tokens
bfloat16
64.89GB
69.31GB
66.41GB
int4
19.09GB
22.19GB
20.78GB
Requirements
python>=3.8
pytorch>=2.0.0
transformers==4.32.0
auto_gptq==0.4.2
Sentencepiece
CUDA 11.4
Inference String Format
The inference string is a concatenated string formed by combining conversation data (human and bot contents) in the training data format. It is used as input during the inference process.
Here is an example format of the concatenated string:
"""<|role_start|>human<|role_end|>Human 1st round input<|role_start|>bot<|role_end|>Bot 1st round output</s><|role_start|>human<|role_end|>Human 2nd round input<|role_start|>bot<|role_end|>Bot 2nd round output</s>.........<|role_start|>human<|role_end|>Human nth round input<|role_start|>bot<|role_end|>{Bot output to be genreated}</s>"""
When applying inference, you always make your input string end with "<|role_start|>bot<|role_end|>" to ask the model generating answers.
import os
import torch
import time
from transformers import AutoTokenizer
from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
os.environ["TOKENIZERS_PARALLELISM"] = "false"defload_model_tokenizer(model_name_or_local_path):
""" Load model and tokenizer based on the given model name or local path of the downloaded model. """
tokenizer = AutoTokenizer.from_pretrained(model_name_or_local_path,
trust_remote_code=True,
use_fast=False,
legacy=False)
tokenizer.padding_side = "left"
model = AutoGPTQForCausalLM.from_quantized(model_name_or_local_path,
inject_fused_attention=False,
inject_fused_mlp=False,
use_cuda_fp16=True,
disable_exllama=False,
device_map='auto'# Support multi-gpus
)
return model, tokenizer
definference(model, tokenizer, prompt):
""" Uset the given model and tokenizer to generate an answer for the specified prompt. """
st = time.time()
prompt = prompt if prompt.endswith('\n') elsef'{prompt}\n'
inputs = f"<|role_start|>human<|role_end|>{prompt}<|role_start|>bot<|role_end|>"
input_ids = tokenizer.encode(inputs,
return_tensors="pt",
padding=True,
add_special_tokens=False).to("cuda")
with torch.no_grad():
generated_ids = model.generate(
input_ids=input_ids,
top_p=0.95,
temperature=0.1,
do_sample=True,
max_new_tokens=512,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id
)
print(f'generated tokens num is {len(generated_ids[0][input_ids.size(1):])}')
outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
print(f'generate text is {outputs[0][len(inputs): ]}')
latency = time.time() - st
print('latency is {} seconds'.format(latency))
if __name__ == "__main__":
model_name_or_local_path = '<Mole name (i.e. codefuse-ai/CodeFuse-CodeLlama-34B-4bits) or local path of the downloaded model>'
prompt = 'Please write a QuickSort program in Python'
model, tokenizer = load_model_tokenizer(model_name_or_local_path)
inference(model, tokenizer, prompt)
The current inference example code is based on
AutoGPTQ
. If you want to achieve higher inference speed, it is recommended to combine it with
TensorRT-LLM (Early Access)
.
Consistency Check
Here, SHA256 values are provided for the model-related files for consistency check during the download.
If you find our
work
useful or helpful for your R&D works, please feel free to cite our paper as below.
@article{mftcoder2023,
title={MFTCoder: Boosting Code LLMs with Multitask Fine-Tuning},
author={Bingchang Liu and Chaoyu Chen and Cong Liao and Zi Gong and Huan Wang and Zhichao Lei and Ming Liang and Dajun Chen and Min Shen and Hailian Zhou and Hang Yu and Jianguo Li},
year={2023},
journal={arXiv preprint arXiv},
archivePrefix={arXiv},
eprint={2311.02303}
}
import os
import torch
import time
from transformers import AutoTokenizer
from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
os.environ["TOKENIZERS_PARALLELISM"] = "false"defload_model_tokenizer(model_name_or_local_path):
""" Load model and tokenizer based on the given model name or local path of downloaded model. """
tokenizer = AutoTokenizer.from_pretrained(model_name_or_local_path,
trust_remote_code=True,
use_fast=False,
legacy=False)
tokenizer.padding_side = "left"
model = AutoGPTQForCausalLM.from_quantized(model_name_or_local_path,
inject_fused_attention=False,
inject_fused_mlp=False,
use_cuda_fp16=True,
disable_exllama=False,
device_map='auto'# Support multi-gpus
)
return model, tokenizer
definference(model, tokenizer, prompt):
""" Uset the given model and tokenizer to generate an answer for the speicifed prompt. """
st = time.time()
prompt = prompt if prompt.endswith('\n') elsef'{prompt}\n'
inputs = f"<|role_start|>human<|role_end|>{prompt}<|role_start|>bot<|role_end|>"
input_ids = tokenizer.encode(inputs,
return_tensors="pt",
padding=True,
add_special_tokens=False).to("cuda")
with torch.no_grad():
generated_ids = model.generate(
input_ids=input_ids,
top_p=0.95,
temperature=0.1,
do_sample=True,
max_new_tokens=512,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id
)
print(f'generated tokens num is {len(generated_ids[0][input_ids.size(1):])}')
outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
print(f'generate text is {outputs[0][len(inputs): ]}')
latency = time.time() - st
print('latency is {} seconds'.format(latency))
if __name__ == "__main__":
model_name_or_local_path = '<模型名字 (即codefuse-ai/CodeFuse-CodeLlama-34B-4bits)或者提前下载到本地的模型路径>'
prompt = '请用Python实现一个快速排序算法'
model, tokenizer = load_model_tokenizer(model_name_or_local_path)
inference(model, tokenizer, prompt)
CodeFuse-CodeLlama-34B-4bits huggingface.co is an AI model on huggingface.co that provides CodeFuse-CodeLlama-34B-4bits's model effect (), which can be used instantly with this codefuse-ai CodeFuse-CodeLlama-34B-4bits model. huggingface.co supports a free trial of the CodeFuse-CodeLlama-34B-4bits model, and also provides paid use of the CodeFuse-CodeLlama-34B-4bits. Support call CodeFuse-CodeLlama-34B-4bits model through api, including Node.js, Python, http.
CodeFuse-CodeLlama-34B-4bits huggingface.co is an online trial and call api platform, which integrates CodeFuse-CodeLlama-34B-4bits's modeling effects, including api services, and provides a free online trial of CodeFuse-CodeLlama-34B-4bits, you can try CodeFuse-CodeLlama-34B-4bits online for free by clicking the link below.
codefuse-ai CodeFuse-CodeLlama-34B-4bits online free url in huggingface.co:
CodeFuse-CodeLlama-34B-4bits is an open source model from GitHub that offers a free installation service, and any user can find CodeFuse-CodeLlama-34B-4bits on GitHub to install. At the same time, huggingface.co provides the effect of CodeFuse-CodeLlama-34B-4bits install, users can directly use CodeFuse-CodeLlama-34B-4bits installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
CodeFuse-CodeLlama-34B-4bits install url in huggingface.co: