Welcome to the official repository of aiXcoder-7B Code Large Language Model. This model is designed to understand and generate code across multiple programming languages, offering state-of-the-art performance in code completion, comprehension, generation, and more tasks about programming languages.
As the capabilities of large code models are gradually being unearthed, aiXcoder has consistently pondered on how to make these models more beneficial in real development scenarios. To this end, we have open-sourced aiXcoder 7B Base, which has undergone extensive training on 1.2T Unique Tokens, and the model's pre-training tasks as well as the contextual information have been uniquely designed for real-world code generation contexts.
aiXcoder 7B Base stands out as the most effective model in code completion scenarios among all models of similar parameter sizes, and it also surpasses mainstream models like codellama 34B and StarCoder2 15B in the average performance on the multilingual nl2code benchmark.
In our ongoing exploration to apply large code models, the release of aiXcoder 7B Base represents a significant milestone. The current version of aiXcoder 7B Base is a foundational model that focuses on improving the efficiency and accuracy of code completion and code generation tasks, aiming to provide robust support for developers in these scenarios. It is important to note that this version has not undergone specific instruct-tuning, which means it might not yet offer optimal performance for specialized higher-level tasks such as test case generation and code debugging.
However, we have plans for further development of the aiXcoder model series already in motion. In the near future, we aim to release new versions of the model that have been meticulously instruct-tuned for a wider range of programming tasks, including but not limited to test case generation and code debugging. Through these instruct-tuned models, we anticipate offering developers more comprehensive and deeper programming support, helping them to maximize efficiency at every stage of software development.
Quickstart
Environment Requirements
Option 1: Build Env
To run the model inference code, you'll need the following environment setup:
Python 3.8 or higher
PyTorch 2.1.0 or higher
sentencepiece 0.2.0 or higher
transformers 4.34.1 or higher (if run inference by transformers library)
Please ensure all dependencies are installed using the following command:
requirements.txt listed all necessary libraries and their versions.
To achieve faster inference speeds, especially for large models, we recommend installing flash attention. Flash attention is an optimized attention mechanism that significantly reduces computation time for transformer-based models without sacrificing accuracy.
Before proceeding, ensure your environment meets the CUDA requirements as flash attention leverages GPU acceleration. Follow these steps to install flash attention:
For a consistent and isolated environment, we recommend running the model inference code using Docker. Here's how to set up and use Docker for our model:
Install Docker: If you haven't already, install Docker on your machine.
Pull the Docker Image: Pull the Docker image from Docker Hub.
Replace "path/to/model_weights_dir" with the actual path to your downloaded model weights.
or run inference with huggingface's transformers:
python sess_huggingface.py
Python Script Execution
Alternatively, you can invoke the model programmatically within your Python scripts. This method provides more flexibility for integrating the model into your applications or workflows. Here's a simple example on how to do it:
python
12from sess_megatron import TestInference
34infer = TestInference()5res = infer.run_infer(6# for FIM style input, code_string stands for prefix context7 code_string="""# 快速排序算法""",8# for FIM style input, later_code stands for suffix context9 later_code="\n",10# file_path should be a path from project to file11 file_path="test.py",12# max num for generated tokens13 max_new_tokens=256,14)15print(res)1617"""output:
1819def quick_sort(arr):
20 if len(arr) <= 1:
21 return arr
22 pivot = arr[0]
23 less = [i for i in arr[1:] if i <= pivot]
24 greater = [i for i in arr[1:] if i > pivot]
25 return quick_sort(less) + [pivot] + quick_sort(greater)
262728# 测试
29arr = [3, 2, 1, 4, 5]
30print(quick_sort(arr)) # [1, 2, 3, 4, 5]
31"""32
python
123import torch
4import sys
5from hf_mini.utils import input_wrapper
6from transformers import AutoModelForCausalLM, AutoTokenizer
78device ="cuda"# the device to load the model onto910tokenizer = AutoTokenizer.from_pretrained("aiXcoder/aixcoder-7b-base")11model = AutoModelForCausalLM.from_pretrained("aiXcoder/aixcoder-7b-base", torch_dtype=torch.bfloat16)121314text = input_wrapper(15# for FIM style input, code_string stands for prefix context16 code_string="# 快速排序算法",17# for FIM style input, later_code stands for suffix context18 later_code="\n# 测试\narr = [3, 2, 1, 4, 5]\nprint(quick_sort(arr)) # [1, 2, 3, 4, 5]",19# file_path should be a path from project to file20 path="test.py"21)2223iflen(text)==0:24 sys.exit()2526inputs = tokenizer(text, return_tensors="pt", return_token_type_ids=False)2728inputs = inputs.to(device)29model.to(device)3031outputs = model.generate(**inputs, max_new_tokens=256)32print(tokenizer.decode(outputs[0], skip_special_tokens=False))33343536"""output:
37def quick_sort(arr):
38 # 如果数组长度小于等于1,直接返回
39 if len(arr) <= 1:
40 return arr
41 # 选择数组的第一个元素作为基准
42 pivot = arr[0]
43 # 初始化左右指针
44 left, right = 1, len(arr) - 1
45 # 循环直到左指针小于右指针
46 while left < right:
47 # 从右到左找到第一个小于基准的元素,与左指针元素交换
48 if arr[right] < pivot:
49 arr[left], arr[right] = arr[right], arr[left]
50 left += 1
51 # 从左到右找到第一个大于等于基准的元素,与右指针元素交换
52 if arr[left] >= pivot:
53 right -= 1
54 # 将基准元素与左指针元素交换
55 arr[left], arr[0] = arr[0], arr[left]
56 # 对左半部分进行递归排序
57 quick_sort(arr[:left])
58 # 对右半部分进行递归排序
59 quick_sort(arr[left + 1:])
60 return arr</s>
61"""62
License
The model weights are licensed under the Model License for academic research use; for commercial use, please apply by sending an email to support@aiXcoder.com.
Acknowledgments
We would like to thank all contributors to the open-source projects and datasets that made this work possible.
Thank you for your interest in our Code Large Language Model. We look forward to your contributions and feedback!