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
Add C2Rust model card
Browse filesDocument the model, companion benchmark, setup, intended use, limitations, and licensing.
README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model:
|
| 4 |
+
- Qwen/Qwen3.5-27B
|
| 5 |
+
library_name: transformers
|
| 6 |
+
pipeline_tag: image-text-to-text
|
| 7 |
+
tags:
|
| 8 |
+
- code
|
| 9 |
+
- c
|
| 10 |
+
- rust
|
| 11 |
+
- code-translation
|
| 12 |
+
- c-to-rust
|
| 13 |
+
- qwen3.5
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# C2Rust
|
| 17 |
+
|
| 18 |
+
C2Rust is a 27B-parameter BF16 Qwen3.5 checkpoint for translating C programs into behaviorally
|
| 19 |
+
equivalent Rust. It is released alongside an execution-based benchmark that compiles each generated
|
| 20 |
+
translation and checks its output against the reference C program.
|
| 21 |
+
|
| 22 |
+
## Resources
|
| 23 |
+
|
| 24 |
+
- [Benchmark, evaluation harness, and setup instructions](https://github.com/moxin-org/C2Rust)
|
| 25 |
+
- [Base model: Qwen/Qwen3.5-27B](https://huggingface.co/Qwen/Qwen3.5-27B)
|
| 26 |
+
- [SACTOR translation engine](https://github.com/qsdrqs/sactor)
|
| 27 |
+
|
| 28 |
+
## Model details
|
| 29 |
+
|
| 30 |
+
| Field | Value |
|
| 31 |
+
|---|---|
|
| 32 |
+
| Base model | `Qwen/Qwen3.5-27B` |
|
| 33 |
+
| Architecture | Qwen3.5 causal language model with vision encoder |
|
| 34 |
+
| Parameters | 27B |
|
| 35 |
+
| Weight format | Safetensors |
|
| 36 |
+
| Precision | BF16 |
|
| 37 |
+
| Primary task | C→Rust program translation |
|
| 38 |
+
|
| 39 |
+
## Intended use
|
| 40 |
+
|
| 41 |
+
The model is intended for research and experimentation on C→Rust translation. Its output should be
|
| 42 |
+
treated as a candidate translation: compile it, test it against the original program, and review it
|
| 43 |
+
for correctness, safety, and maintainability before use.
|
| 44 |
+
|
| 45 |
+
The companion benchmark evaluates a single translation stage that preserves the C interface and may
|
| 46 |
+
produce `unsafe` Rust. It does not establish that generated code is memory-safe, idiomatic, secure,
|
| 47 |
+
or suitable for production.
|
| 48 |
+
|
| 49 |
+
## Running the model with the benchmark
|
| 50 |
+
|
| 51 |
+
Download the checkpoint:
|
| 52 |
+
|
| 53 |
+
```bash
|
| 54 |
+
hf download moxin-org/C2Rust --local-dir /path/to/C2Rust-model
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Clone and prepare the benchmark:
|
| 58 |
+
|
| 59 |
+
```bash
|
| 60 |
+
git clone https://github.com/moxin-org/C2Rust.git
|
| 61 |
+
cd C2Rust
|
| 62 |
+
bash fix_paths.sh
|
| 63 |
+
|
| 64 |
+
cd engine
|
| 65 |
+
uv sync
|
| 66 |
+
./update_rust_ast_parser.sh
|
| 67 |
+
cargo build --release
|
| 68 |
+
cd ..
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
Create an SGLang environment, point `SERVE_VENV` at it, and launch the checkpoint. The helper script
|
| 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 |
+
In another shell, run a two-problem smoke test before a full evaluation:
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
+
python3 scripts/run_eval.py configs/native_prompt.toml results/_smoke \
|
| 83 |
+
--modes argv --limit 2 --workers 1
|
| 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 system dependencies,
|
| 88 |
+
multi-seed evaluation, aggregation, and troubleshooting.
|
| 89 |
+
|
| 90 |
+
## Evaluation protocol
|
| 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 |
+
No reference model score is claimed in the benchmark repository. Use its shipped configuration and
|
| 99 |
+
five-seed aggregation script for comparable measurements.
|
| 100 |
+
|
| 101 |
+
## Limitations
|
| 102 |
+
|
| 103 |
+
- Generated translations may fail to compile or may differ from the source program on untested
|
| 104 |
+
inputs.
|
| 105 |
+
- Passing the supplied tests is not a proof of semantic equivalence, memory safety, or security.
|
| 106 |
+
- The benchmark's primary flow permits `unsafe` Rust and prioritizes behavioral preservation over
|
| 107 |
+
idiomatic Rust.
|
| 108 |
+
- Training-data and training-procedure details are not included in the current release.
|
| 109 |
+
|
| 110 |
+
## Licenses and attribution
|
| 111 |
+
|
| 112 |
+
The checkpoint is released under Apache-2.0 and is based on
|
| 113 |
+
[Qwen/Qwen3.5-27B](https://huggingface.co/Qwen/Qwen3.5-27B). The benchmark repository is
|
| 114 |
+
Apache-2.0. Its dataset includes material derived from IBM Project CodeNet under
|
| 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).
|