Text Generation
Transformers
Safetensors
Rust
qwen3_5
image-text-to-text
code
c
code-translation
c-to-rust
qwen3.5
fine-tuning
sactor
deepspeed
conversational
Instructions to use moxin-org/C2Rust with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use moxin-org/C2Rust with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="moxin-org/C2Rust") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("moxin-org/C2Rust") model = AutoModelForMultimodalLM.from_pretrained("moxin-org/C2Rust", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use moxin-org/C2Rust with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "moxin-org/C2Rust" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moxin-org/C2Rust", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/moxin-org/C2Rust
- SGLang
How to use moxin-org/C2Rust with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "moxin-org/C2Rust" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moxin-org/C2Rust", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "moxin-org/C2Rust" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "moxin-org/C2Rust", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use moxin-org/C2Rust with Docker Model Runner:
docker model run hf.co/moxin-org/C2Rust
File size: 7,480 Bytes
e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 2e68ff0 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee 6ceeeb1 e969dee | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | ---
license: apache-2.0
base_model:
- Qwen/Qwen3.5-27B
library_name: transformers
pipeline_tag: text-generation
tags:
- code
- c
- rust
- code-translation
- c-to-rust
- qwen3.5
- fine-tuning
- sactor
- deepspeed
---
# C2Rust
**C2Rust** is a full-parameter BF16 fine-tune of
[Qwen/Qwen3.5-27B](https://huggingface.co/Qwen/Qwen3.5-27B) for translating C programs into
behaviorally equivalent Rust. The model is trained with a three-stage curriculum and evaluated with
an execution-based SACTOR harness that compiles each candidate and compares its behavior with the
source C program.
The accompanying technical report is titled **“Fine-Tuning Qwen3.5-27B for C-to-Rust Code
Translation: A Three-Stage Curriculum of Pretraining, Debugging-Aware SFT, and Task-Specific SFT”**
(August 2026).
## Results
### C2Rust translation success rate
Success Rate (SR) is the percentage of programs that compile and pass every end-to-end test. Scores
are arithmetic means over five random seeds under the same inference configuration.
| Model | Model size | SR |
|---|---:|---:|
| Qwen3.5-Plus | 397B total / 17B active | 77.20% |
| MiniMax-M2.5 | 230B total / 10B active | 83.90% |
| GLM-5 | 744B total / 40B active | 84.40% |
| GLM-5.2 | 744B total / 40B active | 89.90% |
| Claude Code-4.6 | undisclosed | 90.01% |
| Qwen3.5-27B base | 27B dense | 72.30% |
| **C2Rust (this model)** | **27B dense** | **87.30%** |
The curriculum improves the direct Qwen3.5-27B baseline by **15.00 percentage points** while keeping
model size and serving cost fixed. C2Rust outperforms Qwen3.5-Plus, MiniMax-M2.5, and GLM-5 on this
task, while remaining below GLM-5.2 and Claude Code-4.6.
### General coding capability
| Model | SWE-bench Verified pass@1 |
|---|---:|
| GPT-5-mini (2025-08-07) | 72.0 |
| GPT-OSS-120B | 62.0 |
| Qwen3.5-122B-A10B | 72.0 |
| Qwen3.5-27B base | 72.4 |
| **C2Rust (this model)** | **70.6** |
The 1.8-point difference from the untuned base suggests a modest specialization cost, while the model
retains strong general software-engineering performance.
## Three-stage training curriculum
| Stage | Objective | Data | Training configuration |
|---|---|---|---|
| 1. Rust continued pretraining | Strengthen Rust syntax, idioms, completion, repair, and library knowledge | 1,673,289 examples from seven Rust-focused sources | Full-parameter BF16, 1 epoch, LR `1e-6` |
| 2. Debugging-aware SFT | Learn to consume structured verifier feedback and make targeted repairs | [`microsoft/Verus_Training_Data`](https://huggingface.co/datasets/microsoft/Verus_Training_Data) | Full-parameter BF16, 2 epochs, LR `2e-7` |
| 3. C2Rust task SFT | Learn direct C-to-Rust semantic translation | C2Rust-Moxin `functions/` and `programs/` pairs | Full-parameter BF16, 2 epochs, LR `2e-7` |
Stage 1 combines Strandset-Rust, CodeFIM-Rust-Mellum, rust_instruction_dataset, humaneval-rust,
the Rust subset of Magicoder-OSS-Instruct-75K, the Rust program-synthesis and repair subsets of
xCodeEval, and the Rust subset of StarCoderData.
All three stages use a 16,384-token sequence length, DeepSpeed ZeRO Stage 3, and eight NVIDIA B300
GPUs. Training is text-only. The Qwen3.5 vision encoder remains in the released checkpoint but receives
no task input and plays no role in C-to-Rust translation.
## Model details
| Field | Value |
|---|---|
| Base model | `Qwen/Qwen3.5-27B` |
| Parameters | 27B language model (~28B including the retained vision encoder) |
| Weight format | Safetensors |
| Precision | BF16 |
| Context used in training | 16,384 tokens |
| Fine-tuning type | Full-parameter |
| Primary task | C-to-Rust program translation |
| License | Apache-2.0 |
The tokenizer, vocabulary, and architecture are unchanged from the base checkpoint; no task-specific
special tokens were added.
## Evaluation protocol
The companion benchmark contains **200 C programs**: 92 receive command-line arguments and 108
read standard input. Approximately 120 are derived from IBM Project CodeNet. A translation succeeds
only when the generated Rust program compiles and reproduces every reference output on the supplied
tests within a six-attempt translation and repair budget.
| Setting | Value |
|---|---:|
| Temperature | 0.6 |
| Top-p | 0.95 |
| Top-k | 20 |
| Maximum output length | 1,536 tokens |
| Maximum translation attempts | 6 |
| Random seeds | 5 |
The released repository's default configs evaluate SACTOR's interface-preserving, unidiomatic stage.
Generated code may therefore contain raw pointers or `unsafe` Rust. Passing the benchmark measures
agreement on the supplied test suite, not formal semantic equivalence.
## Resources
- [Benchmark, evaluation harness, and setup instructions](https://github.com/moxin-org/C2Rust)
- [Base model: Qwen/Qwen3.5-27B](https://huggingface.co/Qwen/Qwen3.5-27B)
- [SACTOR translation engine](https://github.com/qsdrqs/sactor)
- [C2Rust-Moxin training datasets](https://github.com/Bobchenyx/Moxin-C2Rust-Datasets)
## Running with the benchmark
Download the checkpoint:
```bash
hf download moxin-org/C2Rust --local-dir /path/to/C2Rust-model
```
Clone and prepare the benchmark:
```bash
git clone https://github.com/moxin-org/C2Rust.git
cd C2Rust
bash fix_paths.sh
cd engine
uv sync
./update_rust_ast_parser.sh
cargo build --release
cd ..
```
Launch the checkpoint with SGLang:
```bash
export SERVE_VENV=/path/to/sglang-venv
./scripts/launch_model.sh /path/to/C2Rust-model 0,1 30878 2
```
Run a two-program smoke test before the complete evaluation:
```bash
python3 scripts/run_eval.py configs/native_prompt.toml results/_smoke \
--modes argv --limit 2 --workers 1
```
See the [benchmark README](https://github.com/moxin-org/C2Rust#setup-once-per-machine) and
[`SETUP.md`](https://github.com/moxin-org/C2Rust/blob/main/SETUP.md) for the complete environment,
five-seed evaluation, aggregation, and troubleshooting workflow.
## Intended use
This release is intended for research and experimentation on C-to-Rust translation. Treat every
generated program as a candidate: compile it, test it against the original implementation, and review
it for correctness, safety, and maintainability before use.
## Limitations
- Passing the supplied tests is not proof of semantic equivalence, memory safety, or security.
- The default evaluation permits `unsafe` Rust and prioritizes behavior preservation over idiomaticity.
- Stage 3 uses function- and program-level pairs, but excludes project-level training examples.
- The model scores 70.6 on SWE-bench Verified versus 72.4 for the base checkpoint, suggesting mild
capability narrowing after full-parameter specialization.
- The report does not yet provide an ablation isolating each curriculum stage's marginal contribution.
## Citation
The supplied manuscript has not finalized its individual author list. Until citation metadata is
released, cite the software artifact:
```bibtex
@software{moxin2026c2rust,
title = {C2Rust: Fine-Tuned Qwen3.5-27B for C-to-Rust Translation},
author = {{Moxin Organization}},
year = {2026},
url = {https://github.com/moxin-org/C2Rust}
}
```
## License and attribution
The checkpoint is released under Apache-2.0 and is derived from
[Qwen/Qwen3.5-27B](https://huggingface.co/Qwen/Qwen3.5-27B). The benchmark is Apache-2.0. Its
dataset includes material derived from IBM Project CodeNet under CDLA-Permissive-2.0; see the
[dataset provenance and terms](https://github.com/moxin-org/C2Rust/blob/main/CodeNet/README.md).
|