Design practice · Research feature

Rendering-Aware Reinforcement Learning for Vector Graphics Generation

A new method uses rendered images to train AI models to create precise and efficient vector graphics by comparing generated code to visual outputs.

Adapted from research by Juan A. Rodriguez, Haotian Zhang, Abhay Puri and colleagues.

arXiv preprint revision · 2025-11-30 · Attribution & reuse
In this article
Text2SVG Results Visualization. We present qualitative comparisons of our RLRF outputs on test samples from the Text2SVG benchmark, alongside generations from Qwen3-32B, GPT-4o, and Gemini 1.5 Pro. Our method effectively aligns Qwen3-8B to produce high-quality, semantically rich, and visually coherent SVGs.
Figure 8: Text2SVG Results Visualization. We present qualitative comparisons of our RLRF outputs on test samples from the Text2SVG benchmark, alongside generations from Qwen3-32B, GPT-4o, and Gemini 1.5 Pro. Our method effectively aligns Qwen3-8B to produce high-quality, semantically rich, and visually coherent SVGs.

Editor’s introduction

The study evaluates RLRF, a reinforcement learning approach that uses rendered images to guide the generation of Scalable Vector Graphics (SVG). It compares generated SVG code to input images to compute feedback, which trains vision-language models to produce more accurate, semantically coherent, and efficient outputs. Results show RLRF achieves strong generalization across unseen SVG types and benchmarks, though it still approaches but does not surpass the performance of the OmniSVG baseline. The evaluation includes both open-source and closed-source models, with results based on available best performances. A new metric, Accurate, is used to assess cases with feasible ground-truth comparisons. The study highlights the effectiveness of rendering feedback in improving SVG generation, particularly in capturing visual consistency and code efficiency, without requiring differentiable rendering during training.

Introduction

Generating structured visual code from perceptual inputs, known as the inverse rendering code generation problem, aims to translate images or text into executable code that reproduces the target visual content. This task has gained momentum with the rise of vision-language models (VLMs) capable of visual-symbolic reasoning and autoregressive sequence generation. Among symbolic formats, Scalable Vector Graphics (SVG) offer a uniquely expressive target: they are compact, editable, and resolution-independent, and align naturally with the token-based generation processes of language models.

This limitation arises from the non-differentiability of the SVG rendering process in the context of autoregressive code generation, a challenge that differs from settings addressed by differentiable rasterizers such as DiffVG. DiffVG makes raster-space losses trainable by expressing an SVG as a small set of continuous primitives, and backpropagating the gradients from the rendered image to those primitive parameters. Autoregressive VLMs, in contrast, emit SVGs one discrete token at a time, making the generation path non-differentiable due to discrete sampling at each decoding step. As gradients cannot flow through discrete sampling steps, differentiable rendering approaches such as DiffVG cannot be applied directly, leaving a critical gap in autoregressive SVG generation.

We design a novel composite reward function integrating complementary reward signals to guide learning: (1) image reconstruction, measured using metrics like L2 distance, (2) semantic similarity, computed using models such as DreamSim or CLIP; and (3) code efficiency, based on deviations in SVG token length. This hybrid reward setup encourages the model to improve SVG generation along multiple axes. RLRF delivers substantial gains over supervised fine-tuning, addressing common failure modes and enabling models to acquire a deeper understanding of SVG, producing accurate and well-structured vector graphics across diverse inputs.

Overcoming the Non-Differentiable Rendering Problem

In the autoregressive VLM setting, the model learns to translate pixel images into SVG code. However, at inference time, it can easily drift off-distribution, leading to poor visual outputs. Unlike other code generation tasks, inverse rendering tasks like SVG generation offer a unique advantage: the generated code can be rendered into a pixel image and directly compared to the input, enabling precise and inexpensive feedback. While differentiable SVG renderers such as DiffVG exist, they rely on latent path representations and are not compatible with our general, token-based approach to code generation. Moreover, because SVG generation involves sampling discrete tokens, gradients cannot be directly propagated. To address this, we propose RLRF (Reinforcement Learning from Rendering Feedback). The model generates SVG code, which is rendered and evaluated using a composite reward that reflects visual fidelity, semantic alignment, and code efficiency. These rewards are used to optimize the model using reinforcement learning techniques, effectively incorporating rendering-based feedback into the training process.

