Instructions to use tkeskin/llama-3.2-1b-instruct-code-translation with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tkeskin/llama-3.2-1b-instruct-code-translation with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tkeskin/llama-3.2-1b-instruct-code-translation") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tkeskin/llama-3.2-1b-instruct-code-translation") model = AutoModelForCausalLM.from_pretrained("tkeskin/llama-3.2-1b-instruct-code-translation") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tkeskin/llama-3.2-1b-instruct-code-translation with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tkeskin/llama-3.2-1b-instruct-code-translation" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tkeskin/llama-3.2-1b-instruct-code-translation", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tkeskin/llama-3.2-1b-instruct-code-translation
- SGLang
How to use tkeskin/llama-3.2-1b-instruct-code-translation 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 "tkeskin/llama-3.2-1b-instruct-code-translation" \ --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": "tkeskin/llama-3.2-1b-instruct-code-translation", "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 "tkeskin/llama-3.2-1b-instruct-code-translation" \ --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": "tkeskin/llama-3.2-1b-instruct-code-translation", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tkeskin/llama-3.2-1b-instruct-code-translation with Docker Model Runner:
docker model run hf.co/tkeskin/llama-3.2-1b-instruct-code-translation
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 (
instructconfig) — 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 (Llama-3.2-1B-Instruct) | This model | Δ | |
|---|---|---|---|
| pass@1 | 17.5% | 32.5% | +15.0 |
| compile rate | 52.8% | 72.7% | +19.8 |
pass@1 by language pair × difficulty (%):
| source | target | difficulty | base | this model |
|---|---|---|---|---|
| cpp | java | Easy | 29.0 | 55.9 |
| cpp | java | Hard | 7.6 | 24.6 |
| cpp | java | Medium | 15.9 | 39.5 |
| cpp | python | Easy | 32.0 | 37.2 |
| cpp | python | Hard | 10.7 | 17.6 |
| cpp | python | Medium | 24.4 | 33.8 |
| java | cpp | Easy | 15.0 | 61.2 |
| java | cpp | Hard | 4.2 | 27.7 |
| java | cpp | Medium | 14.4 | 44.4 |
| java | python | Easy | 31.4 | 44.8 |
| java | python | Hard | 13.0 | 22.9 |
| java | python | Medium | 19.2 | 31.8 |
| python | cpp | Easy | 23.8 | 40.1 |
| python | cpp | Hard | 1.7 | 6.7 |
| python | cpp | Medium | 15.6 | 23.3 |
| python | java | Easy | 24.1 | 30.3 |
| python | java | Hard | 3.4 | 7.6 |
| python | java | Medium | 12.4 | 19.4 |
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
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
- 26
Model tree for tkeskin/llama-3.2-1b-instruct-code-translation
Base model
meta-llama/Llama-3.2-1B-Instruct