Run this model with HF Jobs
Run TheSon2202/mistral-manim-python-coder-v01 on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/TheSon2202/mistral-manim-python-coder-v01. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/TheSon2202/mistral-manim-python-coder-v01 on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/TheSon2202/mistral-manim-python-coder-v01. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/TheSon2202/mistral-manim-python-coder-v01. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use TheSon2202/mistral-manim-python-coder-v01 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TheSon2202/mistral-manim-python-coder-v01 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="TheSon2202/mistral-manim-python-coder-v01") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("TheSon2202/mistral-manim-python-coder-v01") model = AutoModelForCausalLM.from_pretrained("TheSon2202/mistral-manim-python-coder-v01", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use TheSon2202/mistral-manim-python-coder-v01 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "TheSon2202/mistral-manim-python-coder-v01" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TheSon2202/mistral-manim-python-coder-v01", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/TheSon2202/mistral-manim-python-coder-v01
- SGLang
How to use TheSon2202/mistral-manim-python-coder-v01 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "TheSon2202/mistral-manim-python-coder-v01" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TheSon2202/mistral-manim-python-coder-v01", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "TheSon2202/mistral-manim-python-coder-v01" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TheSon2202/mistral-manim-python-coder-v01", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use TheSon2202/mistral-manim-python-coder-v01 with Docker Model Runner:
docker model run hf.co/TheSon2202/mistral-manim-python-coder-v01
Mistral Manim Python Coder (TheSon2202/mistral-manim-python-coder-v01)
This model is a fine-tuned version of Mistral-7B-v0.3 using QLoRA (4-bit NF4), specialized in translating natural language instructions (Text-to-Instruction) into precise Python code for the mathematical animation library Manim.
1. Hyperparameters & Configuration
| Configuration Parameter | Value |
|---|---|
| Base Model | mistralai/Mistral-7B-v0.3 |
| Dataset | Edoh/manim_python |
| Maximum Sequence Length | 512 tokens |
| Learning Rate | 2e-4 (0.0002) |
| Weight Decay | 0.03 |
| Per-Device Batch Size | 2 |
| Gradient Accumulation Steps | 4 |
| Number of Epochs | 2 (Total 120 steps) |
| Optimizer | paged_adamw_32bit |
| LR Scheduler | cosine |
Gradient Clipping (max_grad_norm) |
0.3 |
| Warmup Steps Ratio | 0.1 (10%) |
PEFT (LoRA) Config
- Rank (
r):16 - Alpha (
lora_alpha):32 - Dropout (
lora_dropout):0.05 - Target Modules:
["q_proj", "k_proj", "v_proj", "o_proj"] - Task Type:
CAUSAL_LM
Quantization Config (BitsAndBytes)
- Load in 4-bit:
True - Quant Type:
nf4(Normal Float 4) - Compute Dtype:
torch.float16 - Double Quantization:
True
2. Training Metrics & Evaluation Results
The training process recorded convergence milestones across checkpoints (saved periodically every 50 steps):
| Training Step | Training Loss | Validation Loss | Num Tokens | Mean Token Accuracy |
|---|---|---|---|---|
| Step 50 | 0.2506 |
0.2504 |
41,922 | 94.41% |
| Step 100 | 0.2271 |
0.2374 |
83,632 | 94.83% |
| Step 120 (Final) | 0.2259 |
0.2359 |
100,332 | 94.88% |
General Overview: Both training and validation losses decreased steadily and closely tracked each other (showing no signs of overfitting). Combined with an average token accuracy of approximately 94.88%, this demonstrates that the model successfully learned Manim's syntax and programming conventions.
3. Inference Demo
You can load the model directly from the Hugging Face Hub to generate Manim code using the following Python snippet:
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "TheSon2202/mistral-manim-python-coder-v01"
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
torch_dtype=torch.float16
)
# Configure Chat Template for Mistral Base Model
tokenizer.chat_template = (
"{{ bos_token }}"
"{% for message in messages %}"
"{% if message['role'] == 'system' %}"
"{{ 'System: ' + message['content'] + '\n\n' }}"
"{% elif message['role'] == 'user' %}"
"{{ '[INST] ' + message['content'] + ' [/INST]' }}"
"{% elif message['role'] == 'assistant' %}"
"{{ ' ' + message['content'] + eos_token }}"
"{% endif %}"
"{% endfor %}"
)
def generate_manim_code(instruction):
system_prompt = "Yor are an Coding Python Expert, read the instruction and complete these code correctly"
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": instruction}
]
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=256,
temperature=0.2,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Test code generation
test_instruction = "Create a square with side length 4 and color it red, then animate it to shift right by 3 units."
print(generate_manim_code(test_instruction))
π€ Expected Output (Clean Python Code)
from manim import *
class MyScene(Scene):
def construct(self):
square = Square(side_length=4, color=RED)
self.add(square)
self.play(square.animate.shift(RIGHT * 3), run_time=3)
- Downloads last month
- 135
Model tree for TheSon2202/mistral-manim-python-coder-v01
Base model
mistralai/Mistral-7B-v0.3