Circular Transformers and General-Purpose Coding: The Next Paradigm for AI Programming
As AI models move beyond code completion and bug fixing, code is becoming a general-purpose medium for generating interactive experiences. This article examines how general-purpose coding depends on executable intermediate representations, how Circular Transformers trade parameters for iterative inference, and how automated validation, infrastructure optimization, and safety controls can support reliable long-horizon generation.
1. The Starting Point: Programming Ability Is Being Redefined
Over the past two years, the industry has largely evaluated AI coding ability through tasks such as completing a function or fixing an error. A new trend is now emerging: models are no longer merely writing code. They are using code as a medium to generate videos, animations, mini-games, dashboards, and even complete interactive narrative experiences. This expansion from “code generation” to “generating almost anything through code” can be described as general-purpose coding.
Its evaluation should not focus only on whether a model can produce syntactically correct software. Three capabilities matter more:
- Can it translate vague natural-language intent into an executable structure?
- Can it independently create visuals, text, and interaction logic without external assets?
- Can it preserve consistency across long chains of tasks without gradually breaking down?
2. Why Code Can Serve as a General-Purpose Intermediate Representation
Treating code as an intermediate representation (IR) is not merely a metaphor. It is an engineering necessity.
- Executable: Natural-language descriptions cannot be directly validated by machines, while code can. Runtime behavior provides an objective signal for correctness instead of relying entirely on human judgment.
- Composable: DOM elements, Canvas primitives, shaders, state machines, and animation timelines are all nestable components. Complex works can be assembled from simpler components, which naturally fits the model’s decomposition-based generation process.
- Iterative: Code is plain text and can be read back into the context for local repairs, creating a loop of “generate, run, observe, and correct.”
- Compact: A few hundred lines of front-end code can encode a visual information density comparable to several minutes of video, while consuming far less context than multimodal assets.
This also explains why general-purpose coding evaluations should distinguish among three dimensions:
- Visual coding: Writing rendering logic based on a visual objective.
- Visual reproduction: Reconstructing the structure and styling of a reference image.
- Long-horizon tasks: Preserving the original goal across multiple rounds and files without drifting.
These dimensions increase in difficulty. They respectively test one-shot generation quality, perception-to-code accuracy, and state retention.
3. Circular Transformers: Trading Parameters for Depth
There are traditionally two ways to improve model capability: increasing width by expanding hidden dimensions, or increasing depth by stacking more layers. The former sharply increases memory and bandwidth requirements, while the latter raises inference latency roughly in proportion to the number of layers. Circular Transformers offer a third approach: iteration within a layer.
The core idea is to repeatedly reuse the same weights while progressively refining the hidden state. This creates an effective depth that is much greater than the parameter depth. A simplified example is shown below:
def loop_block(x, shared_layer, n_steps, gate):h = xfor t in range(n_steps):h_new = shared_layer(h)# Adaptive gating: iterate more for hard samples and stop early for easy onesg = gate(h_new, t)h = (1 - g) * h + g * h_newreturn h
The main challenge is not the architecture itself, but compressing the additional overhead. This requires close coordination with inference infrastructure:
- Adaptive step counts: Easy tokens can stop early instead of paying the same iteration cost as every other token.
- In-batch alignment: Different iteration counts can disrupt regular batch processing, requiring bucketing or masking strategies.
- Caching policies: Whether intermediate states are cached, and which projections are reused, directly affects memory consumption.
- Operator fusion: Fusing normalization, gating, and projection operations within the iterative process can reduce kernel launches and repeated memory transfers.
In other words, the benefits of a circular architecture are not free. Only joint optimization of model structure, serving-side scheduling, batching, and cache management can convert its theoretical advantages into real throughput.
4. Generating Interactive Works Without External Assets
Consider a task that provides no images or audio and asks the model to create a pixel-art narrative short film and a multi-ending game based only on textual intent. The process can be abstracted into five stages:
- Intent structuring: Break the creative request into structured fields such as timelines, characters, scenes, and ending branches.
- Programmatic asset generation: Draw all visuals through code, including sprites, palettes, and frame-by-frame movement. Synthesize sound effects with oscillators.
- State-machine design: Branching narratives are essentially finite-state machines. Nodes, conditions, and transitions must be modeled explicitly.
- Closed-loop validation: Run the generated work automatically, then use headless-browser screenshots and assertions to check rendering and transitions.
- Local repair: Feed only failed segments back into the context instead of rewriting the entire work, which helps prevent style drift.
// Minimal branching-narrative skeletonconst scenes = {origin: { text: "1993, a corner of a restaurant", next: ["garage", "chip"] },garage: { text: "The first board powers on", next: ["ipo"] },chip: { text: "Choosing an architectural direction", next: ["ipo", "crisis"] },crisis: { text: "Cash flow reaches the bottom", next: ["comeback"] },comeback:{ text: "Taking the helm again", next: ["endingA"] },ipo: { text: "Going public", next: ["endingB"] }};function step(state, choice) { return scenes[state].next[choice] ?? "endingC"; }
From an engineering perspective, the fourth stage deserves the most attention. Without automated validation, general-purpose coding systems will inevitably lose control of long-horizon tasks after enough iterations.
5. Evaluation and Performance: Do Not Focus on a Single Number
Real-world evaluation should cover multiple types of engineering tasks and examine four metrics together:
- Pass rate
- First-pass success rate
- Number of manual repair rounds
- Long-horizon consistency
A single speed metric has limited value. The throughput of the same service can differ substantially between peak and off-peak periods. In practice, first-token latency, streaming stability, and degradation under long-context workloads often have a greater impact on user experience.
Performance can be improved through request routing, batch aggregation, cache-hit optimization, quantization, and operator-level optimization. These efforts should be supported by logging, monitoring and alerting, and distributed tracing to identify bottlenecks. Static outputs and assets are suitable for object storage, while elastic compute can be provided through a container platform.
6. Rollout Strategy and Risk Control
Capability releases typically follow three stages: first, a gradual rollout to subscribers; next, integration with mainstream AI coding tools and IDE plugin ecosystems; and finally, weight release after security hardening is complete.
Organizations adopting these systems should prepare for three requirements in parallel:
- Sandbox isolation and dependency allowlists for generated code
- Compliance and copyright review for generated outputs
- Resource quotas for usage limits and team collaboration
Baidu AI Cloud can serve as one possible infrastructure foundation for this type of generation-and-validation pipeline through general-purpose capabilities such as container platforms, object storage, logging, and monitoring.
7. Conclusion
The essence of general-purpose coding is to turn code from a “deliverable” into a method of generation. The essence of Circular Transformers is to trade inference-time computation for parameter efficiency.
Together, they point to the same conclusion: the next competitive frontier for foundation models is not simply whether they can write code. It is whether they can use code as a general-purpose language to transform intent into stable, verifiable, and interactive reality.
