BibbyResearch/3blue1brown-manim
Viewer • Updated • 2.41k • 17 • 24
How to use Harish102005/Qwen2.5-Coder-7B-manim with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="Harish102005/Qwen2.5-Coder-7B-manim") # pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Harish102005/Qwen2.5-Coder-7B-manim")
model = AutoModelForCausalLM.from_pretrained("Harish102005/Qwen2.5-Coder-7B-manim", device_map="auto")How to use Harish102005/Qwen2.5-Coder-7B-manim with PEFT:
Task type is invalid.
How to use Harish102005/Qwen2.5-Coder-7B-manim with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "Harish102005/Qwen2.5-Coder-7B-manim"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Harish102005/Qwen2.5-Coder-7B-manim",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/Harish102005/Qwen2.5-Coder-7B-manim
How to use Harish102005/Qwen2.5-Coder-7B-manim with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "Harish102005/Qwen2.5-Coder-7B-manim" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Harish102005/Qwen2.5-Coder-7B-manim",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "Harish102005/Qwen2.5-Coder-7B-manim" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "Harish102005/Qwen2.5-Coder-7B-manim",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use Harish102005/Qwen2.5-Coder-7B-manim with Docker Model Runner:
docker model run hf.co/Harish102005/Qwen2.5-Coder-7B-manim
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!