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|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
library_name: transformers
|
4 |
+
datasets:
|
5 |
+
- md-nishat-008/Mojo-Corpus
|
6 |
+
- md-nishat-008/Mojo-SFT
|
7 |
+
- md-nishat-008/Mojo-mSFT
|
8 |
+
pipeline_tag: text-generation
|
9 |
+
---
|
10 |
+
|
11 |
+
<div align="center">
|
12 |
+
<h1>π₯ Mojo-Coder π₯</h1>
|
13 |
+
<em>State-of-the-art Language Model for Mojo Programming</em>
|
14 |
+
</div>
|
15 |
+
|
16 |
+
|
17 |
+
<div align="center">
|
18 |
+
<table><tr>
|
19 |
+
<td><a href="https://arxiv.org/abs/2410.17736"><img src="https://img.shields.io/badge/arXiv-Read_Paper-blue?style=for-the-badge&logo=arxiv" /></a></td>
|
20 |
+
<td><a href="mailto:[email protected]"><img src="https://img.shields.io/badge/Email-Contact_Us-blue?style=for-the-badge&logo=gmail" /></a></td>
|
21 |
+
</tr></table>
|
22 |
+
</div>
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
<div align="center">
|
27 |
+
<h2>π― Background and Motivation</h2>
|
28 |
+
</div>
|
29 |
+
|
30 |
+
Mojo programming language, developed by Modular, has emerged as a game-changing technology in high-performance computing and AI development. Despite its growing popularity and impressive capabilities (up to 68,000x faster than Python!), existing LLMs struggle with Mojo code generation. Mojo-Coder addresses this gap by providing specialized support for Mojo programming, built upon the robust architecture of [CodeGemma-7B-IT](https://huggingface.co/google/codegemma-7b-it/).
|
31 |
+
|
32 |
+
<div align="center">
|
33 |
+
<h2>π€ Model Information</h2>
|
34 |
+
</div>
|
35 |
+
|
36 |
+
Mojo-Coder transforms natural language instructions into optimized Mojo code, supporting multiple languages (English, German, French, Spanish, and Bangla) while maintaining high-quality code generation capabilities.
|
37 |
+
|
38 |
+
<div align="center">
|
39 |
+
<h2>π Description</h2>
|
40 |
+
</div>
|
41 |
+
|
42 |
+
The Mojo-Coder family consists of three specialized 7B-parameter models, each built on CodeGemma's architecture:
|
43 |
+
| | <h3><a href="https://huggingface.co/md-nishat-008/mojo-coder" style="color: #0969DA;">mojo-coder</a> π₯</h3> | <h3><a href="https://huggingface.co/md-nishat-008/mojo-coder-it" style="color: #0969DA;">mojo-coder-it</a> π</h3> | <h3><a href="https://huggingface.co/md-nishat-008/mojo-coder-it-m" style="color: #0969DA;">mojo-coder-it-m</a> β</h3> |
|
44 |
+
|---------------------------|:---:|:---:|:---:|
|
45 |
+
| π Code Completion | β
| β
| β
|
|
46 |
+
| π‘ NL β Code Generation | | β
| β
|
|
47 |
+
| π Multilingual Support | | | β
|
|
48 |
+
| π Instruction Following | | β
| β
|
|
49 |
+
|
50 |
+
<div align="center">
|
51 |
+
<h2>π Sample Usage</h2>
|
52 |
+
</div>
|
53 |
+
|
54 |
+
Choose the model that best fits your needs:
|
55 |
+
- For basic Mojo code completion: [mojo-coder](https://huggingface.co/md-nishat-008/mojo-coder)
|
56 |
+
- For English instruction-based code generation: [mojo-coder-it](https://huggingface.co/md-nishat-008/mojo-coder-it)
|
57 |
+
- For multilingual support: [mojo-coder-it-m](https://huggingface.co/md-nishat-008/mojo-coder-it-m)
|
58 |
+
|
59 |
+
Notably, our models significantly outperform current state-of-the-art models including GPT-4o and Claude-3.5-Sonnet on the HumanEval-Mojo benchmark.
|
60 |
+
|
61 |
+
<div align="center">
|
62 |
+
<h3>β¨ Let's revolutionize Mojo programming together! β¨</h3>
|
63 |
+
</div>
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
<div style="color: red; text-align: center; padding: 10px; margin: 20px 0; border: 2px solid red; border-radius: 5px;">
|
69 |
+
<strong>β οΈ IMPORTANT: When using the model, you MUST explicitly mention "Mojo" in your prompts (e.g., "Write a Mojo function to...", "Create Mojo code that...") otherwise the model may not generate Mojo code!</strong>
|
70 |
+
</div>
|
71 |
+
|
72 |
+
#### For Code Generation
|
73 |
+
|
74 |
+
```python
|
75 |
+
from transformers import GemmaTokenizer, AutoModelForCausalLM
|
76 |
+
|
77 |
+
tokenizer = AutoTokenizer.from_pretrained("md-nishat-008/Mojo-Coder-it")
|
78 |
+
model = AutoModelForCausalLM.from_pretrained("md-nishat-008/Mojo-Coder-it")
|
79 |
+
|
80 |
+
input_text = "Write me a Mojo function to calculate the nth fibonacci number."
|
81 |
+
input_ids = tokenizer(input_text, return_tensors="pt")
|
82 |
+
|
83 |
+
outputs = model.generate(**input_ids)
|
84 |
+
print(tokenizer.decode(outputs[0]))
|
85 |
+
```
|
86 |
+
|
87 |
+
#### Chat Template
|
88 |
+
|
89 |
+
The instruction-tuned models use a chat template that must be adhered to for conversational use.
|
90 |
+
The easiest way to apply it is using the tokenizer's built-in chat template, as shown in the following snippet.
|
91 |
+
|
92 |
+
Let's load the model and apply the chat template to a conversation. In this example, we'll start with a single user interaction:
|
93 |
+
|
94 |
+
```py
|
95 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
96 |
+
import torch
|
97 |
+
|
98 |
+
tokenizer = AutoTokenizer.from_pretrained("md-nishat-008/Mojo-Coder-it")
|
99 |
+
model = AutoModelForCausalLM.from_pretrained("md-nishat-008/Mojo-Coder-it")
|
100 |
+
|
101 |
+
chat = [{"role": "user", "content": "Write a function that calculates factorial of a number in Mojo"}]
|
102 |
+
inputs = tokenizer.apply_chat_template(chat, tokenize=True, return_tensors="pt").to("cuda")
|
103 |
+
|
104 |
+
with torch.no_grad():
|
105 |
+
outputs = model.generate(
|
106 |
+
inputs=inputs,
|
107 |
+
max_new_tokens=1000,
|
108 |
+
temperature=0.7,
|
109 |
+
top_p=0.95,
|
110 |
+
pad_token_id=tokenizer.eos_token_id,
|
111 |
+
eos_token_id=tokenizer.eos_token_id
|
112 |
+
)
|
113 |
+
|
114 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
115 |
+
```
|
116 |
+
|
117 |
+
At this point, the prompt contains the following text:
|
118 |
+
|
119 |
+
```
|
120 |
+
<bos><start_of_turn>user
|
121 |
+
Write a hello world program in Mojo<end_of_turn>
|
122 |
+
<start_of_turn>model
|
123 |
+
```
|
124 |
+
|
125 |
+
As you can see, each turn is preceded by a `<start_of_turn>` delimiter and then the role of the entity
|
126 |
+
(either `user`, for content supplied by the user, or `model` for LLM responses). Turns finish with
|
127 |
+
the `<end_of_turn>` token.
|
128 |
+
|
129 |
+
You can follow this format to build the prompt manually, if you need to do it without the tokenizer's
|
130 |
+
chat template.
|
131 |
+
|
132 |
+
After the prompt is ready, generation can be performed like this:
|
133 |
+
|
134 |
+
```py
|
135 |
+
inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
|
136 |
+
outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=150)
|
137 |
+
```
|
138 |
+
|
139 |
+
<div align="center">
|
140 |
+
<h2>βοΈ Inputs and Outputs</h2>
|
141 |
+
</div>
|
142 |
+
|
143 |
+
**Inputs**:
|
144 |
+
- For base model (mojo-coder): code prefix and/or suffix for Mojo code completion
|
145 |
+
- For instruction-tuned models (mojo-coder-it & mojo-coder-it-m): natural language prompts/instructions
|
146 |
+
|
147 |
+
<p style="color: red;"><strong>Note: In prompts, you must explicitly mention "Mojo" (e.g., "Write a Mojo function to...", "Write Mojo code to...") otherwise the models may not generate Mojo code.</strong></p>
|
148 |
+
|
149 |
+
**Outputs**:
|
150 |
+
- For all variants: Mojo code snippets and natural language responses
|
151 |
+
- Additional explanations and documentation when requested
|
152 |
+
|
153 |
+
<div align="center">
|
154 |
+
<h2>π Model Data</h2>
|
155 |
+
</div>
|
156 |
+
|
157 |
+
### Training Dataset
|
158 |
+
|
159 |
+
Using [CodeGemma-7B-IT](https://huggingface.co/google/codegemma-7b-it/) as our base model, we further trained on:
|
160 |
+
- [Mojo-Corpus](https://huggingface.co/datasets/md-nishat-008/Mojo_Corpus): 6.5M tokens of curated Mojo code from public repositories
|
161 |
+
- [Mojo-SFT](https://huggingface.co/datasets/md-nishat-008/Mojo_SFT): 3,200 instruction-code pairs for English
|
162 |
+
- [Mojo-mSFT](https://huggingface.co/datasets/md-nishat-008/Mojo_mSFT): Multilingual instruction-code pairs in 5 languages
|
163 |
+
|
164 |
+
### Training Data Processing
|
165 |
+
|
166 |
+
The following data pre-processing techniques were applied:
|
167 |
+
- Rigorous filtering pipeline (F1-F6) to ensure code quality
|
168 |
+
- Apache 2.0 license compliance
|
169 |
+
- Language detection using fastText
|
170 |
+
- Duplicate removal and content validation
|
171 |
+
- Expert review for instruction-code pairs
|
172 |
+
|
173 |
+
<div align="center">
|
174 |
+
<h2>π Evaluation Information</h2>
|
175 |
+
</div>
|
176 |
+
|
177 |
+
### Evaluation Approach
|
178 |
+
|
179 |
+
We evaluate Mojo-Coder on:
|
180 |
+
- [HumanEval-Mojo](https://huggingface.co/datasets/md-nishat-008/HumanEval-Mojo): First benchmark for Mojo code generation
|
181 |
+
- Multi-language instruction following
|
182 |
+
- Code quality and execution success
|
183 |
+
|
184 |
+
### Evaluation Results
|
185 |
+
|
186 |
+
#### Code Generation Benchmarks (Pass@1)
|
187 |
+
|
188 |
+
| Model | HumanEval-Mojo |
|
189 |
+
|-------|----------------|
|
190 |
+
| GPT-4o | 25.5% |
|
191 |
+
| Claude-3.5-Sonnet | 39.8% |
|
192 |
+
| mojo-coder | 36.7% |
|
193 |
+
| mojo-coder-it-m | 61.5% |
|
194 |
+
| mojo-coder-it | 66.4% |
|
195 |
+
|
196 |
+
<div align="center">
|
197 |
+
<h2>β οΈ Limitations and Usage</h2>
|
198 |
+
</div>
|
199 |
+
|
200 |
+
### Intended Usage
|
201 |
+
- Mojo code completion and generation
|
202 |
+
- Multi-language instruction following
|
203 |
+
- Code documentation and explanation
|
204 |
+
- Educational support for Mojo programming
|
205 |
+
|
206 |
+
### Known Limitations
|
207 |
+
- Limited to Mojo programming language
|
208 |
+
- Requires explicit mention of "Mojo" in prompts
|
209 |
+
- Performance may vary with complex algorithms
|
210 |
+
- May occasionally generate Python-like syntax
|
211 |
+
- Based on data available up to 2024
|
212 |
+
|
213 |
+
### Ethical Considerations
|
214 |
+
The model is designed for:
|
215 |
+
- Educational and development purposes
|
216 |
+
- Open-source contribution to Mojo ecosystem
|
217 |
+
- Supporting multilingual access to Mojo programming
|
218 |
+
|
219 |
+
Code should be reviewed and tested before production use, especially for performance-critical applications.
|
220 |
+
|
221 |
+
|
222 |
+
|
223 |
+
<div align="center">
|
224 |
+
<h2>π Citation</h2>
|
225 |
+
</div>
|
226 |
+
|
227 |
+
If you find our work helpful, please consider citing our paper:
|
228 |
+
|
229 |
+
<div style="background-color: #f6f8fa; padding: 20px; border-radius: 5px; margin: 10px 0;">
|
230 |
+
<p style="margin-bottom: 10px;"><strong>MojoBench: Language Modeling and Benchmarks for Mojo</strong></p>
|
231 |
+
|
232 |
+
```bibtex
|
233 |
+
@inproceedings{Raihan2024MojoBenchLM,
|
234 |
+
title = {MojoBench: Language Modeling and Benchmarks for Mojo},
|
235 |
+
author = {Raihan, Nishat and Santos, Joanna C. S. and Zampieri, Marcos},
|
236 |
+
year = {2024},
|
237 |
+
url = {https://api.semanticscholar.org/CorpusID:273532552}
|
238 |
+
}
|
239 |
+
```
|