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:
1import os
2import torch
3import time
4from transformers import AutoTokenizer
5from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
67os.environ["TOKENIZERS_PARALLELISM"]="false"89defload_model_tokenizer(model_name_or_local_path):10"""
11 Load model and tokenizer based on the given model name or local path of the downloaded model.
12 """13 tokenizer = AutoTokenizer.from_pretrained(model_name_or_local_path,14 trust_remote_code=True,15 use_fast=False,16 legacy=False)17 tokenizer.padding_side ="left"1819 model = AutoGPTQForCausalLM.from_quantized(model_name_or_local_path,20 inject_fused_attention=False,21 inject_fused_mlp=False,22 use_cuda_fp16=True,23 disable_exllama=False,24 device_map='auto'# Support multi-gpus25)26return model, tokenizer
272829definference(model, tokenizer, prompt):30"""
31 Uset the given model and tokenizer to generate an answer for the specified prompt.
32 """33 st = time.time()34 prompt = prompt if prompt.endswith('\n')elsef'{prompt}\n'35 inputs =f"<|role_start|>human<|role_end|>{prompt}<|role_start|>bot<|role_end|>"3637 input_ids = tokenizer.encode(inputs,38 return_tensors="pt",39 padding=True,40 add_special_tokens=False).to("cuda")41with torch.no_grad():42 generated_ids = model.generate(43 input_ids=input_ids,44 top_p=0.95,45 temperature=0.1,46 do_sample=True,47 max_new_tokens=512,48 eos_token_id=tokenizer.eos_token_id,49 pad_token_id=tokenizer.pad_token_id
50)51print(f'generated tokens num is {len(generated_ids[0][input_ids.size(1):])}')52 outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)53print(f'generate text is {outputs[0][len(inputs): ]}')54 latency = time.time()- st
55print('latency is {} seconds'.format(latency))565758if __name__ =="__main__":59 model_name_or_local_path ='<Mole name (i.e. codefuse-ai/CodeFuse-CodeLlama-34B-4bits) or local path of the downloaded model>'60 prompt ='Please write a QuickSort program in Python'6162 model, tokenizer = load_model_tokenizer(model_name_or_local_path)63 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}
}
1import os
2import torch
3import time
4from transformers import AutoTokenizer
5from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
67os.environ["TOKENIZERS_PARALLELISM"]="false"89defload_model_tokenizer(model_name_or_local_path):10"""
11 Load model and tokenizer based on the given model name or local path of downloaded model.
12 """13 tokenizer = AutoTokenizer.from_pretrained(model_name_or_local_path,14 trust_remote_code=True,15 use_fast=False,16 legacy=False)17 tokenizer.padding_side ="left"1819 model = AutoGPTQForCausalLM.from_quantized(model_name_or_local_path,20 inject_fused_attention=False,21 inject_fused_mlp=False,22 use_cuda_fp16=True,23 disable_exllama=False,24 device_map='auto'# Support multi-gpus25)26return model, tokenizer
272829definference(model, tokenizer, prompt):30"""
31 Uset the given model and tokenizer to generate an answer for the speicifed prompt.
32 """33 st = time.time()34 prompt = prompt if prompt.endswith('\n')elsef'{prompt}\n'35 inputs =f"<|role_start|>human<|role_end|>{prompt}<|role_start|>bot<|role_end|>"3637 input_ids = tokenizer.encode(inputs,38 return_tensors="pt",39 padding=True,40 add_special_tokens=False).to("cuda")41with torch.no_grad():42 generated_ids = model.generate(43 input_ids=input_ids,44 top_p=0.95,45 temperature=0.1,46 do_sample=True,47 max_new_tokens=512,48 eos_token_id=tokenizer.eos_token_id,49 pad_token_id=tokenizer.pad_token_id
50)51print(f'generated tokens num is {len(generated_ids[0][input_ids.size(1):])}')52 outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)53print(f'generate text is {outputs[0][len(inputs): ]}')54 latency = time.time()- st
55print('latency is {} seconds'.format(latency))565758if __name__ =="__main__":59 model_name_or_local_path ='<模型名字 (即codefuse-ai/CodeFuse-CodeLlama-34B-4bits)或者提前下载到本地的模型路径>'60 prompt ='请用Python实现一个快速排序算法'6162 model, tokenizer = load_model_tokenizer(model_name_or_local_path)63 inference(model, tokenizer, prompt)