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
Update model card from C2Rust technical report
Browse filesAdd the three-stage training curriculum, verified C2Rust and SWE-bench results, evaluation protocol, limitations, and citation guidance.
README.md
CHANGED
|
@@ -3,7 +3,7 @@ license: apache-2.0
|
|
| 3 |
base_model:
|
| 4 |
- Qwen/Qwen3.5-27B
|
| 5 |
library_name: transformers
|
| 6 |
-
pipeline_tag:
|
| 7 |
tags:
|
| 8 |
- code
|
| 9 |
- c
|
|
@@ -11,42 +11,117 @@ tags:
|
|
| 11 |
- code-translation
|
| 12 |
- c-to-rust
|
| 13 |
- qwen3.5
|
|
|
|
|
|
|
|
|
|
| 14 |
---
|
| 15 |
|
| 16 |
# C2Rust
|
| 17 |
|
| 18 |
-
C2Rust is a
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
## Model details
|
| 29 |
|
| 30 |
| Field | Value |
|
| 31 |
|---|---|
|
| 32 |
| Base model | `Qwen/Qwen3.5-27B` |
|
| 33 |
-
|
|
| 34 |
-
| Parameters | 27B |
|
| 35 |
| Weight format | Safetensors |
|
| 36 |
| Precision | BF16 |
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
-
## Running
|
| 50 |
|
| 51 |
Download the checkpoint:
|
| 52 |
|
|
@@ -68,15 +143,14 @@ cargo build --release
|
|
| 68 |
cd ..
|
| 69 |
```
|
| 70 |
|
| 71 |
-
|
| 72 |
-
sets the serving options expected by the benchmark:
|
| 73 |
|
| 74 |
```bash
|
| 75 |
export SERVE_VENV=/path/to/sglang-venv
|
| 76 |
./scripts/launch_model.sh /path/to/C2Rust-model 0,1 30878 2
|
| 77 |
```
|
| 78 |
|
| 79 |
-
|
| 80 |
|
| 81 |
```bash
|
| 82 |
python3 scripts/run_eval.py configs/native_prompt.toml results/_smoke \
|
|
@@ -84,33 +158,41 @@ python3 scripts/run_eval.py configs/native_prompt.toml results/_smoke \
|
|
| 84 |
```
|
| 85 |
|
| 86 |
See the [benchmark README](https://github.com/moxin-org/C2Rust#setup-once-per-machine) and
|
| 87 |
-
[`SETUP.md`](https://github.com/moxin-org/C2Rust/blob/main/SETUP.md) for
|
| 88 |
-
|
| 89 |
|
| 90 |
-
##
|
| 91 |
-
|
| 92 |
-
The companion CodeNet benchmark contains 200 C programs: 92 use command-line arguments and 108 use
|
| 93 |
-
standard input. A problem passes only when the generated Rust program compiles and matches the
|
| 94 |
-
reference C program on every test case. Decoding is fixed at temperature 0.6, top-p 0.95, and top-k
|
| 95 |
-
20. Because individual runs are noisy, the repository reports five-seed means with standard
|
| 96 |
-
deviation and a bootstrap confidence interval.
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
|
|
|
| 100 |
|
| 101 |
## Limitations
|
| 102 |
|
| 103 |
-
-
|
| 104 |
-
|
| 105 |
-
-
|
| 106 |
-
- The
|
| 107 |
-
|
| 108 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
-
##
|
| 111 |
|
| 112 |
-
The checkpoint is released under Apache-2.0 and is
|
| 113 |
-
[Qwen/Qwen3.5-27B](https://huggingface.co/Qwen/Qwen3.5-27B). The benchmark
|
| 114 |
-
|
| 115 |
-
CDLA-Permissive-2.0; see the benchmark's
|
| 116 |
[dataset provenance and terms](https://github.com/moxin-org/C2Rust/blob/main/CodeNet/README.md).
|
|
|
|
| 3 |
base_model:
|
| 4 |
- Qwen/Qwen3.5-27B
|
| 5 |
library_name: transformers
|
| 6 |
+
pipeline_tag: text-generation
|
| 7 |
tags:
|
| 8 |
- code
|
| 9 |
- c
|
|
|
|
| 11 |
- code-translation
|
| 12 |
- c-to-rust
|
| 13 |
- qwen3.5
|
| 14 |
+
- fine-tuning
|
| 15 |
+
- sactor
|
| 16 |
+
- deepspeed
|
| 17 |
---
|
| 18 |
|
| 19 |
# C2Rust
|
| 20 |
|
| 21 |
+
**C2Rust** is a full-parameter BF16 fine-tune of
|
| 22 |
+
[Qwen/Qwen3.5-27B](https://huggingface.co/Qwen/Qwen3.5-27B) for translating C programs into
|
| 23 |
+
behaviorally equivalent Rust. The model is trained with a three-stage curriculum and evaluated with
|
| 24 |
+
an execution-based SACTOR harness that compiles each candidate and compares its behavior with the
|
| 25 |
+
source C program.
|
| 26 |
|
| 27 |
+
The accompanying technical report is titled **“Fine-Tuning Qwen3.5-27B for C-to-Rust Code
|
| 28 |
+
Translation: A Three-Stage Curriculum of Pretraining, Debugging-Aware SFT, and Task-Specific SFT”**
|
| 29 |
+
(August 2026).
|
| 30 |
|
| 31 |
+
## Results
|
| 32 |
+
|
| 33 |
+
### C2Rust translation success rate
|
| 34 |
+
|
| 35 |
+
Success Rate (SR) is the percentage of programs that compile and pass every end-to-end test. Scores
|
| 36 |
+
are arithmetic means over five random seeds under the same inference configuration.
|
| 37 |
+
|
| 38 |
+
| Model | Model size | SR |
|
| 39 |
+
|---|---:|---:|
|
| 40 |
+
| Qwen3.5-Plus | 397B total / 17B active | 77.20% |
|
| 41 |
+
| MiniMax-M2.5 | 230B total / 10B active | 83.90% |
|
| 42 |
+
| GLM-5 | 744B total / 40B active | 84.40% |
|
| 43 |
+
| GLM-5.2 | 744B total / 40B active | 89.90% |
|
| 44 |
+
| Claude Code-4.6 | undisclosed | 90.01% |
|
| 45 |
+
| Qwen3.5-27B base | 27B dense | 72.30% |
|
| 46 |
+
| **C2Rust (this model)** | **27B dense** | **87.30%** |
|
| 47 |
+
|
| 48 |
+
The curriculum improves the direct Qwen3.5-27B baseline by **15.00 percentage points** while keeping
|
| 49 |
+
model size and serving cost fixed. C2Rust outperforms Qwen3.5-Plus, MiniMax-M2.5, and GLM-5 on this
|
| 50 |
+
task, while remaining below GLM-5.2 and Claude Code-4.6.
|
| 51 |
+
|
| 52 |
+
### General coding capability
|
| 53 |
+
|
| 54 |
+
| Model | SWE-bench Verified pass@1 |
|
| 55 |
+
|---|---:|
|
| 56 |
+
| GPT-5-mini (2025-08-07) | 72.0 |
|
| 57 |
+
| GPT-OSS-120B | 62.0 |
|
| 58 |
+
| Qwen3.5-122B-A10B | 72.0 |
|
| 59 |
+
| Qwen3.5-27B base | 72.4 |
|
| 60 |
+
| **C2Rust (this model)** | **70.6** |
|
| 61 |
+
|
| 62 |
+
The 1.8-point difference from the untuned base suggests a modest specialization cost, while the model
|
| 63 |
+
retains strong general software-engineering performance.
|
| 64 |
+
|
| 65 |
+
## Three-stage training curriculum
|
| 66 |
+
|
| 67 |
+
| Stage | Objective | Data | Training configuration |
|
| 68 |
+
|---|---|---|---|
|
| 69 |
+
| 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` |
|
| 70 |
+
| 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` |
|
| 71 |
+
| 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` |
|
| 72 |
+
|
| 73 |
+
Stage 1 combines Strandset-Rust, CodeFIM-Rust-Mellum, rust_instruction_dataset, humaneval-rust,
|
| 74 |
+
the Rust subset of Magicoder-OSS-Instruct-75K, the Rust program-synthesis and repair subsets of
|
| 75 |
+
xCodeEval, and the Rust subset of StarCoderData.
|
| 76 |
+
|
| 77 |
+
All three stages use a 16,384-token sequence length, DeepSpeed ZeRO Stage 3, and eight NVIDIA B300
|
| 78 |
+
GPUs. Training is text-only. The Qwen3.5 vision encoder remains in the released checkpoint but receives
|
| 79 |
+
no task input and plays no role in C-to-Rust translation.
|
| 80 |
|
| 81 |
## Model details
|
| 82 |
|
| 83 |
| Field | Value |
|
| 84 |
|---|---|
|
| 85 |
| Base model | `Qwen/Qwen3.5-27B` |
|
| 86 |
+
| Parameters | 27B language model (~28B including the retained vision encoder) |
|
|
|
|
| 87 |
| Weight format | Safetensors |
|
| 88 |
| Precision | BF16 |
|
| 89 |
+
| Context used in training | 16,384 tokens |
|
| 90 |
+
| Fine-tuning type | Full-parameter |
|
| 91 |
+
| Primary task | C-to-Rust program translation |
|
| 92 |
+
| License | Apache-2.0 |
|
| 93 |
|
| 94 |
+
The tokenizer, vocabulary, and architecture are unchanged from the base checkpoint; no task-specific
|
| 95 |
+
special tokens were added.
|
| 96 |
+
|
| 97 |
+
## Evaluation protocol
|
| 98 |
+
|
| 99 |
+
The companion benchmark contains **200 C programs**: 92 receive command-line arguments and 108
|
| 100 |
+
read standard input. Approximately 120 are derived from IBM Project CodeNet. A translation succeeds
|
| 101 |
+
only when the generated Rust program compiles and reproduces every reference output on the supplied
|
| 102 |
+
tests within a six-attempt translation and repair budget.
|
| 103 |
|
| 104 |
+
| Setting | Value |
|
| 105 |
+
|---|---:|
|
| 106 |
+
| Temperature | 0.6 |
|
| 107 |
+
| Top-p | 0.95 |
|
| 108 |
+
| Top-k | 20 |
|
| 109 |
+
| Maximum output length | 1,536 tokens |
|
| 110 |
+
| Maximum translation attempts | 6 |
|
| 111 |
+
| Random seeds | 5 |
|
| 112 |
+
|
| 113 |
+
The released repository's default configs evaluate SACTOR's interface-preserving, unidiomatic stage.
|
| 114 |
+
Generated code may therefore contain raw pointers or `unsafe` Rust. Passing the benchmark measures
|
| 115 |
+
agreement on the supplied test suite, not formal semantic equivalence.
|
| 116 |
+
|
| 117 |
+
## Resources
|
| 118 |
|
| 119 |
+
- [Benchmark, evaluation harness, and setup instructions](https://github.com/moxin-org/C2Rust)
|
| 120 |
+
- [Base model: Qwen/Qwen3.5-27B](https://huggingface.co/Qwen/Qwen3.5-27B)
|
| 121 |
+
- [SACTOR translation engine](https://github.com/qsdrqs/sactor)
|
| 122 |
+
- [C2Rust-Moxin training datasets](https://github.com/Bobchenyx/Moxin-C2Rust-Datasets)
|
| 123 |
|
| 124 |
+
## Running with the benchmark
|
| 125 |
|
| 126 |
Download the checkpoint:
|
| 127 |
|
|
|
|
| 143 |
cd ..
|
| 144 |
```
|
| 145 |
|
| 146 |
+
Launch the checkpoint with SGLang:
|
|
|
|
| 147 |
|
| 148 |
```bash
|
| 149 |
export SERVE_VENV=/path/to/sglang-venv
|
| 150 |
./scripts/launch_model.sh /path/to/C2Rust-model 0,1 30878 2
|
| 151 |
```
|
| 152 |
|
| 153 |
+
Run a two-program smoke test before the complete evaluation:
|
| 154 |
|
| 155 |
```bash
|
| 156 |
python3 scripts/run_eval.py configs/native_prompt.toml results/_smoke \
|
|
|
|
| 158 |
```
|
| 159 |
|
| 160 |
See the [benchmark README](https://github.com/moxin-org/C2Rust#setup-once-per-machine) and
|
| 161 |
+
[`SETUP.md`](https://github.com/moxin-org/C2Rust/blob/main/SETUP.md) for the complete environment,
|
| 162 |
+
five-seed evaluation, aggregation, and troubleshooting workflow.
|
| 163 |
|
| 164 |
+
## Intended use
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
+
This release is intended for research and experimentation on C-to-Rust translation. Treat every
|
| 167 |
+
generated program as a candidate: compile it, test it against the original implementation, and review
|
| 168 |
+
it for correctness, safety, and maintainability before use.
|
| 169 |
|
| 170 |
## Limitations
|
| 171 |
|
| 172 |
+
- Passing the supplied tests is not proof of semantic equivalence, memory safety, or security.
|
| 173 |
+
- The default evaluation permits `unsafe` Rust and prioritizes behavior preservation over idiomaticity.
|
| 174 |
+
- Stage 3 uses function- and program-level pairs, but excludes project-level training examples.
|
| 175 |
+
- The model scores 70.6 on SWE-bench Verified versus 72.4 for the base checkpoint, suggesting mild
|
| 176 |
+
capability narrowing after full-parameter specialization.
|
| 177 |
+
- The report does not yet provide an ablation isolating each curriculum stage's marginal contribution.
|
| 178 |
+
|
| 179 |
+
## Citation
|
| 180 |
+
|
| 181 |
+
The supplied manuscript has not finalized its individual author list. Until citation metadata is
|
| 182 |
+
released, cite the software artifact:
|
| 183 |
+
|
| 184 |
+
```bibtex
|
| 185 |
+
@software{moxin2026c2rust,
|
| 186 |
+
title = {C2Rust: Fine-Tuned Qwen3.5-27B for C-to-Rust Translation},
|
| 187 |
+
author = {{Moxin Organization}},
|
| 188 |
+
year = {2026},
|
| 189 |
+
url = {https://github.com/moxin-org/C2Rust}
|
| 190 |
+
}
|
| 191 |
+
```
|
| 192 |
|
| 193 |
+
## License and attribution
|
| 194 |
|
| 195 |
+
The checkpoint is released under Apache-2.0 and is derived from
|
| 196 |
+
[Qwen/Qwen3.5-27B](https://huggingface.co/Qwen/Qwen3.5-27B). The benchmark is Apache-2.0. Its
|
| 197 |
+
dataset includes material derived from IBM Project CodeNet under CDLA-Permissive-2.0; see the
|
|
|
|
| 198 |
[dataset provenance and terms](https://github.com/moxin-org/C2Rust/blob/main/CodeNet/README.md).
|