Downloads · 30 days
98
19% of all-time downloads
Harish102005/Qwen2.5-Coder-7B-manim
Qwen2.5-Coder-7B-manim is a text generation model from Harish102005. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
Downloads · 30 days
98
19% of all-time downloads
All-time downloads
511
Public
Parameters
7.6B
15.2 GB on disk
Likes
2
Public
Click a slice to open those files.
.safetensors15.2 GB · 100%
From the Hugging Face model README
Generate Manim (Mathematical Animation Engine) Python code from natural language descriptions! Fine-tuned on 2,407 examples from the 3Blue1Brown Manim dataset using QLoRA with Unsloth.
pip install unsloth transformers accelerate
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="Harish102005/Qwen2.5-Coder-7B-manim",
max_seq_length=2048,
dtype=None,
load_in_4bit=True,
)
FastLanguageModel.for_inference(model)
# Alpaca-style prompt template
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{}
### Input:
{}
### Response:
{}"""
prompt = "Create a blue circle that grows to twice its size"
inputs = tokenizer([
alpaca_prompt.format(
"Generate Manim code for the following task:",
prompt,
""
)
], return_tensors="pt").to("cuda")
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.3,
top_p=0.9,
repetition_penalty=1.1,
do_sample=True,
)
generated_code = tokenizer.decode(outputs, skip_special_tokens=True)
print(generated_code.split("### Response:")[-1].strip())
def generate_manim_code(prompt, max_tokens=512):
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{}
### Input:
{}
### Response:
{}"""
formatted_prompt = alpaca_prompt.format(
"Generate Manim code for the following task:",
prompt,
""
)
inputs = tokenizer([formatted_prompt], return_tensors="pt").to("cuda")
outputs = model.generate(
**inputs,
max_new_tokens=max_tokens,
temperature=0.3,
top_p=0.9,
repetition_penalty=1.1,
do_sample=True,
)
generated_text = tokenizer.decode(outputs, skip_special_tokens=True)
if "### Response:" in generated_text:
code = generated_text.split("### Response:")[-1].strip()
if "### Instruction:" in code:
code = code.split("### Instruction:")[0].strip()
return code
return generated_text
# Example
code = generate_manim_code("Create a rotating square")
print(code)
Prompt: "Create a rotating square that changes color from blue to red"
from manim import *
class MyScene(Scene):
def construct(self):
square = Square(color=BLUE)
self.add(square)
self.play(square.animate.rotate(PI), run_time=2)
square.set_color(RED)
Prompt: "Draw a sine wave from 0 to 2π with animation"
from manim import *
class MyScene(Scene):
def construct(self):
axes = Axes(x_range=[0, 2*PI], y_range=[-1, 1])
graph = axes.plot(lambda x: np.sin(x), color=BLUE)
self.add(axes, graph)
Prompt: "Show the equation E=mc² and fade it in"
from manim import *
class MyScene(Scene):
def construct(self):
e_mc_squared = MathTex("E=mc^2")
self.play(Write(e_mc_squared))
self.wait()
| Parameter | Value |
|---|---|
| LoRA Rank (r) | 16 |
| LoRA Alpha | 16 |
| LoRA Dropout | 0.0 |
| Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Max Sequence Length | 2048 |
| Precision | BFloat16 |
| Quantization | 4-bit NF4 (double quantization) |
from transformers import TextStreamer
text_streamer = TextStreamer(tokenizer, skip_prompt=True)
_ = model.generate(**inputs, streamer=text_streamer, max_new_tokens=512, temperature=0.3)
prompts = ["Create a blue circle", "Draw a red square", "Show a green triangle"]
for prompt in prompts:
code = generate_manim_code(prompt)
print(f"Prompt: {prompt}\n{code}\n{'-'*60}")
✅ Star this model if you find it useful!