Views
No views yet
TheSon2202/mistral-manim-python-coder-v01)| 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%) |
r): 16lora_alpha): 32lora_dropout): 0.05["q_proj", "k_proj", "v_proj", "o_proj"]CAUSAL_LMTruenf4 (Normal Float 4)torch.float16True| 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.
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_id = "TheSon2202/mistral-manim-python-coder-v01"
5
6# Load tokenizer and model
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8model = AutoModelForCausalLM.from_pretrained(
9 model_id,
10 device_map="auto",
11 torch_dtype=torch.float16
12)
13
14# Configure Chat Template for Mistral Base Model
15tokenizer.chat_template = (
16 "{{ bos_token }}"
17 "{% for message in messages %}"
18 "{% if message['role'] == 'system' %}"
19 "{{ 'System: ' + message['content'] + '\n\n' }}"
20 "{% elif message['role'] == 'user' %}"
21 "{{ '[INST] ' + message['content'] + ' [/INST]' }}"
22 "{% elif message['role'] == 'assistant' %}"
23 "{{ ' ' + message['content'] + eos_token }}"
24 "{% endif %}"
25 "{% endfor %}"
26)
27
28def generate_manim_code(instruction):
29 system_prompt = "Yor are an Coding Python Expert, read the instruction and complete these code correctly"
30 messages = [
31 {"role": "system", "content": system_prompt},
32 {"role": "user", "content": instruction}
33 ]
34
35 prompt = tokenizer.apply_chat_template(
36 messages,
37 tokenize=False,
38 add_generation_prompt=True
39 )
40
41 inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
42
43 with torch.no_grad():
44 outputs = model.generate(
45 **inputs,
46 max_new_tokens=256,
47 temperature=0.2,
48 do_sample=True,
49 pad_token_id=tokenizer.eos_token_id
50 )
51
52 return tokenizer.decode(outputs[0], skip_special_tokens=True)
53
54# Test code generation
55test_instruction = "Create a square with side length 4 and color it red, then animate it to shift right by 3 units."
56print(generate_manim_code(test_instruction))1from manim import *
2
3class MyScene(Scene):
4 def construct(self):
5 square = Square(side_length=4, color=RED)
6 self.add(square)
7 self.play(square.animate.shift(RIGHT * 3), run_time=3)