Scope
Input: SVG source plus a text motion instruction. Output: complete animated SVG using animate or animateTransform. This is text-to-code; no image pixels or video are used. The base architecture includes a vision component, but this experiment trains language-side adapters only and does not evaluate image inputs.
Supported task grammar covers translation, rotation, scaling and opacity, including simultaneous motions and a held peak. The original elements, IDs and attributes must be preserved. Generated code is untrusted: use the repository's validator and sandboxed renderer. Do not embed unchecked model output into an application.
Training and data
Original procedural dataset: 1,000 training / 100 validation / 100 test rows, Apache-2.0. Dataset revision: a5866291699f723306d59db53bbd7ca3bcd331e9. Drawing families and motion combinations are disjoint across splits. Exact input/instruction duplicates are removed. The generator contains no paid-model outputs or third-party art.
Each input combines input_svg and instruction in the native chat template; the assistant target is target_svg. Causal next-token cross-entropy applies to assistant target tokens only. Prompt and padding labels are -100. No sequence is truncated; the configured maximum is 2,048 tokens. Thinking is disabled in both baseline and adapted inference.
LoRA rank 16, alpha 32, dropout 0. Language attention, MLP and linear-attention projection layers are adapted; 10,822,656 parameters are trainable. The frozen base revision is 2fc06364715b967f1860aea9cf38778875588b17. Weights remain in float32; training uses float32 because the initial T4 fp16 trial produced nonfinite gradients. Inference uses fp16 autocast.
Main run: 100 optimizer steps (0.40 epoch), batch 1 with accumulation 4, learning rate 1e-4, 5 warmup steps, cosine decay, AdamW, activation checkpointing, seed 20261120. Hardware: Tesla T4. Training runtime: 512.1 seconds. Peak allocated GPU memory logged during training: 5.00 GiB. Checkpoint checkpoint-100 was selected by lowest token loss on the first 20 fixed validation examples. The test set did not select checkpoints.
Tested packages: torch 2.14.1+cu130, transformers 5.23.0, peft 0.22.0, datasets 5.2.0, accelerate 1.16.0, playwright 1.58.0.
Evaluation
Table with columns: Model, Complete tasks passed| Model | Complete tasks passed |
|---|
| Untouched base | 0/100 |
| LoRA adapter | 100/100 |
Every task requires safe valid SVG, unchanged original drawing structure, and browser-rendered motion within tolerance at cycle fractions 0, .13, .39, .50, .61, .80, .99 and 1.25. Matrix coefficients use tolerance .015, translation .5 SVG units, effective opacity .02. Animation code is not compared to an exact target string, but the unchanged scene structure is checked strictly. Decoding is greedy, with a 1,024-token output limit and batches of four in both arms. No repair loop or cherry-picked exclusion is used.
These are narrow synthetic tasks with fixed phrasing and repetitive motion rules. Results do not establish general animation quality, arbitrary SVG support, paraphrase robustness, or superiority over larger models. Token loss is separate from the task success metric. All test predictions and TensorBoard events are included under evidence/.
Use
Install the tested Transformers and PEFT versions listed above. This adapter requires its pinned base model and a CUDA GPU for the tested usage path:
import jsonimport torchfrom huggingface_hub import hf_hub_downloadfrom peft import PeftModelfrom transformers import AutoTokenizer, Qwen3_5ForConditionalGeneration adapter_id = "lxyuan/SVG-Motion-Qwen3.5-0.8B-LoRA"base = Qwen3_5ForConditionalGeneration.from_pretrained( "Qwen/Qwen3.5-0.8B", revision="2fc06364715b967f1860aea9cf38778875588b17", dtype=torch.float32, attn_implementation="sdpa",).to("cuda")model = PeftModel.from_pretrained(base, adapter_id).eval()tokenizer = AutoTokenizer.from_pretrained(adapter_id)path = hf_hub_download("lxyuan/svg-motion-lab", "test.jsonl", repo_type="dataset", revision="a5866291699f723306d59db53bbd7ca3bcd331e9")with open(path) as stream: example = json.loads(next(stream))messages = [ {"role": "system", "content": "You animate existing SVG drawings. Preserve every original element, ID and attribute. Insert only native SVG animate or animateTransform children in the supplied motion groups. Return only the complete SVG."}, {"role": "user", "content": example["input_svg"] + "\n\n" + example["instruction"]},]prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)inputs = tokenizer(prompt, add_special_tokens=False, return_tensors="pt").to("cuda")with torch.inference_mode(), torch.autocast("cuda", dtype=torch.float16): tokens = model.generate(**inputs, do_sample=False, max_new_tokens=1024, use_cache=True, pad_token_id=tokenizer.pad_token_id)svg = tokenizer.decode(tokens[0, inputs.input_ids.shape[1]:], skip_special_tokens=True).strip()print(svg)
The output is SVG source code, not rendered video. Use the repository's browser evaluator to validate it before rendering.
Reproduce
Clone the nlp repository, change into experiments/svg-motion-lab, generate the data with python dataset.py --output data, install Chromium as described in the README, and run:
uv run --script train.py --data data --output outputs/full --steps 100 --revision 2fc06364715b967f1860aea9cf38778875588b17