Papers
Topics
Authors
Recent
Search
2000 character limit reached

FlexCAD: Unified Controllable CAD Generation

Updated 13 July 2026
  • FlexCAD is a unified, LLM-based system for controllable CAD generation that edits specific hierarchy levels using structured text representation.
  • It employs a hierarchy-aware masked-span infilling strategy to enable precise instance selection and consistent modifications across sketch-and-extrude hierarchies.
  • The system demonstrates high validity and robust performance on the DeepCAD benchmark, outperforming existing CAD generation baselines.

Searching arXiv for the FlexCAD paper and its baseline methods. FlexCAD is a unified, LLM-based system for controllable CAD generation across all sketch-and-extrude modeling hierarchies. It takes an existing CAD model plus a user’s intent specifying what to change, and produces multiple new models that alter only the selected part while preserving the rest of the construction. The system is introduced in “FlexCAD: Unified and Versatile Controllable CAD Generation with Fine-tuned LLMs” (Zhang et al., 2024), where controllable generation is framed over six levels—sketch-extrusion, extrusion, sketch, face, loop, and curve—within sketch-and-extrude modeling (SEM). Its central premise is that SEM CAD can be re-expressed as structured text and edited through hierarchy-aware masked-span infilling by a fine-tuned LLM.

1. Problem setting and conceptual scope

FlexCAD addresses controllable CAD generation, defined as creating CAD models based on user intent while changing only the selected construction component and preserving the remaining structure (Zhang et al., 2024). The motivating problem is that prior controllable CAD generators either provide limited control or require separate models per control type, making workflows inefficient and brittle. The paper further identifies three limitations of codebook-based approaches: they cannot select a specific instance when multiple sketches or extrusions exist, they do not handle finer levels such as faces, loops, and curves, and they may fail to maintain consistency when only part of a model should change (Zhang et al., 2024).

The underlying rationale is hierarchical. In SEM, curves form loops, loops form faces, faces form sketches, and sketches are extruded into 3D bodies. FlexCAD is therefore designed around the observation that real design edits occur at multiple levels of this hierarchy, not merely at the whole-object or sketch level. A unified model is presented as a way to share knowledge across hierarchies, including geometric priors and topology conventions, while reducing engineering overhead and avoiding mismatched behaviors across separately trained models (Zhang et al., 2024).

The paper states three main contributions. First, it introduces a concise text representation of SEM CAD, in which each hierarchy is abstracted into a sequence of tokens that is shorter, more interpretable, and more LLM-friendly than prior one-hot encodings. Second, it defines a hierarchy-aware masking strategy for fine-tuning LLMs, where the masked field is a hierarchy-aligned token span such as a specific extrusion or a set of curves in a loop. Third, it presents a unified model that supports control at all six levels and reports strong quality and controllability on the DeepCAD benchmark, surpassing SkexGen, Hnc-cad, and few-shot GPT-4o in the reported controlled-generation evaluations (Zhang et al., 2024).

2. Structured text representation of SEM CAD

FlexCAD converts a SEM CAD model into structured text by serializing each construction hierarchy into sequences of tokens with explicit delimiters (Zhang et al., 2024). The representation is compositional: curves are the finest elements, loops are concatenations of curve tokens, faces are concatenations of loops, sketches are concatenations of faces, and sketch-extrusion assemblies are formed by a sketch followed by its extrusion. A CAD model with multiple sketch-extrusions is represented by concatenating all sketch-extrusion texts.

At the geometric level, curves are typed tokens with numeric parameters. A line uses one point token plus the next curve’s first point to implicitly define the segment, and coordinates are stored as integer coordinates (x,y)(x, y). An arc is represented by three points as integer coordinates. A circle is represented by four points uniformly distributed along the circumference; the paper states that this four-point variant proved robust (Zhang et al., 2024). Points are discretized 2D integer coordinates, consistent with prior discretization practice.

Structural delimitation is explicit. A special token H_endH\_end marks the end of each hierarchy H{curve,loop,face,sketch,extrusion}H \in \{\text{curve}, \text{loop}, \text{face}, \text{sketch}, \text{extrusion}\} (Zhang et al., 2024). This yields a text format in which parent structures are recoverable from token boundaries alone, without custom structural encodings beyond delimiters and hierarchy tokens.

Extrusion parameters are also textual tokens. They are represented as a fixed-length sequence “BVVTTTRRRRRRRRRSOO” with 18 fields: Boolean operation, top and bottom displacements, 3D translation, 3D rotation as a 3×33 \times 3 matrix, uniform scale, and 2D center of scaling (Zhang et al., 2024). The Boolean operation is one of add, cut, or intersect.