Rewards for Vector Graphics Rendering

We carefully design reward functions that automatically evaluate SVG generation quality across multiple dimensions. A key advantage of this setup is that we have access to fully automated, high-quality reward signals, eliminating the need to learn one using human annotations. We focus our reward design on two core aspects of SVG generation: the visual fidelity of the rendered output and the efficiency of the SVG code in terms of compression. To capture both, we implement a suite of complementary reward functions that assess the rasterized image and the underlying SVG code. These include image reconstruction accuracy, semantic alignment, and code efficiency. By combining these rewards with tunable weights, our framework provides rich and targeted feedback that drives the model to produce SVGs that are both visually faithful and structurally compact. We utilize CairoSVG as our SVG renderer.

Evaluation

Baselines. We compare our approach against image processing methods (Vtracer, Potrace, PyAutoTrace ), deep learning methods (LIVE, DiffVG ), and LLMs and VLMs including Claude3.7 Sonnet, GPT-4o, Gemini Family and open-source models like Qwen2.5VL or Llama4 families. These baselines span a wide range of modeling approaches, scales, and architectures.

Benchmarks. For Im2SVG, we report results on SVG-Stack-Hard, a curated subset of 500 visually complex and diverse SVGs selected from the original SVG-Stack (see Appendix B.2 for more details on datasets). We also evaluate on additional benchmarks including SVG-Emoji, SVG-Fonts, and SVG-Icons. For Text2SVG evaluation, we use the MM-Icon and MM-Illustration, as well as Flickr30k Captions.

Metrics. For Im2SVG, we use MSE and SSIM for pixel-level fidelity, and DINO Score and LPIPS for perceptual similarity. Code Efficiency is the negated mean difference between ground truth and predicted SVG token counts. Positive values indicate more compact outputs. Ideally, the score is near zero, reflecting compression without loss of fidelity. For Text2SVG, we evaluate with CLIP similarity and an LLM-based judge (Qwen2.5-VL-72B) for text–image alignment. Additional details on metrics are provided in Appendix B.1.

Conclusion

We have shown that reinforcement learning (RL) can be highly effective for inverse rendering tasks, where models generate code that is rendered into images. By designing tailored rewards, we significantly enhance SVG reconstruction and generation capabilities in vision-language models (VLMs). We introduced RLRF (Reinforcement Learning from Rendering Feedback), a novel approach for fine-tuning autoregressive VLMs on SVG generation using RL. RLRF equips models with a stronger understanding of the SVG code space, enabling them to produce more efficient, semantically aligned, and visually accurate outputs, even on benchmarks and SVG types not seen during training. We first apply supervised fine-tuning (SFT) to give models a strong foundation in SVG generation. RLRF then drives exploration through rendered rollouts, computes automatic rewards, and optimizes generation accordingly. This results in a fully automated, high-quality training signal powered by a composite reward that balances pixel-level accuracy, semantic alignment, and code efficiency. The results are compelling: models trained with RLRF consistently generate SVGs with deeper structural understanding, improved visual fidelity, and significantly better code efficiency.

Text2SVG Results

We compare both open-source and closed-source VLMs, none of which were explicitly trained on these benchmarks. For baseline models, we report the best available results, including those from MM-Icons and MM-Illustrations as documented in. We are actively working to expand the set of evaluated models and report additional scores. We also introduce a new metric, Accurate, which is computed only on results for which ground-truth comparisons are feasible. The results show that while RLRF does not yet outperform the OmniSVG baseline, it demonstrates strong generalization and SVG generation capabilities. Notably, our method approaches OmniSVG’s performance despite not being trained on any paired SVGs from the target datasets. Among all models, Claude 3.7 achieves the strongest results, potentially due to specific tuning for SVG tasks. Nonetheless, RLRF showcases a promising path toward rendering-aware, reward-driven SVG generation.

Generalization across SVG Benchmarks

