IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. XX, NO. XX, XX 2026
1
From Mirage to Grounding: Towards Reliable Multimodal Circuit-to-Verilog Code Generation
arXiv:2604.27969v1 [cs.SE] 30 Apr 2026
Guang Yang, Xing Hu∗ , Xiang Chen, and Xin Xia
Abstract—Multimodal large language models (MLLMs) are increasingly used to translate visual artifacts into code, from UI mockups into HTML to scientific plots into Python scripts. A circuit diagram can be viewed as a visual domain-specific language for hardware: it encodes timing, topology, and bitlevel semantics that are invisible to casual inspection yet safetycritical once fabricated in silicon. Translating such diagrams into register-transfer-level (RTL) code therefore represents an extreme reliability test for vision-to-code generation. We reveal a phenomenon we call Mirage: replacing a circuit diagram with a blank image leaves Pass@k unchanged or even higher, because models bypass the visual input and instead exploit identifier semantics in the module_header to retrieve canonical RTL templates. This constitutes a new, highly covert class of defect in AI-assisted code generation that directly undermines MLLMs’ trustworthiness. To quantify the effect, we construct C2VE VAL and evaluate eight MLLMs under a paired Normal/Anony protocol in which Anony mode anonymizes all identifiers in both the diagram and the module header; Anony-mode scores drop sharply across all models, confirming that high Normal-mode accuracy is largely a Mirage. We then propose VeriGround (4B), trained with identifier anonymization, refusal augmentation, and D-ORPO (Decision-Focused ORPO) preference alignment that up-weights pivotal generate-or-refuse tokens. VeriGround achieves Functional Pass@1 of 46.11%/42.51% (Normal/Anony) with a False Refusal Rate of only 1.20%/0.00%, while maintaining ≥92% Refusal Rate on blank images. With only 4B parameters, VeriGround performs on par with GPT-5.4 under Normal and significantly outperforms all baselines under Anony, confirming genuine visual grounding. The evaluation methodology and training recipe generalize beyond hardware: C2VE VAL’s paired protocol can benchmark any vision-to-code pipeline, and VeriGround’s anonymization-refusal-alignment triad offers a transferable solution for balancing hallucination and over-refusal in AI code generation. Index Terms—multimodal large language models, vision-tocode generation, visual grounding, software trustworthiness, Verilog.
I. I NTRODUCTION Image-to-code generation has become a central paradigm in AI-assisted coding. From UI mockups rewritten as HTML [1]– [6], to scientific plots reverse-engineered into reproducible Python scripts [7]–[9], multimodal large language models (MLLMs) are shifting the front-end of software creation from Corresponding author: Xing Hu. Guang Yang is with the State Key Laboratory of Blockchain and Data Security, Zhejiang University, Hangzhou, China, and also with the Hangzhou HighTech Zone (Binjiang) Institute of Blockchain and Data Security, Hangzhou, China. Xing Hu and Xin Xia are with the State Key Laboratory of Blockchain and Data Security, Zhejiang University, Hangzhou, China. Xiang Chen is with the School of Artificial Intelligence and Computer Science, Nantong University, Nantong, China. E-mail: [email protected], [email protected], [email protected], [email protected]. Manuscript received April 19, 2020; revised August xx, xxxx.
Fig. 1. Motivating example 1 of the Mirage phenomenon. The model generates correct code regardless of whether the input contains the real circuit diagram or a blank image.
purely textual specifications toward richer visual artifacts. In each of these tasks, the visual input can be viewed as a visual domain-specific language (visual DSL): a UI mockup specifies layout and interaction semantics, a chart encodes data and rendering logic, and each must be faithfully translated into executable code. Recently, this paradigm has been extended to hardware: MLLMs are used to translate circuit diagrams into synthesizable register-transfer-level (RTL) code, a task we call circuit-to-Verilog code generation [10], [11]. A circuit diagram is arguably the demanding visual DSL, because it encodes timing, topology, and bit-level semantics that are invisible to casual inspection yet safety-critical once fabricated in silicon. While unreliable vision-to-code translation is a general concern across all visual DSLs, the consequences in the hardware domain are uniquely severe [12], [13]. RTL sits at the very beginning of the silicon design flow and feeds downstream into synthesis, place-and-route, and fabrication; a single misread schematic can propagate silently through the entire toolchain and materialize as a silicon-level defect whose cost is orders of magnitude higher than a rendering or plotting error. More broadly, if an AI code generator appears to “understand” a visual specification while actually bypassing it, the resulting code carries a covert correctness risk that conventional testing may not catch. This directly threatens MLLMs’ trustworthiness, a core concern of the software engineering community. Circuit-to-Verilog generation therefore serves as a rigorous proving ground: any reliability flaw exposed here is likely
IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. XX, NO. XX, XX 2026
2
Fig. 2. Motivating example 2 of the Mirage phenomenon. When the real circuit diagram is provided, the model generates incorrect Verilog that fails the testbench. When the diagram is replaced by a blank image while the module_header is retained, the model instead produces correct code.
to manifest, in milder but equally insidious forms, in other vision-to-code pipelines. Although recent studies have demonstrated the feasibility of using MLLMs to read circuit diagrams and generate Verilog code, a fundamental question remains largely unexplored: do existing MLLMs truly read circuit diagrams, or merely exploit textual shortcuts? Our motivating examples make this concern concrete. In both Fig. 1 and Fig. 2 the model under test is Opus 4.6, one of the current frontier code-generation models. Following standard practice, the module_header (module name, ports, and parameters) is provided as part of the prompt so that the generated interface matches the testbench and Pass@k can be computed without name-mismatch failures. Yet this seemingly innocuous input turns out to be a powerful textual shortcut. In Fig. 1, the model produces identical correct code for a half-adder whether the input contains the real circuit or a blank image: the module name TopModule is semantically vacuous, but the output ports sum and cout already reveal the target function, making the diagram redundant. Fig. 2 is even more striking: for fsm_3state, the model fails with the real diagram yet succeeds with a blank image, suggesting that the visual input can actively interfere with generation. We term this failure mode the Mirage phenomenon [14]: high benchmark scores mask the fact that models rely on textual priors in the module_header rather than genuinely grounding in the visual circuit topology. Mirage constitutes a new, highly covert class of AI code-generation defect: the output may compile and even pass certain tests, yet it was
never derived from the visual specification, leaving latent errors that surface only in untested scenarios. A natural way to test this hypothesis is to anonymize the identifiers in both the module_header and the circuit diagram, thereby stripping the semantic cues that enable such shortcuts. Following this idea, we construct C2VE VAL (Circuit-toVerilog Evaluation), a benchmark that samples problems from established Verilog code-generation benchmarks and renders each reference solution into a circuit diagram via NETLISTSVG 1 , ensuring exact image-code correspondence. C2VE VAL has two variants: Normal, which retains the original identifiers in both the diagram and the module header, and Anony (anonymized), which replaces all semantically loaded identifiers with positional placeholders and re-renders the diagram accordingly, preserving circuit topology while removing semantic cues. We evaluate eight MLLMs, from 4B opensource models to frontier systems, under each variant in two modes: Original (real diagram provided) and Mirage (diagram replaced by a blank image, header retained). Three findings emerge: (i) under Normal, Mirage mode matches or exceeds Original on every model, suggesting that models largely bypass the circuit diagram and sometimes perform worse when it is present; (ii) under Anony, the Mirage advantage reverses for seven of eight models, isolating identifier semantics in the header as the primary driver of Normal-mode performance; and (iii) genuine visual grounding accounts for only ∼8–9% of samples, with the vast majority of tasks remaining unsolved 1 https://github.com/nturley/netlistsvg
IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. XX, NO. XX, XX 2026
once identifier shortcuts are removed. Based on these findings, we first curate a large-scale circuitdiagram-to-Verilog dataset by mining high-quality Verilog projects from GitHub and converting each design into a circuit diagram. We then introduce VeriGround (4B), a lightweight MLLM trained with three targeted interventions that together address the hallucination-vs-refusal trade-off common to all vision-to-code generators: (i) mixed supervised fine-tuning on Original and Anony data to reduce reliance on semantically loaded identifiers; (ii) refusal augmentation with blankdiagram and image-header-mismatch negatives, teaching the model to abstain when visual evidence is absent or inconsistent; (iii) D-ORPO (Decision-Focused ORPO) alignment, which up-weights the first K response tokens with a decision weight α, concentrating the preference signal on the generateor-refuse boundary and mitigating the over-refusal problem of standard ORPO [15]. Extensive experiments demonstrate that VeriGround effectively reverses the Mirage phenomenon. With only 4B parameters, VeriGround achieves Functional Pass@1 of 46.11% under Normal, approaching GPT-5.4 (45.51%) and surpassing GPT-4o (33.52%) and MiMo-v2-omni (37.72%); under Anony, VeriGround reaches 42.51%, significantly outperforming all baselines (p < 0.001, McNemar’s test). Meanwhile, the False Refusal Rate on valid inputs is reduced to 1.20%/0.00% (Normal/Anony) while the Refusal Rate on blank inputs remains above 92%. In summary, this paper makes four contributions: 1) Phenomenon. We identify and document the Mirage phenomenon: all eight evaluated MLLMs produce equal or higher scores when the circuit diagram is removed, and genuine visual grounding accounts for only ∼8–9% of samples. 2) Benchmark & Evaluation. We construct C2VE VAL with exact image-code correspondence and a paired Normal/Anony×Original/Mirage protocol that isolates identifier semantics as the single variable. 3) Method. We propose VeriGround (4B), trained with identifier anonymization, refusal augmentation, and DORPO (Decision-Focused ORPO) alignment. 4) Evaluation. VeriGround achieves Functional Pass@1 of 46.11%/42.51% (Normal/Anony) with False Refusal Rates of only 1.20%/0.00%, while maintaining ≥92% Refusal Rate on blank inputs. To facilitate the replication of VeriGround, we make our source code, trained models, and benchmark publicly available on GitHub.2 The remainder of this paper is organized as follows. Section II introduces the background and problem definition. Section III presents the empirical study that motivates the approach. Section IV details the proposed method. Section V reports the experimental results. Section VI discusses hyperparameter sensitivity, mismatch refusal, and threats to validity. Section VII reviews related work. Section VIII concludes the paper. 2 https://github.com/NTDXYG/VeriGround
3
II. BACKGROUND AND P RELIMINARIES A. Multimodal Large Language Models A multimodal large language model (MLLM) [16], [17] extends a text-only LLM to process both visual and textual inputs. Given a visual input I and a textual prompt T , an MLLM M auto-regressively generates an output sequence Ŷ = (y1 , . . . , yL ): P (Ŷ | I, T ; θ) =
L Y
P (yt | y<t , I, T ; θ),
(1)
t=1
where θ denotes the model parameters. Existing MLLMs broadly fall into two architectural paradigms. Connector-based MLLMs adopt a three-component architecture. A visual encoder (e.g., ViT [18]–[20]) extracts a feature sequence zv = Enc(I); a connector (typically an MLP) projects it into the LLM embedding space, yielding visual tokens hv = Proj(zv ); an LLM backbone then generates conditioned on [hv ; ht ], where ht = Embed(T ) is the text token embedding sequence. Representative models include LLaVA [21]–[23] and InternVL [24], [25]. Native multimodal MLLMs forgo the connector and jointly train vision and language components within a unified transformer. A visual encoder produces hv = Enc(I) and a token embedding layer produces ht = Embed(T ); both sequences are fed directly into a shared backbone without an intermediate projection, with decoupled parallel strategies for the heterogeneous modalities to maintain training efficiency. Representative models include Gemini [26], [27] and GPT4o [28]. B. Circuit-to-Verilog Code Generation We now specialize the MLLM formulation in Eq. (1) to the circuit-to-Verilog setting. Definition 1 (Circuit-to-Verilog Code Generation). Given a circuit diagram image I and a module header H, the task is to generate a Verilog module body V̂ such that the complete module H ⊕ V̂ is both syntactically valid and functionally equivalent to the reference implementation H ⊕V ∗ , where ⊕ denotes concatenation and V ∗ is the ground-truth module body. The textual prompt takes the form T = (instruction, H), where the instruction is a fixed task description. Since the instruction is constant across all samples, we abbreviate the generation as: V̂ = M(I, H). (2) We next detail the two variable inputs to M. Definition 2 (Module Header). A module header H specifies the external interface of a Verilog module [29]: H = module name [#(params)] (ports);
(3)
where name is the module identifier, params is an optional parameter list, and ports specifies input/output ports with their directions and bit-widths. In standard practice, H is always provided so that the generated interface matches the testbench and evaluation can proceed without name-mismatch failures.
IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. XX, NO. XX, XX 2026
Definition 3 (Circuit Diagram). A circuit diagram I is a visual representation of the target circuit’s topology, depicting gates, flip-flops, multiplexers, and their interconnections [30]. In our setting, each diagram is rendered from V ∗ via NETLISTSVG, so the labels in I correspond exactly to the identifiers in V ∗ . III. E MPIRICAL S TUDY A. Benchmark Construction To investigate the Mirage phenomenon, we construct C2VE VAL, a circuit-to-Verilog benchmark with exact imagecode correspondence. The construction follows a three-stage pipeline. Stage 1: Seed dataset collection. We source problems from four established Verilog code-generation benchmarks: VerilogEval-v2 [31], [32], RTLLM-v2 [33], [34], ResBench [35], and ArchXBench [36], which collectively span diverse circuit categories, each accompanied by a complete testbench. Stage 2: Reference code curation. For each seed problem, we generate candidate Verilog solutions with two frontier MLLMs (GPT-5.4 and Opus-4.6) and simulate each candidate against the corresponding testbench; only solutions passing all assertions are retained as verified reference implementations V ∗. Stage 3: Diagram rendering and filtering. Each V ∗ is rendered into a circuit diagram via NETLISTSVG and rasterized to JPEG at 96 DPI, producing image I whose labels correspond exactly to the identifiers in V ∗ (Definition 3). Samples that fail to render or whose I exceeds 2,048 visual tokens under the Qwen-3.5 tokenizer are discarded. 1) Normal and Anony variants.: The above pipeline yields the Normal variant of C2VE VAL. To test whether high Normal-mode accuracy is a Mirage driven by identifier semantics rather than genuine visual understanding, we further construct an Anony (anonymized) variant: for each sample, the module name is replaced with a generic module_name, and all port and parameter identifiers are replaced with positional placeholders val_0, val_1, . . . ; the anonymized code is then re-rendered through the same Stage 3 pipeline to produce a new diagram Ianon paired with an anonymized header Hanon . The circuit topology is preserved; only the semantic cues are removed. For example, the following Normal-mode header: module sync_fifo #(DEPTH=32, WIDTH=8) (clk, rst_n, wr_en, rd_en);
is anonymized to: module module_name #(val_0=32, val_1=8) (val_2, val_3, val_4, val_5);
The corresponding circuit diagram is re-rendered with the same positional placeholders, ensuring that the only way to produce correct code is to read the visual topology. 2) Benchmark statistics.: The resulting C2VE VAL comprises 169 samples. Each sample is a tuple (I, H, V ∗ , T , D) together with its anonymized counterpart (Ianon , Hanon ), where I is the circuit diagram, H is the module header (Definition 2), V ∗ is the reference module body, T is the testbench, and D is the natural-language functional description.
4
TABLE I C ATEGORY DISTRIBUTION OF C2VE VAL .
Category
Count
Ratio
Basic Combinational Logic Sequential Building Blocks Finite State Machines Mathematical Operations & Algo.
81 43 32 11
48.5% 25.7% 19.2% 6.6%
Total
169
100%
Fig. 3. Token-count distributions (left: density histograms; right: CDFs) for circuit-diagram images (top, blue) and module headers (bottom, orange) in C2VE VAL.
Table I reports the category distribution: Basic Combinational Logic constitutes the largest share (48.5%), followed by Sequential Building Blocks (25.7%) and Finite State Machines (19.2%), with Mathematical Operations & Algorithms as the smallest category (6.6%). This distribution reflects the natural composition of introductory-to-intermediate RTL design tasks in the seed benchmarks. Fig. 3 visualizes the token-count distributions of the two inputs. Circuit-diagram images exhibit a heavy right-skewed distribution (µ = 340.6, median = 133.0): approximately half of the diagrams encode within 133 tokens, yet a few complex designs exceed 1,500 tokens. Module headers, by contrast, are remarkably compact (µ = 33.5, median = 30.0), with over 90% falling below 60 tokens. This order-of-magnitude asymmetry is noteworthy: the header occupies less than onetenth of the visual token budget, yet it encodes the module name, port names, and parameter values, which collectively carry rich semantic information. B. Empirical Setup 1) Evaluated Models: We evaluate eight MLLMs spanning 4B to frontier-scale parameters. The proprietary group includes GPT-4o [37], GPT-5.4 [38], Opus-4.6 [39], and MiMo-v2-omni [40]. The open-source group includes EGM4B, EGM-8B [41], Qwen3.5-4B, and Qwen3.5-9B [42]. Each
IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. XX, NO. XX, XX 2026
5
TABLE II PASS @k (%) ON C2VE VAL UNDER THE N ORMAL AND A NONY BENCHMARK VARIANTS . M IRAGE MODE REPLACES THE CIRCUIT DIAGRAM WITH A BLANK IMAGE WHILE THE MODULE HEADER IS RETAINED . B OLD DENOTES THE HIGHER SCORE BETWEEN O RIGINAL AND M IRAGE IN EACH PAIR .
Model GPT-5.4 GPT-4o MiMo-v2-omni Opus-4.6 EGM 4B EGM 8B Qwen3.5 4B Qwen3.5 9B
Normal
Mode
Anony
Syn. @1
Syn. @5
Func.@1
Func.@5
Syn. @1
Syn. @5
Func.@1
Func.@5
Original Mirage Original Mirage Original Mirage Original Mirage
97.60 100.00 92.22 94.61 85.03 86.23 98.20 100.00
– – – – – – – –
45.51 47.90 39.52 39.52 37.72 41.32 52.69 63.47
– – – – – – – –
93.41 100.00 79.64 94.01 79.64 82.63 88.62 99.40
– – – – – – – –
24.55 6.59 16.17 8.38 19.16 5.99 11.38 14.97
– – – – – – – –
Original Mirage Original Mirage Original Mirage Original Mirage
79.04 83.83 37.72 83.83 38.32 56.89 70.66 76.05
98.20 99.40 64.67 95.81 76.50 94.10 97.60 99.40
18.56 20.36 10.18 22.75 7.78 10.78 14.97 19.76
29.94 31.14 23.35 36.53 19.16 25.75 32.34 38.92
50.90 33.53 22.16 23.95 35.33 61.68 62.28 79.04
93.41 86.83 71.26 73.65 78.44 98.80 92.22 100.00
4.19 0.60 0.60 0.60 5.99 2.40 8.38 3.59
10.78 7.78 8.38 5.99 12.57 5.39 14.97 7.78
model is evaluated under both the Normal and Anony variants of C2VE VAL. 2) Evaluation Metrics: We adopt two Pass@k metrics computed with the unbiased estimator [43], [44]. Syntax Pass@k measures the probability that at least one of k sampled completions yields a syntactically compilable Verilog module. Functional Pass@k measures the probability that at least one of k completions passes all testbench assertions under simulation. Functional correctness implies syntactic validity, so Functional Pass@k ≤ Syntax Pass@k. 3) Implementation Details: Due to API cost constraints, proprietary models are reported as Pass@1 only. Open-source models are served locally; we sample n = 5 completions per problem at temperature = 0.7 and report both Pass@1 and Pass@5. All compilation and simulation are performed with Icarus Verilog 3 . C. Empirical Findings Finding 1: The Mirage phenomenon is universal: removing the circuit diagram does not degrade, and often improves, code generation. Under the Normal benchmark, Mirage mode matches or exceeds Original mode on every model across all metrics (Table II). The most extreme case is EGM 8B, whose Syntax Pass@1 jumps by 46 points upon removing the circuit diagram, while Opus-4.6 sees a Functional gain of over 10 points. The same trend holds at Pass@5: all four open-source models see Mirage surpass Original on every metric, ruling out singlesample variance. A sample-level decomposition (Table III) corroborates this pattern: on average, 13.1% of samples are solved by Mirage only versus 8.2% by Original only, meaning the diagram actively impairs generation on 60% more samples than it aids. 3 https://github.com/steveicarus/iverilog
TABLE III S AMPLE - LEVEL F UNCTIONAL PASS @1 BREAKDOWN (%) ON C2VE VAL (167 SAMPLES ). E ACH SAMPLE IS CATEGORIZED BY WHETHER O RIGINAL AND M IRAGE EACH PRODUCE CORRECT CODE .
Model
Both
Original
Mirage
Neither
GPT-5.4 GPT-4o MiMo-v2 Opus-4.6
35.3 30.5 26.3 43.1
10.2 9.0 11.4 9.6
12.6 9.0 15.0 20.4
41.9 51.5 47.3 26.9
EGM 4B EGM 8B Qwen3.5 4B Qwen3.5 9B
10.2 7.8 2.4 5.4
8.4 2.4 5.4 9.6
10.2 15.0 8.4 14.4
71.3 74.9 83.8 70.7
Avg.
20.1
8.2
13.1
58.5
GPT-5.4 GPT-4o MiMo-v2 Opus-4.6
6.0 4.2 2.4 4.8
18.6 12.0 16.8 6.6
0.6 4.2 3.6 10.2
74.9 79.6 77.2 78.4
EGM 4B EGM 8B Qwen3.5 4B Qwen3.5 9B
0.0 0.0 0.6 1.8
4.2 0.6 5.4 6.6
0.6 0.6 1.8 1.8
95.2 98.8 92.2 89.8
Avg.
2.5
8.8
2.9
85.8
Normal
Anony
Finding 2: Identifier semantics in the module header, not visual understanding, are the primary driver of Normal-mode performance. Anonymization strips semantic identifiers while preserving circuit topology. Under the Anony benchmark, the Mirage advantage vanishes: Original surpasses Mirage on Functional Pass@1 for seven of eight models (Table II), and this reversal extends to Pass@5 for all four open-source models. At the
IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. XX, NO. XX, XX 2026
6
Fig. 4. Training pipeline of VeriGround.
sample level (Table III), the Both category, i.e., samples solved by both modes, collapses from 20.1% to 2.5%, confirming that the vast majority of Normal-mode joint successes were driven by header-based shortcuts rather than diagram comprehension. Correspondingly, aggregate Functional Pass@1 drops drastically upon anonymization (e.g., GPT-5.4: 45.51 → 24.55; Opus-4.6: 52.69 → 11.38), further isolating identifier semantics as the dominant factor.
A. Dataset Collection
a) Step 1: Source collection.: Approximately 150K synthesisable Verilog snippets are harvested from public GitHub repositories, spanning a broad spectrum of hardware designs. b) Step 2: Synthesisability verification.: Each snippet is compiled with YOSYS [46] and discarded if synthesis fails, ensuring that every retained sample corresponds to a valid hardware design. c) Step 3: Benchmark decontamination.: To prevent data leakage, we remove any sample whose Rouge-L [47] similarity with the test sets exceeds 0.5. d) Step 4: Difficulty filtering.: Samples for which Qwen2.5-Coder-7B/32B-Instruct can produce a functionally correct solution within five attempts (verified via formal equivalence checking [45]) are discarded, retaining approximately 87K non-trivial instances. e) Step 5: Circuit-diagram rendering.: Each retained reference implementation V ∗ is synthesised into a gate-level netlist and rendered as an SVG schematic via NETLISTSVG. Samples that fail to render are excluded, leaving approximately 67K Circuit–Verilog pairs. f) Step 6: Visual-token budget filtering.: The SVG schematics are rasterised to JPEG at 96 DPI. Samples whose image exceeds 2,048 visual tokens under the Qwen-3.5 tokenizer are discarded, yielding the Normal training set of 27,260 samples. g) Anonymised variant.: Applying the same anonymisation procedure used for C2VE VAL (Section III-A), we replace all semantically loaded identifiers with positional placeholders and re-render the corresponding circuit diagrams, producing the Anony training set of 26,756 samples. The Normal and Anony sets are merged into a unified corpus Dall of 54,016 samples.
We construct a large-scale circuit-diagram-to-Verilog training corpus through a six-step pipeline. Steps 1–4 follow the data-curation workflow of CodeV-R1 [45]; Steps 5–6 extend it with diagram rendering and visual-token budgeting.
B. Mixed Supervised Fine-Tuning We partition Dall into two disjoint subsets: a seed pool Dalign of 5,000 samples reserved for the subsequent alignment
Finding 3: Genuine visual grounding is extremely limited, accounting for only ∼8–9% of samples. The Original-only rate in Table III, which captures samples where the diagram is necessary and sufficient for correct generation, remains nearly identical across Normal (8.2%) and Anony (8.8%). This stability suggests that approximately 8– 9% of samples contain visual cues that models can genuinely extract irrespective of whether identifiers carry semantic meaning. Beyond this small fraction, current MLLMs largely fail to leverage circuit diagrams: under Anony, 85.8% of samples are solved by neither mode, indicating that once identifier shortcuts are removed, the overwhelming majority of circuitto-code tasks remain out of reach. IV. M ETHOD Figure 4 illustrates the overall training pipeline of VeriGround, which consists of three stages: (i) training data collection and anonymisation, (ii) supervised fine-tuning (SFT) on the mixed Normal + Anony corpus, and (iii) preference alignment with D-ORPO.
IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. XX, NO. XX, XX 2026
7
Prompt Template
TABLE IV P REFERENCE - PAIR COMPOSITION FOR THE ALIGNMENT STAGE .
Please write a Verilog module based on the provided circuit diagram image. Return only the Verilog code, without any explanation.
Cat.
Image condition
Chosen yw
Rejected yl
Ratio
M ATCH B LANK M ISMATCH
Correct diagram Blank image Unrelated diagram
Verilog Refusal Refusal
Refusal Verilog Verilog
40% 30% 30%
For example: ‘‘‘verilog your Verilog code here ‘‘‘ Module header (must not be changed): {module_header}
Refusal Response Template Based on the provided circuit diagram, I cannot accurately determine the Verilog implementation. The module header provided is: {module_header} However, the provided image does not match the given module header, so I cannot generate the correct Verilog code with confidence. Fig. 5. Prompt and refusal templates used for preference-pair construction. {module_header} is instantiated with the sample-specific header H.
stage (Section IV-D), and Dsft = Dall \Dalign (49,016 samples) used for supervised fine-tuning. Each SFT instance is a triple (I, H, V ∗ ), where I denotes the circuit diagram, H the module header, and V ∗ the reference Verilog module body. The model Mθ is optimised with the standard autoregressive objective:
rejected response yl follows the refusal template in Figure 5. This category reinforces the model’s generation capability, ensuring that valid visual evidence is not spuriously refused. b) Category B LANK (30%).: The circuit diagram is replaced with a blank white image I∅ , while the module header H is retained. The chosen response follows the refusal template; the rejected response is the header-matching code V ∗ . By explicitly penalising code generation in the absence of visual input, this category directly targets the Mirage shortcut. c) Category M ISMATCH (30%).: The circuit diagram I ′ is sampled from a different instance in Dalign such that I ′ depicts a circuit unrelated to H. Refusal is again chosen over the header-matching code. This category trains the model to detect semantic inconsistency between the visual and textual modalities, rather than defaulting to header-driven generation. Ratio design. Each source sample in Dalign naturally yields exactly one M ATCH pair, one B LANK pair, and one M IS MATCH pair, giving a raw ratio of 1 : 1 : 1. We observe that this equal split over-represents refusal-preferred pairs (two out of three categories choose refusal), biasing the model toward over-refusal. To counterbalance, we up-sample M ATCH to 40% and assign 30% each to B LANK and M ISMATCH, yielding a 4 : 3 : 3 split that keeps the three categories close in size while giving the generation-preferred category a slight majority.
|V ∗ |
LSFT = −
X
∗ log pθ (vt∗ | I, H, v<t ),
(4)
t=1
where vt∗ denotes the t-th token of V ∗ . Because Dsft interleaves Normal and Anony samples in roughly equal proportion, the same module header H appears with both semantically loaded and anonymised identifiers across different instances. This compels the model to ground its predictions in the visual topology of I rather than memorising identifier-to-template mappings, as a direct countermeasure to the Mirage phenomenon identified in Section III-C. C. Preference Pair Construction The alignment stage operates on preference pairs (yw , yl ) (chosen vs. rejected), each conditioned on an input (I, H). A well-calibrated circuit-to-Verilog model should produce correct code when the diagram faithfully depicts the target circuit, and refuse to answer when the visual evidence is absent or inconsistent with the header. All three categories share the unified prompt and refusal templates shown in Figure 5. We derive three complementary categories of preference pairs from Dalign , summarised in Table IV. a) Category M ATCH (40%).: The input pairs a matching circuit diagram I with its corresponding module header H. The chosen response yw is the reference module body V ∗ ; the
D. D-ORPO: Decision-Focused ORPO 1) ORPO Background: Preference alignment methods such as DPO [48] and GRPO [49] impose significant overhead on multimodal models: DPO doubles memory by maintaining a frozen reference model, while GRPO requires costly online rollouts with high-resolution image encoding. ORPO [15] avoids both costs by unifying supervised learning and preference optimisation in a single, reference-free objective. Given a preference pair (yw , yl ) conditioned on input x, ORPO combines the negative log-likelihood (NLL) of the chosen response with an odds-ratio (OR) penalty: 1 X log pθ (yw,t | x, yw,<t ) + β · LOR , (5) LORPO = − |yw | t | {z } LNLL
where β controls the preference strength and the OR term is oddsθ (yw | x) LOR = − log σ log , (6) oddsθ (yl | x) with oddsθ (y | x) ≜ pθ (y | x) / (1 − pθ (y | x)). In practice, the sequence-level log-probability is replaced by its token-level average: T
ℓ̄θ (y | x) =
1X log pθ (yt | x, y<t ), T t=1
(7)
IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. XX, NO. XX, XX 2026
where T = |y|. Note that every token contributes equally to ℓ̄θ ; we revisit this assumption below. 2) Motivation: In our generate-or-refuse setting, the binary decision is fully determined by the first few response tokens (cf. Figure 5): once the model emits ‘‘‘verilog it is committed to code generation, whereas a refusal opens with Based on the ..., I cannot ... . This creates a length asymmetry: code responses span hundreds of tokens while refusals contain only tens, so the uniform weighting of Eq. 7 dilutes the odds-ratio gradient on the pivotal opening tokens. We observe that this dilution leads to over-refusal: the model favours the shorter refusal path even for valid inputs, because the uniform odds ratio provides insufficient gradient on the initial decision to generate. 3) Formulation: To address this, we propose D-ORPO (Decision-Focused ORPO), which assigns a higher weight α > 1 to the first K response tokens in both the NLL and OR objectives. Let r = min{t : yt is a response token} denote the index of the first response token. We define a per-token weight function: ( α, if r ≤ t < r + K, wt = (8) 1, otherwise, where K is the decision window size and α is the decision weight. The weighted average log-probability replaces Eq. 7: PT wt · log pθ (yt | x, y<t ) D . (9) ℓ̄θ (y | x) = t=1 PT t=1 wt
8
Algorithm 1: D-ORPO Training Input: SFT-initialised model Mθ ; preference dataset Dpref ; decision window K; decision weight α; OR coefficient β Output: Aligned model Mθ (i) (i) B 1 for each mini-batch {(xi , yw , yl )}i=1 from Dpref do 2 Forward pass: compute per-token log-probs log pθ (yt | x, y<t ) for both yw and yl ; 3 Compute per-token weights wt via Eq. 8; 4 Compute ℓ̄θD (yw | x) and ℓ̄θD (yl | x) via Eq. 9; 5 Compute LD-ORPO via Eq. 10; 6 Update θ via back-propagation on LD-ORPO ;
Proof. (1) follows by direct substitution. For (2), dΓ/dα = K(Tr − Tc )/[αK + (Tr − K)]2 < 0 since Tr < Tc . For (3), dividing numerator and denominator by αK gives Γ → 1. Property (1) quantifies the imbalance under standard ORPO: the decision gradient fraction for the short refusal is Tc /Tr times that for the long code response, causing the OR objective to steer the decision boundary toward refusal far more strongly than toward generation. Properties (2) and (3) guarantee that D-ORPO monotonically reduces this imbalance toward unity as α increases. Algorithm 1 summarises the D-ORPO training procedure.
E. Training Details
measures the fractional contribution of the K decision tokens to the gradient of ℓ̄θD (Eq. 9). When α = 1, this reduces to K/T .
We instantiate VeriGround, initialised from Qwen3.5-4B. VeriGround is fine-tuned with LoRA [50] (r=16, αLoRA =16, dropout = 0) applied to all attention and MLP projection matrices in both the vision encoder and the language backbone. Training proceeds in two sequential stages. a) Stage 1: Supervised fine-tuning.: The model is trained on Dsft (49,016 samples) for 5 epochs using AdamW (8-bit) with a learning rate of 2 × 10−4 , and a maximum sequence length of 4,096 tokens. We hold out the last 5,000 samples as a validation set, evaluate every 1,000 steps, and retain the checkpoint with the lowest validation loss. b) Stage 2: D-ORPO alignment.: Starting from the best SFT checkpoint, we perform one epoch of D-ORPO training on the preference pairs derived from Dalign (Section IV-C). The learning rate is reduced to 5×10−6 . The D-ORPO-specific hyper-parameters are set to decision window K=8, decision weight α=2.0, and OR coefficient β=0.1.
Proposition 1 (Gradient Rebalancing). Let Tc > Tr > K denote the lengths of a code response and a refusal response, respectively. The decision gradient imbalance ratio
V. E XPERIMENTAL R ESULTS
Substituting ℓ̄θD for ℓ̄θ in Eqs. 5 and 6 yields the D-ORPO objective: D D LD-ORPO = LNLL + β · LOR . (10) When α = 1, D-ORPO reduces to standard ORPO, confirming it as a strict generalisation. 4) Theoretical Analysis: Definition 4 (Decision Gradient Fraction). For a response of length T with decision window K ≤ T and weight α ≥ 1, the decision gradient fraction ϕ(T, K, α) ≜
Γ(α) ≜
αK αK + (T − K)
ϕ(Tr , K, α) αK + (Tc − K) = ϕ(Tc , K, α) αK + (Tr − K)
satisfies: 1) Γ(1) = Tc /Tr ; 2) Γ(α) is strictly decreasing in α for all α ≥ 1; 3) limα→∞ Γ(α) = 1.
(11)
(12)
This section evaluates VeriGround along two research questions: RQ1: Does VeriGround improve grounded code generation? • RQ2: Does VeriGround refuse unreliable visual inputs without over-refusing valid diagrams? •
IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. XX, NO. XX, XX 2026
9
TABLE V PASS @k (%) OF V ERI G ROUND ABLATION VARIANTS ON C2VE VAL UNDER THE PAIRED N ORMAL /A NONY × O RIGINAL /M IRAGE PROTOCOL . F OR O RIGINAL ROWS , BOLD = HIGHEST ( BEST ); FOR M IRAGE ROWS , BOLD = LOWEST ( BEST ).
Variant Base (Qwen3.5-4B)
Anony-mixed SFT +ORPO