π©Β Models | πΒ Dataset | πΒ Quick Start | πΒ Demo | πΒ Citation | πΒ Acknowledgements
Important
We are keeping improving the documents and adding more implementation details. Please stay tuned!
- π©Magicoder is a model family empowered by πͺOSS-Instruct, a novel approach to enlightening LLMs with open-source code snippets for generating low-bias and high-quality instruction data for code.
- πͺOSS-Instruct mitigates the inherent bias of the LLM-synthesized instruction data by empowering them with a wealth of open-source references to produce more diverse, realistic, and controllable data.
Model | Checkpoint | Size | HumanEval (+) | MBPP (+) | Demo | License |
---|---|---|---|---|---|---|
Magicoder-CL-7B | π€ HF Link | 7B | 60.4 (55.5) | 64.2 (52.6) | -- | Llama2 |
Magicoder-S-CL-7B | π€ HF Link | 7B | 70.7 (66.5) | 68.4 (56.6) | -- | Llama2 |
Magicoder-DS-6.7B | π€ HF Link | 6.7B | 66.5 (60.4) | 75.4 (61.9) | -- | DeepSeek |
Magicoder-S-DS-6.7B | π€ HF Link | 6.7B | 76.8 (70.7) | 75.7 (64.4) | Demo* | DeepSeek |
*Demo link will expire on 12/8/2023.
- Magicoder-OSS-Instruct-75K: generated through OSS-Instruct using
gpt-3.5-turbo-1106
and used to train both Magicoder and Magicoder-S series. - Magicoder-Evol-Instruct-110K: decontaminated and redistributed from theblackcat102/evol-codealpaca-v1, used to further finetune Magicoder series and obtain Magicoder-S models.
from transformers import pipeline
import torch
MAGICODER_PROMPT = """You are an exceptionally intelligent coding assistant that consistently delivers accurate and reliable responses to user instructions.
@@ Instruction
{instruction}
@@ Response
"""
instruction = "Implement a high-level API for a TODO list application. The API takes as input an operation request and updates the TODO list in place. If the request is invalid, raise an exception."
prompt = MAGICODER_PROMPT.format(instruction=instruction)
generator = pipeline(
model="ise-uiuc/Magicoder-S-DS-6.7B",
task="text-generation",
torch_dtype=torch.bfloat16,
device_map="auto",
)
result = generator(prompt, max_length=2048, num_return_sequences=1, temperature=0.0)
print(result[0]["generated_text"])
This code snippet will generate the following output:
Here is a simple Python implementation of a TODO list API:
```python
class TodoList:
def __init__(self):
self.todo_list = []
def add_task(self, task):
if not isinstance(task, str):
raise ValueError("Task must be a string")
self.todo_list.append(task)
def remove_task(self, task):
if task not in self.todo_list:
raise ValueError("Task not found in the list")
self.todo_list.remove(task)
def get_tasks(self):
return self.todo_list
def update_task(self, old_task, new_task):
if old_task not in self.todo_list:
raise ValueError("Old task not found in the list")
if not isinstance(new_task, str):
raise ValueError("New task must be a string")
index = self.todo_list.index(old_task)
self.todo_list[index] = new_task
def clear_list(self):
self.todo_list = []
```
This API allows you to add tasks, remove tasks, get all tasks, update tasks, and clear the list. It also raises exceptions for invalid operations.
You can use this API like this:
```python
todo = TodoList()
todo.add_task("Buy groceries")
todo.add_task("Finish project")
print(todo.get_tasks()) # Output: ['Buy groceries', 'Finish project']
todo.update_task("Buy groceries", "Buy fruits")
print(todo.get_tasks()) # Output: ['Buy fruits', 'Finish project']
todo.remove_task("Finish project")
print(todo.get_tasks()) # Output: ['Buy fruits']
todo.clear_list()
print(todo.get_tasks()) # Output: []
```
We follow WizardCoder and provide the script to build a local demo server with gradio. Refer to /demo for more information.
Here are some interesting examples showing Magicoder's improvements over base models:
Magicoder's Understanding Ability
We create the following two examples by making two original HumanEval problems more complicated. While both Magicoder-S-DS-6.7B and deepseek-coder-6.7b-base, which is Magicoder's base model, can solve the original HumanEval problem, only our Magicoder-S-DS-6.7B can solve the new complicated problems.
Original Problem:
Write a function to, given list of integers, return list in "strange" order. "Strange" sorting, is when you start with the minimum value, then maximum of the remaining integers, then minimum and so on.
New Problem:
Write a function to, given list of integers, return list in "ascending" order. "Ascending" sorting, is when you start with the minimum value, then maximum of the remaining integers, then minimum and so on.
This problem is challenging because we change the name of a new way (not ascending) to sort integers from "strange" to "ascending". The model should understand that the word "ascending" here has a new meaning based on both the context and the fact that it is surrounded by quotation marks. As is shown in the following responses to the new problem from two models, Magicoder-S-DS-6.7B successfully understands this complicated requirement, while deepseek-coder-6.7b-base is misled and sort integers in ascending order instead.
Response to New Problem:
# Magicoder-S-DS-6.7B (Correct)
def ascending_sort(lst):
sorted_lst = []
while lst:
min_val = min(lst)
sorted_lst.append(min_val)
lst.remove(min_val)
if lst:
max_val = max(lst)
sorted_lst.append(max_val)
lst.remove(max_val)
return sorted_lst
# deepseek-coder-6.7b-base (Wrong)
def sort_ascending(lst):
lst.sort()
return lst
Original Problem:
Write a function that takes an integer a and returns True if this ingeger is a cube of some integer number. Note: you may assume the input is always valid.
New Problem:
Write a function that takes an integer a and returns True if this ingeger is a cube of some integer number. Note: you should check whether the input is valid.
This problem is challenging because we ask the model to check the inputs' validity rather than assuming the input is always valid. While Magicoder-S-DS-6.7B successfully check the validity of the input, deepseek-coder-6.7b-base wrongly sets a < 0
as the criterion of invalidity and thus fails to solve the problem.
Response to New Problem:
# Magicoder-S-DS-6.7B (Correct)
def is_cube(a):
if not isinstance(a, int):
return False
if a < 0:
a = -a
return round(a ** (1. / 3)) ** 3 == a
# deepseek-coder-6.7b-base (Wrong)
def is_cube(a):
if a < 0:
return False
else:
for i in range(1, a):
if i**3 == a:
return True
return False
Magicoder's Ability to Use External Libraries
We create the following example that requires models to use external libraries for the certain task. While our Magicoder-S-DS-6.7B successfully follow the instruction in the example, both deepseek-coder-6.7b-base and deepseek-coder-6.7b-instruct tend to miss some requirements in the instruction.
Prompt:
Write a gradio application for the following use case: Take an input image and return a 45 degree clockwise rotated image. You should also add text description under the output showing the rotation degree.
This instruction is challenging because our Magicoder's training dataset does not contain the library "gradio" that is necessary for this task. Here are the gradio applications that Magicoder-S-DS-6.7B, deepseek-coder-6.7b-instruct, and deepseek-coder-6.7b-base construct respectively:
Magicoder-S-DS-6.7B: Correct!
Magicoder-S-DS-6.7B successfully performs the 45-degree rotation on the input image in the clockwise direction. As required in the instruction, it adds the text description under the output.
Deepseek-coder-6.7b-instruct: Wrong...
Deepseek-coder-6.7b-instruct wrongly performs the 45-degree rotation on the input image in the counterclockwise direction. It also adds the text description under the output.
Deepseek-coder-6.7b-base: Wrong...
Deepseek-coder-6.7b-base also wrongly performs the 45-degree rotation on the input image in the counterclockwise direction. Even worse, it misses the text description under the output.
@misc{magicoder,
title={Magicoder: Source Code Is All You Need},
author={Yuxiang Wei and Zhe Wang and Jiawei Liu and Yifeng Ding and Lingming Zhang},
year={2023},
eprint={2312.02120},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
- WizardCoder: Evol-Instruct
- DeepSeek-Coder: Base model for Magicoder-DS
- CodeLlama: Base model for Magicoder-CL
- StarCoder: Data decontamination
-
Bias, Risks, and Limitations: Magicoders may sometimes make errors, produce misleading contents, or struggle to manage tasks that are not related to coding.
-
Usage: Magicoder models are trained on the synthetic data generated by OpenAI models. Please pay attention to OpenAI's terms of use when using the models and the datasets. Magicoders will not compete with any OpenAI's commercial product.