Monday, September 14, 2026
TheAI NEWS

The World's Leading Intelligence & Artificial Intelligence Journal

AI & ModelsSep 6, 20264 min read

Training a coding model to paint watercolours with TRL and OpenEnv

An open-source research team has demonstrated how to train small coding models to generate realistic watercolour paintings using Transformer Reinforcement Learning (TRL) and interactive execution environments (OpenEnv).

Ajinkya Pawar

By Ajinkya Pawar

Head of Search & AI Intelligence • The AI NEWS

Training a coding model to paint watercolours with TRL and OpenEnv
Training a coding model to paint watercolours with TRL and OpenEnv

Key Developments & Executive Briefing

Executive Briefing
01

Teaching Language Models to Paint Using Python Code

Reinforcement LearningCode-to-Art

Researchers used TRL and OpenEnv to train a lightweight coding model to output procedural rendering code that generates high-fidelity digital watercolour art.

02

Interactive Feedback Replaces Blind Supervised Learning

Environment FeedbackZero-Loss Loop

Rather than predicting pixel tokens directly, the model executes brush stroke commands in an isolated sandbox and optimizes based on visual perceptual loss.

03

Blueprints for Agentic Execution Feedback

Developer TakeawayOpen Weights

The technique provides a repeatable architecture for training code models to solve complex, multi-step tasks where output quality can only be evaluated post-execution.

A viral machine learning experiment published on Hugging Face demonstrates how open-source developers can train small language models to paint realistic digital watercolours using reinforcement learning and interactive execution feedback.

Authored by researchers using Hugging Face's TRL (Transformer Reinforcement Learning) library and the OpenEnv framework, the project explores an intriguing alternative to standard diffusion models: teaching coding LLMs to write procedural Python scripts that physically simulate watercolour physics, brush pressure, and pigment diffusion.

The project paper and codebase, titled *"Training a coding model to paint watercolours with TRL and OpenEnv"*, has quickly climbed developer ranking boards on GitHub and Hacker News.

Why Procedural Code Beats Blind Diffusion

Most modern image generators (like Midjourney or Stable Diffusion) operate as dense diffusion networks, predicting pixel values directly from noise vectors. While visually impressive, they are notorious black boxes: users cannot edit individual brushstrokes, adjust pigment layers, or inspect how the artwork was constructed.

The Hugging Face researchers took a radically different path:

  1. 1.The LLM Writes Executable Canvas Commands: The model does not output images. Instead, it outputs Python scripts using graphics libraries like PyCairo and NumPy to render procedural splatters, brush washes, and translucent pigment blending.
  2. 2.The OpenEnv Feedback Sandbox: The generated code is compiled and executed in a headless sandbox environment.
  3. 3.Reward Modeling: An automated visual critic compares the rendered image against a target reference, assigning a reward score based on color harmony, texture accuracy, and stroke efficiency.
  4. 4.Policy Updates with TRL: The model updates its code generation policy using PPO (Proximal Policy Optimization), learning which mathematical formulas produce realistic wet-on-wet watercolour bleeding.

According to the author's notes:

"In every single training run, the first thing the model learned was to stop producing invalid Python syntax and runtime crashes. Once it achieved deterministic execution, it rapidly developed complex layering techniques—laying down light background washes first before applying detailed dry-brush outlines, mimicking the exact technique human watercolorists use."

What This Unlocks for Software Engineers

Beyond digital art, this research offers a compelling blueprint for software engineering agents operating in the real world:

  • Self-Correcting Execution Loops: Models trained with environment feedback learn how their code behaves at runtime, drastically reducing syntax and logic bugs.
  • Compact Footprint: Because the model only outputs lightweight text commands, the entire system runs on modest compute clusters without needing multi-GPU diffusion backends.
  • Deterministic Reproducibility: Every painting is a clean, version-controlled Python script that can be scaled infinitely to any resolution without pixelation.

The training scripts, reward functions, and OpenEnv configurations are available openly on Hugging Face.

Discussion (0)

avatar

Be the first to share insights on this story.