We further observe that RLRF consistently outperforms SVG-SFT across all metrics on both SVG-Emojis and SVG-Fonts. However, on SVG-Icons, RLRF only improves perceptual metrics such as DINO and LPIPS, while MSE and SSIM scores are slightly worse. This discrepancy is likely due to the nature of the dataset, which is heavily skewed toward sparse line drawings on white backgrounds. In such cases, small misalignments in thin black strokes can cause large changes in pixel-based metrics, making MSE and SSIM less reliable indicators of perceptual quality. Notably, traditional image processing methods perform quite well in general, as they are highly optimized for this style of imagery. However, this comes at the cost of producing extremely verbose SVGs with unnecessarily long token sequences, which lack semantic structure and often result in less efficient, non-sharp outputs and with artifacts.

We show qualitative visualizations in Figures 10 and 11, highlighting the generalization capabilities of RLRF. Despite never being trained on these datasets, models fine-tuned with RLRF produce SVGs that closely match the input in both shape and style, often achieving near-perfect reconstructions. SVG-SFT provides a reasonable baseline and captures basic structure, confirming the importance of the supervised pretraining stage. However, it frequently exhibits notable misalignments. For example, in the “disk” icon, RLRF preserves overlapping circular segments more accurately, whereas SVG-SFT distorts the occlusion geometry. In the “dress” example, RLRF leverages symmetry more effectively, producing a more coherent and balanced shape. Other models, including GPT-4o, Claude 3.7, and Gemini 1.5 Pro, perform inconsistently and often fail to reconstruct fine details or preserve shape semantics. This highlights the advantage of reinforcement learning from rendering feedback, which enables RLRF to develop a stronger understanding of structure and style across out-of-distribution examples.

A limitation we observe on RLRF is the model’s tendency to “give up"" on very complex inputs, producing code that diverges and then falls into loops. This likely stems from difficulty approximating intricate visual content. We believe this can be mitigated by scaling up the diversity and complexity of training data, especially images that require longer and more challenging SVG sequences.

User Study on Editability and Fidelity

We ran a user study to evaluate the editability and fidelity of SVGs produced by four model variants: StarVector, StarVector + RLRF, Qwen2.5VL-7B + SFT, and Qwen2.5VL-7B + RLRF. We sampled 50 examples from the SVG-Stack-Hard dataset, covering a wide range of primitives and structural complexity.

In terms of Fidelity, RLRF was preferred in 42.7 percent of comparisons, SFT in 12.0 percent, and the remaining 45.3 percent were ties. Regarding Editability, RLRF was preferred in 59.2 percent of comparisons, SFT in 15.0 percent, and 25.8 percent were ties.

These results show that RLRF improves both fidelity and editability compared with SFT. Although SFT already achieves strong fidelity and ties with RLRF on many straightforward examples, RLRF performs better on the more challenging cases without reducing visual quality. Participants consistently favored the SVGs produced by RLRF in terms of structure and ease of modification. Designers specifically pointed out that SFT sometimes introduced unused attributes or redundant styles, while RLRF produced more compact and interpretable paths and a cleaner overall organization.

Vision-Language Model Design

VLMs combine an image encoder with a decoder-only language model to process and generate multimodal content. The image encoder, often a Vision Transformer (ViT) or a convolutional network, converts the input image into a sequence of high-dimensional vectors called visual tokens. These are not discrete tokens like in language, but continuous embeddings representing image regions.

To make these embeddings compatible with the language model, they are passed through linear projection layers. This allows the language model to attend to the visual context during generation. Since large images can produce many visual tokens, some models add modules to reduce their number and retain only the most relevant ones. For example, Q-Former uses learnable queries to extract a smaller set of tokens, while Perceiver Resampler and AlignVLM use resampling and sparse attention to compress the visual information efficiently.

Once the visual tokens are projected, they are combined with any textual prompt and fed into a decoder-only language model. This model generates output tokens one at a time, using both the image and text context. In our case, the output is SVG code. The model learns to translate visual inputs into structured sequences of SVG instructions that can be rendered to reconstruct the original image. This setup allows the model to reason about both the appearance and structure of visual content and generate precise vector representations.

Context Length

Context length plays a crucial role in autoregressive SVG generation. Complex SVGs with fine-grained structure and intricate visual elements often require sequences that span tens or even hundreds of thousands of tokens. The Qwen2.5-VL model supports a context length of up to 128k tokens, which allows it to handle long and highly detailed SVG code sequences.

