Code-based Image Generation: Benchmarking, Baselines, and Improved Rewards
Select an image to read its program.
Abstract
Code-based image generation
An LLM generates code, and a renderer turns it into an image
Image generation models, such as diffusion and autoregressive models, generate images in pixel or latent spaces. An LLM instead generates code, and a renderer turns the program into an image. We call this paradigm code-based image generation (CIG).
An image model generates in latent space; an LLM generates a program that a fixed renderer draws
CIG has three useful features.
- Deterministic rendering. A fixed renderer executes the code, so improving image quality reduces to improving the code.
- Interpretable. Each image comes from a program that can be read.
- Scales with coding capabilities. A better coding model is a better image generator.
CIG also allows a new reward signal: the judge can read the program, understand how the image is constructed, and check the prompt against it. But each single input has a drawback.
The same judge gives different answers when shown the image, the program or both
An image-only judge struggles to tell what a crude shape is meant to be. A program-only judge struggles to tell whether an object in the code is visible.
Can open-source LLMs learn CIG from stronger models? Yes: after SFT and GRPO, our model, Pictor-27B, matches or beats its teacher mix.
Does having the program enable a better reward? Yes: the judge shown both gains GenEval2 GM over the base model, against for the program alone and for the image alone.
Images are programs
Read and edit an image as a program
A program can be read, changed and rendered again. The renderer is fixed, so a better image needs a better program.
Each teaser image is a program you can read and run
The model reads a text prompt and writes a JavaScript program. The renderer is headless Chrome. It opens a blank 512×512 page with no network and runs the program for at most 60 seconds. Rendering is deterministic, so a better image needs a better program.
Change a value in the program and the image follows
Program 11, read-only
Prompt
Method
Two stages: SFT, then GRPO
Stage 1 is supervised fine-tuning on prompt-program pairs from three teachers: GPT-5.6 Luna, Terra and Sol write 50%, 30% and 20% of the programs. A program is kept if it renders a non-blank image within the token limit. Stage 2 is GRPO: for each prompt the model writes programs, and a judge scores each one.
One GRPO step: one prompt, a group of programs
Four rewards differ only in what the judge is shown
| Reward | prompt | image | program | judge calls |
|---|---|---|---|---|
| IR | ✓ | ✓ | – | 1 |
| PR | ✓ | – | ✓ | 1 |
| IPR | ✓ | ✓ | ✓ | 1 |
| avgR | ✓ | mean of the IR and PR scores | 2 | |
PR, IPR and the PR call of avgR read a cleaned program, with comments and unused code removed. The image is always rendered from the original program.
Benchmarking
Leaderboard
How well do LLMs draw with code?
Frontier models like GPT-6 Astra and Gemini 4 Argon have very strong scores, reaching about 70 on DPG-Bench and 40 strict score on GenOlympiad. Open-weight models and small language models like DeepSeek-V4.1-Flash and Claude Haiku 5.5 are worse.
Select a model to see six of its images.
Image modelLLM Ours, IPR in green
Ours: Pictor-27B is Qwen3.8-27B after SFT, then GRPO with the image+program reward (IPR). Pictor-27B-SFT is the model after SFT only. Pictor-27B-IR, -PR and -avgR replace IPR with the image-only, program-only or averaged reward. Pictor-9B starts from Qwen3.5-9B.
How do LLMs compare with image models?
GPT-Image-2.5 has the strongest scores on GenEval2, PRISM-Bench, DPG-Bench and WISE, but is inferior to LLMs on GenOlympiad, possibly because GenOlympiad needs reasoning, at which LLMs are strong.
GPT-Image-2.5 has the strongest scores on GenEval2 and PRISM-Bench but is inferior to LLMs on GenOlympiad
Larger and newer models score higher. GPT-6 Astra is above GPT-5.6 Sol, and GPT-6 Luna is above GPT-5.6 Luna, on all five benchmarks.
Baselines
Can open-source LLMs learn CIG from stronger models?
Yes. SFT and GRPO take Qwen3.8-27B from to GenEval2 GM, above its teacher mix at .
Pictor-27B passes its teacher mix on GenEval2 after SFT and GRPO
SFT fixes most failed renders. At 27B, render success goes from % to %. At 9B it goes from % to %. GRPO raises it to % and %.
Does model size matter?
Yes. GenEval2 AM of the base models goes from near 0 (0.8B) to (27B); after SFT and GRPO it goes from to .
A larger LLM is a better CIG model, before and after post-training
Select a model size to see the scores.
Improved rewards
Does having the program enable a better reward?
Yes. The image+program reward (IPR) trains a better model. It scores higher than the image-only (IR), program-only (PR) and averaged rewards on 9 of 11 metrics, including out-of-distribution benchmarks, and people prefer its images to those of the IR model.
IPR is best on 9 of the 11 metrics, in and out of distribution
Same eight prompts, six of our models
Is the IPR gain reliable?
Yes. People prefer the images from the IPR model, and the gains of IPR over IR and SFT are significant.
The IR model gains little after update 50, while IPR keeps rising
Each reward trains its own GRPO model from the same SFT model for 250 updates. We call a difference clear when it is statistically significant (95% interval on one side of zero).
In a blind study, people prefer the images of the IPR model
IPR is clearly above IR in three training setups
With four programs per prompt, IPR is clearly above every other reward
Why does IPR train the best model?
IR separates correct from incorrect images less than PR and IPR, and IPR follows the lower of the IR and PR scores.
Higher agreement with humans does not mean a better reward. The agreement of IR and IPR with humans is similar, but IR trains the weakest models. A potential reason is that agreement only checks which image scores higher, while GRPO also uses how far apart the scores are.
Ruled out
IR scores 90 or more to half of the incorrect images
An image is correct if it passes every GenEval2 item for its prompt, and incorrect otherwise. For about half of the incorrect images, the reasoning of IR names no error.
IR scores correct and incorrect images closer together than PR and IPR
This suggests the IR judge gives correct images a weaker advantage during GRPO.
Inside the candidate groups of the SFT model
The near-ties and the high scores repeat: IR % of pairs within 5 points, IPR %; incorrect scored 90 or more: % and %. The mean gap between a correct and an incorrect program is similar for every judge ( to points).
Which judge counts best?
The judge shown both. It matches human counts on % of counts with both inputs, % with the image and % with the program.
Hide an elephant from the image only, and the program judge cannot react
A correct program for “four pink elephants” loses one elephant.
elephant() calls, lines 236–241
The same test on 68 programs
The removed version disables the first elephant() call. The program has no randomness, so deleting that line draws the same image. Mean change in judge points over 68 correct programs:
Exact counts by what the judge sees
IPR follows the lower of the IR and PR scores
When PR is higher than IR by 20 points or more, the mean scores are for IR, for PR and for IPR. avgR gives . Fit within prompts: IPR = IR + PR + min(IR, PR).
Programs only one judge likes
SFT programs on 100 GenEval2 prompts, by which judges score them 70 or more. A program only one judge likes usually has an error, and IPR scores it low.
Programs on which the two single-input judges disagree or agree
Further analysis
A judge that reads can be tricked by written instructions
A fake program end raises the PR score by and the IPR score by . Removing comments and unused code before judging stops it.
A fake program end raises the score without changing the image
“”, last lines
A judge that reads the program also reads anything written in it. Training uses cleaned programs.
edits raise the score; cleaning removes them
The IPR judge uses the fewest reasoning tokens per call
IPR’s ranking among correct programs follows the program
The IR model does not improve under its own judge
Why each is ruled out
IR is a less accurate judge.
IR agrees with the majority of raters % of the time and IPR %. Their models gain and GM over SFT.
The IPR model only looks better to its own judge.
Under the IR judge, the IPR model is clearly above the IR model, by points.
IR was held back by tight gradient clipping.
With clipping at 1.0 instead of 0.02 (shorter-SFT and other-prompts setups), IR is still GM below IPR. The IPR model writes Canvas more often (% against % of programs). In the shorter-SFT setup both mostly write Canvas (% and %) and IR still ends below, so format does not explain the gain.
Paper and citation