Fine-Tuning Qwen3-27B for C-to-Rust Code Translation: A Three-Stage Curriculum of Pretraining, Debugging-Aware SFT, and Task-Specific SFT
Organizations: Northeastern University · EmbodyX Inc · Aibao LLC
Abstract
Translating C code into safe, idiomatic Rust is a longstanding software-engineering goal because it can eliminate entire classes of memory-safety vulnerabilities while preserving the functional behavior of legacy systems. Large language models (LLMs) have shown promise for this task but typically underperform when applied off-the-shelf, since general-purpose pretraining rarely emphasizes idiomatic Rust generation, cross-language semantic equivalence, or the ability to reason about and repair compiler/runtime feedback. In this report we describe a three-stage fine-tuning curriculum applied to Qwen3-27B that is designed to progressively specialize the model for the C-to-Rust (C2Rust) translation task: (1) continued pretraining on Rust-centric corpora to strengthen the model's prior over idiomatic Rust syntax and standard-library usage; (2) supervised fine-tuning (SFT) on the microsoft/Verus_Training_Data dataset to instill debugging and self-repair behavior over Rust code; and (3) task-specific SFT on paired C/Rust solutions derived from LeetCode problems to teach direct semantic translation. We evaluate the resulting model using the agentic, static-analysis-guided verification framework of SACTOR, which performs structure-aware, two-phase (unidiomatic to idiomatic) translation with foreign-function-interface (FFI)-based end-to-end (E2E) testing. We report success rate, idiomaticity (Clippy lint counts, unsafe-code fraction), and failure-mode analyses, and compare our fine-tuned model against baseline Qwen3-27B and other LLMs evaluated under the same framework.
Figures & tables
| Property | Value |
|---|---|
| Parameters (language model) | 27B ( 28B including the vision encoder) |
| Hidden dimension | 5,120 |
| Number of layers | 64 |
| Layer layout | 16 [ 3 (Gated DeltaNet FFN) 1 (Gated Attention FFN) ] |
| Gated DeltaNet heads | 48 (value), 16 (query/key) |
| Gated DeltaNet head dimension | 128 |
| Setting | Value |
|---|---|
| ZeRO stage | 3 |
| Precision | bf16.enabled = auto (BF16 training) |
| zero_allow_untested_optimizer | true |
| overlap_comm | false |
| contiguous_gradients | true |
| sub_group_size |
| Stage | Objective | Data Source | Training Type |
|---|---|---|---|
| 1 | Rust language proficiency | Rust code from various Rust datasets | Continued pretraining |
| 2 | Debugging / self-repair | microsoft/Verus_Training_Data | Instruction SFT |
| 3 | C2Rust task translation | LeetCode C/Rust paired solutions | Instruction SFT |
| Name | Hugging Face Source | Examples |
|---|---|---|
| Strandset-Rust | Fortytwo-Network/Strandset-Rust-v1 | 191,008 |
| CodeFIM-Rust-Mellum | Etherll/CodeFIM-Rust-Mellum | 56,920 |
| rust_instruction_dataset | ysr/rust_instruction_dataset | 524 |
| humaneval-rust | diversoailab/humaneval-rust | 164 |
| Magicoder-OSS-Instruct-75K-rust | ise-uiuc/Magicoder-OSS-Instruct-75K | 4,695 (Rust subset) |
| xCodeEval-rust | NTU-NLP-sg/xCodeEval | 39,510 |
| Data Type | Concatenation Pattern | Representative Source |
|---|---|---|
| FIM / code completion | prefix + middle / completion + suffix | CodeFIM-Rust-Mellum |
| Instruction + code | instruction + code | rust_instruction_dataset |
| Context + code | code_context + code | Several Strandset-Rust-v1 categories |
| Code + explanation | code_context + code + explanation / summary | Strandset-Rust-v1 (e.g., documentation-oriented categories) |
| Before/after (repair-style) | code_context + code_before + rationale / comment + code_after | Strandset-Rust-v1 (e.g., code-review categories) |
| Full source | prompt + declaration + solution + test | humaneval-rust |
| Setting | Value |
|---|---|
| LLaMA-Factory stage | pt (continued pretraining) |
| Fine-tuning type | full (full-parameter) |
| Distributed backend | DeepSpeed ZeRO Stage 3 (§ 3 ) |
| Precision | BF16 |
| max_samples | (effectively unlimited – the full corpus is used) |
| Sequence length ( cutoff_len ) | 16,384 tokens |
| Part | Subtype | Approx. Count |
|---|---|---|
| Part 1 (self-/tutorial-synthesis) | Direct-generation (program + spec + proof) | 5.7M |
| Part 1 (self-/tutorial-synthesis) | Debugging (unverified verified pair + error report) | 1.2M |
| Part 2 (agent trajectories, Sonnet 4.5) | Long direct-generation CoT | 871 |
| Part 2 (agent trajectories, Sonnet 4.5) | Single-step debugging CoT | 3,686 |
| Total | 6.9M + 4,557 |
| Setting | Value |
|---|---|
| LLaMA-Factory stage | sft |
| Fine-tuning type | full (full-parameter) |
| Initialized from | Stage 1 checkpoint |
| Distributed backend | DeepSpeed ZeRO Stage 3 (§ 3 ) |
| Precision | BF16 |
| max_samples | (effectively unlimited – the full configured dataset is used) |
| Setting | Value |
|---|---|
| LLaMA-Factory stage | sft |
| Fine-tuning type | full (full-parameter) |
| Initialized from | Stage 2 checkpoint |
| Distributed backend | DeepSpeed ZeRO Stage 3 (§ 3 ) |
| Precision | BF16 |
| max_samples | (effectively unlimited – the full configured dataset is used) |
| Configuration | Value |
| Temperature | 0.6 |
| Top-p | 0.95 |
| Top-k | 20 |
| Maximum output length | 1,536 |
| Maximum translation attempts | 6 |
| Model | Model Size | SR |
|---|---|---|
| Qwen3.5-Plus | 397B (17B active) | 77.20% |
| MiniMax-M2.5 | 230B (10B active) | 83.90% |
| GLM-5 | 744B (40B active) | 84.40% |
| GLM-5.2 | 744B (40B active) | 89.90% |
| Claude Code-4.6 | – | 90.01% |
| Qwen3.5-27B (base, no fine-tuning) | 27B (dense) | 72.30% |
| Model | SWE-bench Verified |
|---|---|
| GPT-5-mini (2025-08-07) | 72.0 |
| GPT-OSS-120B | 62.0 |
| Qwen3.5-122B-A10B | 72.0 |
| Qwen3.5-27B (base, no fine-tuning) | 72.4 |
| Ours (Qwen3.5-27B + Stages 1–3) | 70.6 |
Code Translation
Code translation converts programs between languages, frameworks, and representations while aiming to preserve behavior and sometimes improve safety or performance.
See all 41 papers