Downloads ยท 30 days
8
10% of all-time downloads
md-nishat-008/Mojo-Coder
Mojo-Coder is a text generation model from md-nishat-008. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
<div align="center" <h1๐ฅ Mojo-Coder ๐ฅ</h1 <emState-of-the-art Language Model for Mojo Programming</em </div
Downloads ยท 30 days
8
10% of all-time downloads
All-time downloads
81
Public
Parameters
8.5B
17.1 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors17.1 GB ยท 100%
From the Hugging Face model README
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.
<div align="center"> <h2>๐ค Model Information</h2> </div>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.
<div align="center"> <h2>๐ Description</h2> </div>The Mojo-Coder family consists of three specialized 7B-parameter models, each built on CodeGemma's architecture:
| <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> | |
|---|---|---|---|
| ๐ Code Completion | โ | โ | โ |
| ๐ก NL โ Code Generation | โ | โ | |
| ๐ Multilingual Support | โ | ||
| ๐ Instruction Following | โ | โ |
Choose the model that best fits your needs:
Notably, our models significantly outperform current state-of-the-art models including GPT-4o and Claude-3.5-Sonnet on the HumanEval-Mojo benchmark.
<div style="color: red; text-align: center; padding: 10px; margin: 20px 0; border: 2px solid red; border-radius: 5px;"> <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> </div>from transformers import GemmaTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("md-nishat-008/Mojo-Coder-it")
model = AutoModelForCausalLM.from_pretrained("md-nishat-008/Mojo-Coder-it")
input_text = "Write me a Mojo function to calculate the nth fibonacci number."
input_ids = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(**input_ids)
print(tokenizer.decode(outputs[0]))
The instruction-tuned models use a chat template that must be adhered to for conversational use. The easiest way to apply it is using the tokenizer's built-in chat template, as shown in the following snippet.
Let's load the model and apply the chat template to a conversation. In this example, we'll start with a single user interaction:
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
tokenizer = AutoTokenizer.from_pretrained("md-nishat-008/Mojo-Coder-it")
model = AutoModelForCausalLM.from_pretrained("md-nishat-008/Mojo-Coder-it")
chat = [{"role": "user", "content": "Write a function that calculates factorial of a number in Mojo"}]
inputs = tokenizer.apply_chat_template(chat, tokenize=True, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model.generate(
inputs=inputs,
max_new_tokens=1000,
temperature=0.7,
top_p=0.95,
pad_token_id=tokenizer.eos_token_id,
eos_token_id=tokenizer.eos_token_id
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
At this point, the prompt contains the following text:
<bos><start_of_turn>user
Write a hello world program in Mojo<end_of_turn>
<start_of_turn>model
As you can see, each turn is preceded by a <start_of_turn> delimiter and then the role of the entity
(either user, for content supplied by the user, or model for LLM responses). Turns finish with
the <end_of_turn> token.
You can follow this format to build the prompt manually, if you need to do it without the tokenizer's chat template.
After the prompt is ready, generation can be performed like this:
inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=150)
<div align="center">
<h2>โ๏ธ Inputs and Outputs</h2>
</div>
Inputs:
Outputs:
Using CodeGemma-7B-IT as our base model, we further trained on:
The following data pre-processing techniques were applied:
We evaluate Mojo-Coder on:
| Model | HumanEval-Mojo |
|---|---|
| GPT-4o | 25.5% |
| Claude-3.5-Sonnet | 39.8% |
| mojo-coder | 36.7% |
| mojo-coder-it-m | 61.5% |
| mojo-coder-it | 66.4% |
The model is designed for:
Code should be reviewed and tested before production use, especially for performance-critical applications.
<div align="center"> <h2>๐ Citation</h2> </div>If you find our work helpful, please consider citing our paper:
<div style="background-color: #f6f8fa; padding: 20px; border-radius: 5px; margin: 10px 0;"> <p style="margin-bottom: 10px;"><strong>MojoBench: Language Modeling and Benchmarks for Mojo</strong></p>@inproceedings{Raihan2024MojoBenchLM,
title = {MojoBench: Language Modeling and Benchmarks for Mojo},
author = {Raihan, Nishat and Santos, Joanna C. S. and Zampieri, Marcos},
year = {2024},
url = {https://api.semanticscholar.org/CorpusID:273532552}
}