The token vocabulary therefore contains four categories: entity and type tokens such as curve, loop, face, sketch, and extrusion; curve-type subtokens line, arc, and circle; numeric tokens for coordinates and extrusion parameters; and structural delimiters such as H_endH\_end. For controllable generation, additional hierarchy-specific mask tokens are introduced, including [sketch-extrusion mask], [sketch mask], [extrusion mask], [face mask], [loop mask], [line mask], [arc mask], and [circle mask] (Zhang et al., 2024).

This representation has two stated consequences. It makes CAD sequences shorter and more interpretable than prior one-hot encodings, and it aligns CAD construction with the token-sequence regime for which decoder-only LLMs are already optimized. A plausible implication is that the explicit hierarchy boundaries reduce ambiguity during infilling by turning localized edits into contiguous masked spans.

3. Hierarchy-aware masking and learning objective

The training paradigm in FlexCAD is masked-span infilling over hierarchy-specific fields (Zhang et al., 2024). Let the CAD text be a token sequence X=(x1,,xn)X = (x_1, \ldots, x_n). A hierarchy h{CAD,sketch-extrusion,extrusion,sketch,face,loop,curve}h \in \{\text{CAD}, \text{sketch-extrusion}, \text{extrusion}, \text{sketch}, \text{face}, \text{loop}, \text{curve}\} is selected, and then a contiguous span Sh={is,,ie}S^h = \{i_s, \ldots, i_e\} corresponding to a hierarchy-aware field is chosen. The tokens in that span are replaced by a hierarchy-specific mask token mhm_h, and the model is trained to predict the target tokens YShY_{S^h} conditioned on the unmasked context, instruction, and hierarchy (Zhang et al., 2024).

The objective is an autoregressive cross-entropy infilling loss:

H_endH\_end0

The paper also gives the equivalent masked-span likelihood form H_endH\_end1 and minimizes the negative log-likelihood (Zhang et al., 2024).

Mask selection is hierarchy-dependent. At CAD level, internal sketch-extrusions are masked to vary the number of sketch-extrusions and composition. At sketch-extrusion level, an entire sketch-extrusion is replaced by [sketch-extrusion mask]. At sketch level, a specific sketch is masked with [sketch mask]; at extrusion level, one extrusion is masked with [extrusion mask]. Face and loop control can mask one or multiple faces or loops, with multiple mask tokens used jointly when needed. Curve control masks all curves within a loop using type-aware masks such as [line mask], [arc mask], and [circle mask], allowing topology to be preserved or altered by retaining or changing the type and number of masked curves (Zhang et al., 2024).

A distinctive aspect of the training regime is unified training. At each epoch and for each CAD text, the method uniformly samples a hierarchy and its corresponding prompt template. This is intended to ensure that a single model learns all control tasks end-to-end and can transfer knowledge across levels (Zhang et al., 2024). The ablation data supports the importance of this design: for sketch-level control, random masking contiguous tokens yields PV 90.6%, removing hierarchy-specific mask tokens yields PV 91.5%, training only on sketch-level yields PV 92.2%, and the full hierarchy-aware unified setting yields PV 93.4% (Zhang et al., 2024).

The masking strategy is also the mechanism by which instance selection becomes possible. Because the masked span is a specific contiguous token subsequence, the system can target, for example, “extrusion #2” or “loop #1 in sketch #0” rather than editing an unspecified occurrence. This directly addresses the paper’s critique that earlier methods cannot select a specific instance when multiple sketches or extrusions exist (Zhang et al., 2024).

4. Model architecture, data, and inference workflow

FlexCAD uses Llama-3-8B as the base LLM, described as a standard decoder-only Transformer with rotary positional embeddings (Zhang et al., 2024). Adaptation is performed through LoRA fine-tuning with rank H_endH\_end2 and alpha H_endH\_end3, training only approximately H_endH\_end4 of parameters, about H_endH\_end5 million, while keeping the base model frozen. The paper also reports experiments with Llama-3-70B using LoRA, with about H_endH\_end6 million trainable parameters and approximately H_endH\_end7 of the total parameters (Zhang et al., 2024).