With the growing availability of models that support very long contexts, including recent work pushing towards hundreds of thousands or even millions of tokens, we expect context length to become less of a limitation in the near future. In principle, this trend makes large-scale vector representation increasingly feasible.

In our experiments, we cap the context length at 32k tokens to fit within GPU memory constraints. This is sufficient for all benchmark samples we evaluate, including a wide range of complex SVGs. In comparison, the StarVector model was limited to an 8k token context, which restricts its ability to model large or deeply nested SVG structures.

SVG Generation

SVG generation methods are typically categorized into three main approaches: classical image processing, latent variable models, and large language model (LLM)-based techniques. Traditional methods such as VTracer, Potrace, and Autotrace convert raster images into vector graphics by tracing contours and clustering regions. While effective for extracting shapes, these approaches produce long and unstructured SVGs composed of raw path commands. The resulting code is verbose, difficult to edit, and lacks higher-level semantic organization.

Deep learning has also been applied to this domain, particularly through differentiable rendering techniques that overcome the inherent non-differentiability of SVG rendering. DiffVG introduced a differentiable rasterizer, enabling the development of latent variable models that learn deep representations of SVG commands and the parameters of geometric primitives. These models use architectures based on variational autoencoders, diffusion processes, or autoregressive decoders.

Compared to traditional methods, latent variable models offer more structured control and support tasks like interpolation and style transfer. However, they often rely on simplified subsets of the SVG syntax, producing outputs that are less compact and less interpretable. Additionally, these models are typically trained on narrow, domain-specific datasets, limiting their generalization to diverse SVG types, an area where classical image processing methods remain more broadly applicable.

Vision-Language Models (VLMs)

Early VLMs such as Flamingo, BLIP-2, LLaVA, and GPT-4V introduced a powerful paradigm by adapting frozen vision encoders and connecting them to pretrained unimodal LLMs. This is typically done through learned projection layers that map visual features into token-like embeddings. These models follow an autoregressive generation strategy, enabling them to process both images and text within a unified token stream and perform instruction-following and multi-turn conversations grounded in visual inputs.

In parallel, the use of LLMs for code generation has grown rapidly recently. Code can be seen as a separate modality, with structure and syntax that differ significantly from natural language. Progress in this area has been driven by the availability of large-scale code corpora and the development of specialized coding models such as Codex, CodeGen, and StarCoder.

This convergence of multimodal models and their use on structured output generation and code generation enables a new class of problems: inverse rendering code generation, also known as visual-code generation). In these tasks, the model generates code that compiles or renders into visual content. Examples include SVG, TikZ, HTML, and CAD, which are used for generating graphics, diagrams, and illustrations. Prior efforts in this area include diagram and layout generation and text-to-CAD synthesis.

Reinforcement Learning Post-Training

Reinforcement Learning (RL) has become essential for post-training fine-tuning of large language models (LLMs). Reinforcement Learning from Human Feedback (RLHF), using Proximal Policy Optimization (PPO), has become the standard for aligning LLM outputs with human preferences, improving tasks like summarization and instruction-following. An alternative approach, Group Relative Policy Optimization (GRPO), stabilizes training by normalizing rewards across batches, removing the need for a separate value network and reducing variance. In the visual generation space, GRPO has been successfully used for image editing. In code generation, frameworks like CodeRL employ an actor-critic approach where the critic predicts functional correctness to guide the actor. PPOCoder integrates PPO with execution feedback, using compiler results as rewards to fine-tune code generation models. StepCoder introduces a curriculum of code completion subtasks, optimizing exploration by masking unexecuted code segments. Additionally, Reinforcement Learning from Execution Feedback (RLEF) enables models to refine code iteratively based on execution outcomes, enhancing performance on complex tasks. In multimodal domains, approaches like ViCT use a visual critic to align generated UI code with input screenshots, improving fidelity in UI-to-code generation. RL has also been applied in architectural design, where agents learn to generate space layouts by optimizing spatial and functional constraints. Together, these methods demonstrate the power of RL in enhancing alignment, correctness, and efficiency across generative models.