CoolFace
Modelpublic

tkeskin/mistral-7b-v0.3-code-translation

sourceHugging Faceapache-2.0updated 3mo agoView on Hugging Face
0likes8downloads
Model Card

mistral-7b-v0.3-code-translation

A fine-tuned version of mistralai/Mistral-7B-Instruct-v0.3 for translating code between C++, Java, and Python.

Training

  • Base model: mistralai/Mistral-7B-Instruct-v0.3
  • Method: LoRA (Low-Rank Adaptation) via LLaMA-Factory
  • Dataset: tkeskin/leetcode-solutions (instruct config) — directed C++/Java/Python translation pairs derived from LeetCode solutions
  • Hardware: AMD MI210 (ROCm) / NVIDIA CUDA, flash_attn: sdpa
  • LoRA target: all linear layers (lora_target: all)
  • Precision: bf16

Evaluation

Evaluated with an execution-based translation benchmark: each held-out evaluation-config payload from tkeskin/leetcode-solutions is a directed source→target translation whose output is compiled and run against the problem's input/output pairs. The eval split is held out from training (no leakage). Metric is pass@1 (all test cases pass), n-weighted over 3,336 payloads.

Base (Mistral-7B-Instruct-v0.3)This modelΔ
pass@111.8%59.6%+47.8
compile rate45.0%84.7%+39.6

This is the largest gain in the series — the base model barely produces compilable C++/Java, and fine-tuning lifts it to near the top. pass@1 by language pair × difficulty (%):

sourcetargetdifficultybasethis model
cppjavaEasy9.781.4
cppjavaHard3.447.5
cppjavaMedium8.172.9
cpppythonEasy29.761.6
cpppythonHard16.045.8
cpppythonMedium27.364.3
javacppEasy2.779.6
javacppHard2.551.3
javacppMedium4.170.0
javapythonEasy4.164.5
javapythonHard6.145.8
javapythonMedium8.462.3
pythoncppEasy19.764.6
pythoncppHard10.126.9
pythoncppMedium17.851.9
pythonjavaEasy17.264.8
pythonjavaHard2.528.8
pythonjavaMedium8.553.1

Full methodology is in the llm-fine-tune repo (Stage 5).

Intended use

Given source code in one of C++, Java, or Python, the model generates a translation into the target language, following the same logic and structure.

Usage

python
from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "tkeskin/mistral-7b-v0.3-code-translation"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)

messages = [
    {
        "role": "user",
        "content": "Translate the following C++ code to Python:\n\nint add(int a, int b) { return a + b; }"
    }
]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
outputs = model.generate(inputs, max_new_tokens=256)
print(tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True))