The model uses the Llama-3 tokenizer over the textual CAD tokens, augmented with special tokens for H_endH\_end8 and the hierarchy-specific masks (Zhang et al., 2024). Training is carried out on DeepCAD, consisting of 178,238 SEM sequences, split into 90% train, 5% validation, and 5% test after removing duplicates and invalid sequences following SkexGen. The implementation uses the Transformers library, four NVIDIA A6000 GPUs, batch size 32, the AdamW optimizer, a cosine-annealed learning rate of H_endH\_end9, and 30 epochs. The reported training time is approximately 20 hours for 8B LoRA and approximately 80 hours for full-parameter 8B fine-tuning (Zhang et al., 2024).

At inference time, user intent is encoded by masking the desired hierarchy field in the CAD text and providing an instruction. The workflow is: convert the original CAD model to structured text, identify the hierarchy and specific instance to modify, replace the target field with the appropriate mask token or tokens, build an instruction describing the edit or simply indicating the mask is to be infilled, decode with sampling settings, splice the predicted tokens back into the CAD text, and parse the completed text back to SEM for 3D rendering (Zhang et al., 2024). The default decoding settings are temperature H{curve,loop,face,sketch,extrusion}H \in \{\text{curve}, \text{loop}, \text{face}, \text{sketch}, \text{extrusion}\}0 and top-H{curve,loop,face,sketch,extrusion}H \in \{\text{curve}, \text{loop}, \text{face}, \text{sketch}, \text{extrusion}\}1.

The paper provides representative edit patterns. An extrusion-depth change is implemented by replacing the tokens for a selected extrusion with [extrusion mask], yielding new extrusion tokens with the updated top displacement while keeping other fields consistent. Loop regeneration is performed by masking a loop and optionally giving curve-type guidance such as two arcs and two lines. A face-level edit, such as adding a second inner loop to a face, may use multiple [loop mask] tokens jointly. These examples illustrate the paper’s broader claim that consistency across hierarchies is maintained by serializing tokens so that edits at a finer level propagate correctly to parent levels while non-masked structures remain unchanged (Zhang et al., 2024).

5. Supported control regimes and empirical performance

FlexCAD supports control at CAD level, sketch-extrusion level, extrusion level, sketch level, face level, loop level, and curve level (Zhang et al., 2024). CAD-level control masks internal sketch-extrusions to vary count and complexity. Sketch-extrusion control modifies one sketch-extrusion while leaving others unchanged. Extrusion control can change the Boolean type and transform parameters of a selected extrusion. Sketch control can replace an entire sketch while preserving the associated extrusion. Face and loop control permit local topological edits such as adding inner loops or rewriting a loop as an arc-line-arc-line pattern. Curve control adjusts geometry while optionally preserving topology, for example by masking the four lines in a loop and regenerating only their coordinates (Zhang et al., 2024).

Evaluation uses Coverage (COV), Minimum Matching Distance (MMD), Jensen–Shannon Divergence (JSD), Novel, Unique, Prediction Validity (PV), and Realism (Zhang et al., 2024). COV, MMD, and JSD measure diversity and quality relative to the test set; Novel is the percentage of generated models not in training; Unique is the percentage appearing only once in the generated set; PV is the fraction that render to valid 3D solids; and Realism is human preference versus training data.

For sketch-level and extrusion-level control, the paper reports results from 10k generations per method and a 3k test subset for COV, MMD, and JSD (Zhang et al., 2024).

Method Sketch-level Extrusion-level
GPT-4o COV 58.2%, MMD 1.34, JSD 1.43, Novel 69.7%, Unique 72.8%, PV 62.3%, Realism 23.2% COV 53.3%, MMD 1.42, JSD 2.14, Novel 58.6%, Unique 65.3%, PV 48.8%, Realism 19.7%
SkexGen COV 60.6%, MMD 1.27, JSD 1.51, Novel 90.7%, Unique 93.5%, PV 68.7%, Realism 34.8% COV 63.6%, MMD 1.23, JSD 1.44, Novel 89.3%, Unique 89.1%, PV 76.1%, Realism 35.2%
Hnc-cad COV 62.4%, MMD 1.21, JSD 1.07, Novel 87.6%, Unique 92.1%, PV 72.6%, Realism 36.3% COV 65.6%, MMD 1.25, JSD 1.38, Novel 86.2%, Unique 87.8%, PV 79.7%, Realism 38.0%
FlexCAD COV 65.6%, MMD 1.19, JSD 0.82, Novel 92.1%, Unique 92.6%, PV 93.4%, Realism 39.6% COV 68.5%, MMD 1.19, JSD 1.32, Novel 87.6%, Unique 90.4%, PV 93.3%, Realism 42.1%

