Home

Awesome

🎩 Magicoder: Source Code Is All You Need

<p align="left"> <a href="https://openreview.net/forum?id=XUeoOBid3x"><img src="https://img.shields.io/badge/Paper-ICML'24-a55fed.svg?style=for-the-badge" alt="Paper" class="img-fluid"/></a> <a href="https://arxiv.org/abs/2312.02120"><img src="https://img.shields.io/badge/arXiv-2312.02120-b31b1b.svg?style=for-the-badge"> <a href="https://opensource.org/license/mit/"><img src="https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge"> <a href="https://huggingface.co/ise-uiuc/"><img src="https://img.shields.io/badge/πŸ€—%20Hugging%20Face-ise--uiuc-%23ff8811.svg?style=for-the-badge"> <a href="https://twitter.com/magicoder_ai"><img src="https://img.shields.io/badge/@magicoder__ai-000000?style=for-the-badge&logo=x&logoColor=white"> </p> <p align="left"> 🎩&nbsp;<a href="#-models">Models</a> | πŸ“š&nbsp;<a href="#-dataset">Dataset</a> | πŸš€&nbsp;<a href="#-quick-start">Quick Start</a> | πŸ‘€&nbsp;<a href="#-demo">Demo</a> | πŸ“&nbsp;<a href="#-citation">Citation</a> | πŸ™&nbsp;<a href="#-acknowledgements">Acknowledgements</a> </p>

We are thrilled that Magicoder and OSS-Instruct have inspired many amazing projects, including:

Contact: Yuxiang Wei, Zhe Wang, Yifeng Ding, Jiawei Liu, Lingming Zhang.

About

[!IMPORTANT]

Overview of OSS-Instruct Overview of Result

🎩 Models

ModelCheckpointSizeHumanEval (+)MBPP (+)License
Magicoder-CL-7BπŸ€— HF Link7B60.4 (55.5)64.2 (52.6)Llama2
Magicoder-S-CL-7BπŸ€— HF Link7B70.7 (66.5)68.4 (56.6)Llama2
Magicoder-DS-6.7BπŸ€— HF Link6.7B66.5 (60.4)75.4 (61.9)DeepSeek
Magicoder-S-DS-6.7BπŸ€— HF Link6.7B76.8 (70.7)75.7 (64.4)DeepSeek

πŸ‘€ Demo

Online Gradio Demo

Quickly try out our Magicoder Playground powered by gradio! Huge thanks to AK(@_akhaliq) and the HuggingΒ Face team for their support!

Local Gradio Demo

We follow WizardCoder and provide the script to build a local demo server. You can launch your local gradio demo as following:

cd demo
CUDA_VISIBLE_DEVICES=0 python magicoder_demo.py \
   --base_model "ise-uiuc/Magicoder-S-DS-6.7B" \
   --device "cuda:0" \
   --port 8080

πŸ“š Dataset

πŸš€ Quick Start

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: []
```

πŸ“ Citation

@InProceedings{wei2024magicoder,
  title = 	 {Magicoder: Empowering Code Generation with {OSS}-Instruct},
  author =       {Wei, Yuxiang and Wang, Zhe and Liu, Jiawei and Ding, Yifeng and Zhang, Lingming},
  booktitle = 	 {Proceedings of the 41st International Conference on Machine Learning},
  pages = 	 {52632--52657},
  year = 	 {2024},
  volume = 	 {235},
  series = 	 {Proceedings of Machine Learning Research},
  month = 	 {21--27 Jul},
  publisher =    {PMLR},
  pdf = 	 {https://raw.githubusercontent.com/mlresearch/v235/main/assets/wei24h/wei24h.pdf},
  url = 	 {https://proceedings.mlr.press/v235/wei24h.html}
}
<!-- ``` @article{wei2023magicoder, title={Magicoder: Source Code Is All You Need}, author={Wei, Yuxiang and Wang, Zhe and Liu, Jiawei and Ding, Yifeng and Zhang, Lingming}, journal={arXiv preprint arXiv:2312.02120}, year={2023} } ``` -->

πŸ™ Acknowledgements

We thank AK(@_akhaliq) and the HuggingΒ Face team for their support in the Magicoder Playground! We also thank the following amazing projects that truly inspired us:

⚠️ Important Note

⭐️ Star History

<a href="https://star-history.com/#ise-uiuc/magicoder&Timeline"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=ise-uiuc/magicoder&type=Timeline&theme=dark" /> <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=ise-uiuc/magicoder&type=Timeline" /> <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=ise-uiuc/magicoder&type=Timeline" /> </picture> </a>