Skip navigation
Frontier models can generate very nice images from code.
0:00 / 1:05

Frontier models can generate very nice images from code.

Liang Zheng

@LiangZheng_061.4K followers

Visit on X
254 likesDownloadOriginal post

14,096 views

Frontier models can generate very nice images from code. Can we train open-source LLMs for image generation, and how? Check out Pictor-27B, our code-based image generation model post-trained from Qwen. Given a prompt, Pictor-27B writes JS code, which is rendered into an image in browser. This unlocks a new reward signal: the code. Which reward is best: image, code or both? Both. 1/n

22 Comments

Comments from the original post on X (Twitter)

  • Liang Zheng's profile picture

    @LiangZheng_06

    Why code? Three reasons. 1. Deterministic rendering: better code means a better image. 2. Interpretable: every image comes from a program you can read and edit. 3. Scales with coding ability: a better coding model is a better image generator. 2/n

    7 likes

  • Liang Zheng's profile picture

    @LiangZheng_06

    We evaluate 14 LLMs on five benchmarks: GenEval2, PRSIM, GenOlypiad, Wise, and DPG-bench. LLMs are stronger than diffusion image models on tasks requiring strong reasoning. Full leaderboard: 3/n

    4 likes

  • Liang Zheng's profile picture

    @LiangZheng_06

    We develop an SFT+RL baseline for Qwen post-training. - We use a mixture of GPT models as teachers and SFT the Qwen model. - We use a set of prompts for GRPO. We use the rendered image for computing the reward with a GPT judge. 4/n

    5 likes

  • Liang Zheng's profile picture

    @LiangZheng_06

    drawback of image-only reward: visual misjudgement. drawback of code-only reward: can't see. image+code reward trains the best model. Our final recipe: Qwen-27B + SFT + GRPO with image+code reward. 5/n

    5 likes

  • Liang Zheng's profile picture

    @LiangZheng_06

    Paper: GitHub: Hugging Face: Project page: Amazing work by @nicolewangr @xingjian_leng @zinho_leung 6/n

    12 likes

  • Wilco Kruijer's profile picture

    @WilcoKr

    3d models next?

    1 like

  • Liang Zheng's profile picture

    @LiangZheng_06

    well, yeah, 3d and videos would be interesting.

    1 like

  • tenshin's profile picture

    @MixtTensi8198

    This is amazing! Thank you for the github also! :)

    1 like

  • Dominik's profile picture

    @EternitiesAI

    writing code that renders the image makes the output easy to inspect.

    1 like

  • Liang Zheng's profile picture

    @LiangZheng_06

    yeah, verification becomes easier by inspecting the code. but there can also be errors, e.g., an object in the code may be occluded in the rendered image. so perhaps using both image and code for reward modeling.

  • Kevin Ngo's profile picture

    @kevin_t_ngo

    very cool! all of the art on my personal website were made with code

    1 like

  • Liang Zheng's profile picture

    @LiangZheng_06

    retire diffusion models?

  • Viz's profile picture

    @reachmeviz

    Great experiment, though I wonder why train the model specifically to generate code that renders as a static image? Why not train it to generate native HTML/Canvas components directly? That could make it easier to build Claude Opus–style motion graphics too.

  • Featherless AI's profile picture

    @FeatherlessAI

    This looks very cool. Has python code performance been tested as well? For example, python is very useful to create scenes in blender for 3d image generation.

  • Liang Zheng's profile picture

    @LiangZheng_06

    we only did JS code. it's absolutely interesting to think about python and blender for 3d gen!

  • Daniel's profile picture

    @XDanielDev

    did you guys try a final t2i? also how does it do with reflections, I have this prompt: A scrambled 3x3 Rubik's cube placed beside a mirror, clearly showing its mirror reflection. Beside the cube is a wine glass filled to the brim, and a clock shows the hands placed at 5 and 8.

  • Liang Zheng's profile picture

    @LiangZheng_06

    this can be added to GenOlympiad prompt base😅 - looks pretty challenging. will see the results later

  • Daniel's profile picture

    @XDanielDev

    Yeah, I believe the only one that kinda solve it is nano banana pro, maybe 2.1 with thinking? GPT always messes up the reflected cube stickers

  • Liang Zheng's profile picture

    @LiangZheng_06

    i think Astra and Fable might do a better job. we tested such hard prompts on GenOlympiad - LLMs are generally better than diffusion.

  • Daniel's profile picture

    @XDanielDev

    It’s unfortunate, it would be nice to have precision like this locally. SN-U1.6 would be nice with the code planning. What’s really needed is also the agentic self correction, maybe not so much however if starting from code-generated images

    1 like