These results show that FlexCAD achieves the highest PV in both reported controlled settings and the lowest MMD in both settings, with the lowest JSD at sketch level and better Realism than the baselines listed in the paper (Zhang et al., 2024). For other hierarchies, the paper reports FlexCAD-only PV values of 91.8% at CAD level, 90.5% at sketch-extrusion level, 93.2% at face level, 90.5% at loop level, and 90.2% at curve level, with comparable COV, MMD, and JSD across levels (Zhang et al., 2024).

The ablations further characterize the role of pretraining, model scale, and adaptation strategy. For sketch-level control, Transformer-4M without pretraining reaches PV 80.2%; Llama-3-8B-from-scratch reaches 89.5%; Llama-3-8B full fine-tuning with pretraining reaches 91.7% at approximately 80 hours; Llama-3-8B-Instruct LoRA reaches 90.5%; FlexCAD with Llama-3-8B LoRA reaches 93.4% at approximately 20 hours; and Llama-3-70B LoRA reaches 94.6% at higher cost (Zhang et al., 2024). This indicates that the reported gains arise not only from scale but also from the hierarchy-aware and unified fine-tuning formulation.

In unconditional generation, FlexCAD reports COV 89.2%, MMD 0.91, JSD 1.53, PV 90.5%, and Realism 51.5%; the paper adds that JSD improves to 0.78 when relaxing PV to approximately 80% via sampling settings (Zhang et al., 2024). This makes explicit a diversity-validity trade-off that also appears in the sensitivity study: higher temperature and top-H{curve,loop,face,sketch,extrusion}H \in \{\text{curve}, \text{loop}, \text{face}, \text{sketch}, \text{extrusion}\}2 increase diversity and uniqueness but reduce PV, motivating the default choice H{curve,loop,face,sketch,extrusion}H \in \{\text{curve}, \text{loop}, \text{face}, \text{sketch}, \text{extrusion}\}3 and top-H{curve,loop,face,sketch,extrusion}H \in \{\text{curve}, \text{loop}, \text{face}, \text{sketch}, \text{extrusion}\}4 to keep PV above 90% (Zhang et al., 2024).

6. Limitations, operational trade-offs, and prospective directions

The paper identifies several limitations and failure modes. Data imbalance affects rare topologies: loops with 5–8 lines can yield irregular polygonal shapes, whereas 4-line loops are much more common and therefore better predicted (Zhang et al., 2024). Efficiency is another limitation. Inference latency is approximately 0.56 s per sample for Llama-3-8B, compared with 0.15 s for SkexGen and 0.38 s for Hnc-cad, while 70B inference is approximately 3 s (Zhang et al., 2024). The authors characterize the trade-off as one of higher controllability and unified deployment versus higher memory use and latency than specialized small models.

Constraint interactions remain challenging. The paper notes that complex geometric or parametric constraints and long dependency chains across hierarchies may challenge purely text-based infilling, leading to minor inconsistencies (Zhang et al., 2024). Tokenization sensitivity is also reported: numeric discretization and the choice of circle representation influence performance, with the four-point circle showing a slight edge. Another limitation is ambiguity in user intent. Vague instructions can produce diverse but not precisely intended results; clearer hierarchical masks and type hints help (Zhang et al., 2024).

These limitations shape the future directions proposed in the paper. The first is constraint-aware decoding, integrating geometric or parametric constraint solvers into decoding to ensure exact feasibility. The second is multimodal conditioning through sketches, images, or point clouds. The third is post-generation geometric validation such as manifoldness or tolerance checks. Additional directions include incorporating structural, thermal, or kinematic simulation signals, improving numeric handling through mixed discrete–continuous representations, and extending toward richer instruction following in text-to-CAD settings with multimodal LLMs (Zhang et al., 2024).

In application terms, the system is positioned for CAD design workflows, human-in-the-loop editing, design exploration, and interoperability with existing CAD systems via its text representation (Zhang et al., 2024). The article’s evidence supports a narrower technical conclusion: FlexCAD demonstrates that SEM CAD can be treated as a language-like sequence domain in which hierarchy-specific masked infilling provides a single-model alternative to multi-model controllable CAD pipelines. This suggests that the principal contribution of FlexCAD is not merely higher validity metrics, but the consolidation of control, instance selection, and cross-hierarchy consistency into one end-to-end LLM fine-tuning framework (Zhang et al., 2024).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to FlexCAD.