llama-3.2-1b-instruct-code-translation

A fine-tuned version of meta-llama/Llama-3.2-1B-Instruct for translating code between C++, Java, and Python.

Training

  • Base model: meta-llama/Llama-3.2-1B-Instruct
  • 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), flash_attn: sdpa
  • LoRA target: all linear layers (lora_target: all)
  • Precision: bf16

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

from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "tkeskin/llama-3.2-1b-instruct-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))
Downloads last month
29
Safetensors
Model size
1B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for tkeskin/llama-3.2-1b-instruct-code-translation

Adapter
(646)
this model

Dataset used to train tkeskin/llama-3.2-1b-instruct-code-translation