INQUIRING LINE

Many different CadQuery scripts can build the exact same 3D shape — so how should an AI learn to write 'correct' CAD code?

Why do multiple CadQuery scripts produce geometrically equivalent CAD models?

This explores why many different CadQuery programs (CadQuery is a Python library for scripting 3D CAD models) can build the same physical shape, and what that means for training AI to write CAD code.


This explores why many different CadQuery programs can build the same 3D shape, and why that matters for teaching AI to write CAD code. The basic reason is simple, and the corpus takes it as given rather than studying it: a CAD script is a recipe, not a description of the finished part. You can make a box with one primitive call, or by drawing a rectangle and extruding it, or by cutting a block down to size. You can put a hole in before or after a fillet, or measure from a different reference point. Every one of these steps is different code, but they all end in the same solid. The corpus is more useful on the next question: if many scripts are equally right, how do you train a model to find one of them?

This is where the many-scripts problem starts to bite. Plain supervised fine-tuning teaches the model to copy one reference script, token by token. It ends up penalized for choosing a different but equally valid way to build the part, and it isn't directly rewarded for getting the shape right. The result is a telling gap: fine-tuning alone gives about 91% runnable code but only about 50% geometric overlap with the target (Can CAD code be syntactically correct yet geometrically wrong?). The model learns what CAD code looks like before it learns what the code builds.

The fix in the corpus is to stop comparing code and start comparing shapes. CAD-Coder runs each generated script, renders the solid, and rewards the model for how close the result lands to the target shape, measured with a point-cloud distance (Chamfer distance) (Can executing generated code measure CAD generation quality?). Because any script that builds the right geometry gets full credit, the many-scripts problem stops being a source of noise. The ablation shows this geometric reward does most of the work, cutting error from 74.55 to 17.34. Adding step-by-step planning brings it down to 6.54, and the authors credit planning with helping the model reach equivalent solutions instead of one memorized path (What drives CAD-Coder's improvement over supervised fine-tuning alone?). CAD-RL goes further with three task-specific rewards and reaches 99.6% runnable code and about 79% geometric accuracy (Can task-specific rewards outperform general pretraining for CAD code?).

The same pattern shows up well beyond CAD. In language, same-meaning prompts are not treated as equal: models respond to how common a phrasing is, not just what it means (Why do semantically identical prompts produce different LLM outputs?). CAD is the useful mirror image. There, a deterministic program (the CAD kernel) collapses many surface forms into one checkable result, which is exactly what makes a reliable reward possible. Turning math into formal proof code has the same many-to-one shape: there are many valid ways to formalize a theorem, and the real difficulty is the surrounding library of definitions (Can autoformalization work statement by statement?).

The takeaway you might not have expected: the fact that many CadQuery scripts give the same model isn't a curiosity. It's the reason the field moved from imitating code to rewarding geometry. Whenever many outputs are equally correct, grading the result instead of the wording is what lets reinforcement learning beat imitation.


Sources 6 notes

Can CAD code be syntactically correct yet geometrically wrong?

Supervised fine-tuning alone produces 91% executable CAD code but only 50% geometric IoU. Chain-of-thought reasoning raises IoU to 61%, while RL post-training pushes it to 72%, showing the two capabilities decouple during early training.

Can executing generated code measure CAD generation quality?

CAD-Coder trains LLMs to write executable CadQuery code, then uses GRPO with Chamfer Distance to the target shape as a geometric reward signal. This approach reduces mean Chamfer Distance to 6.54 and outperforms existing text-to-CAD systems while maintaining low code invalidity rates.

What drives CAD-Coder's improvement over supervised fine-tuning alone?

CAD-Coder's ablation shows SFT alone achieves Mean CD 74.55, adding GRPO jumps to 17.34, and including chain-of-thought reasoning reaches 6.54. The geometric reward directly optimizes 3D correctness, while planning helps capture equivalent solutions.

Can task-specific rewards outperform general pretraining for CAD code?

CAD-RL, trained with three domain-specific rewards and chain-of-thought guidance, achieves 99.63% executability and 78.7% geometric IoU under structured input, outperforming CAD-Coder by +8.3% IoU and +3.39% executability. This suggests hand-specified rewards can unlock latent reasoning in pretrained models for precise code generation.

Why do semantically identical prompts produce different LLM outputs?

Cao et al. and Adam's Law show that semantically identical prompts with different sentence-level frequencies produce systematically different output quality. Higher-frequency phrasings win because models register statistical mass from pre-training, not meaning.

Show all 6 sources
Can autoformalization work statement by statement?

Real formalization demands constructing entire interdependent libraries of axioms, definitions, and lemmas—not just translating single theorems. The Kepler conjecture formalization took 11 years mostly building this scaffolding.

Papers this line draws on 8

The research behind the notes this line reads — ranked by how closely each paper relates.