How to use from the
Use from the
Transformers library
# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("text-generation", model="roskosmos19/Rhea-Coder-0.5B")
messages = [
    {"role": "user", "content": "Who are you?"},
]
pipe(messages)
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("roskosmos19/Rhea-Coder-0.5B")
model = AutoModelForCausalLM.from_pretrained("roskosmos19/Rhea-Coder-0.5B", device_map="auto")
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=256)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
Quick Links

Rhea-Coder-0.5B

A small English coding assistant: a LoRA fine-tune of Qwen/Qwen2.5-Coder-0.5B-Instruct on 1,008 Python instruction examples from Magicoder-OSS-Instruct-75K.

This repo contains:

  • the merged model (bf16 safetensors) at the repo root โ€” load it like any Qwen2 model;
  • the LoRA adapter in adapter/ โ€” apply it to the base model with PEFT.

Honest note: this is a small, CPU-only training run (about 119 minutes on 2 CPU cores, one epoch over ~1k examples). It is an experiment in efficient fine-tuning, not a new state of the art. See the evaluation below โ€” it helped a little.

Evaluation (HumanEval subset, pass@1, greedy)

Same script, same 40 tasks, same prompt and decoding for both models (bf16, greedy, max 384 new tokens, batch 8, each solution executed in an isolated subprocess with a 10 s timeout and 2 GB memory limit). The fine-tuned row was measured on the merged bf16 weights published in this repo.

Model HumanEval subset (40 tasks) pass@1
Qwen2.5-Coder-0.5B-Instruct (base) 18/40 = 45.0 %
Rhea-Coder-0.5B (this model) 21/40 = 52.5 %

The fine-tune improved this HumanEval subset by 3 task(s). With only 40 tasks this is a small, noisy signal (one task = 2.5 points), not a definitive result. Tasks newly solved: HumanEval/100, HumanEval/113, HumanEval/136, HumanEval/142, HumanEval/64, HumanEval/72. Tasks newly failed: HumanEval/150, HumanEval/79, HumanEval/80.

Task subset: random.seed(0); sorted(random.sample(range(164), 40)) over openai/openai_humaneval โ†’ indices [3, 10, 15, 18, 23, 24, 25, 35, 37, 52, 55, 64, 66, 72, 77, 79, 80, 84, 90, 91, 98, 100, 102, 103, 105, 107, 111, 113, 120, 122, 124, 129, 130, 136, 137, 142, 149, 150, 155, 160]. These numbers are on a 40-task subset with our own prompt and are not comparable to the official full-HumanEval numbers reported by Qwen.

Training details

Setting Value
Base model Qwen/Qwen2.5-Coder-0.5B-Instruct
Method LoRA (PEFT), r = 16, alpha = 32, dropout = 0.05
Target modules q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj (all linear projections)
Trainable parameters 8.8 M (1.75 % of 503 M)
Base weights bf16 (frozen); LoRA weights fp32
Data 1,008 Python examples from Magicoder-OSS-Instruct-75K, chat format, โ‰ค 512 tokens each (417,479 tokens total)
Loss assistant tokens only (prompt masked)
Epochs 1
Batch micro-batch 1 (no padding) ร— gradient accumulation 16 = effective 16; 63 optimizer steps
Optimizer AdamW, lr 2e-4, cosine schedule, 5 % warmup, grad-clip 1.0
Attention eager (PyTorch's CPU flash-SDPA kernel was ~10ร— slower in bf16)
Hardware 2 ARM CPU cores (Neoverse-V2), ~7 GB RAM, no GPU
Gradient checkpointing on
Training time 119 min of training compute (final run; an earlier attempt without checkpointing was stopped at step 38 and restarted from scratch, and the final run was interrupted by a machine restart at step 38 and resumed from its step-30 LoRA + optimizer checkpoint; recomputed steps not counted)
Training loss 0.551 (step 1) โ†’ 0.399 (mean of last 5 steps)

Data selection / decontamination: Python-only rows from Magicoder-OSS-Instruct-75K, shuffled (seed 0), filtered to โ‰ค 512 tokens with the Qwen chat template. Rows sharing any 13-word n-gram with a HumanEval prompt or canonical solution, or defining a function with a HumanEval entry-point name, were removed (all 164 tasks, not just the 40 evaluated).

Why 0.5B and not 1.5B? Qwen2.5-Coder-1.5B-Instruct fit in RAM, but measured ~11 s per 256-token step on this CPU, i.e. ~5 hours for 1,000 examples. The 0.5B model trains at ~55โ€“80 tokens/s (with / without gradient checkpointing), so ~1k examples fit in about 1.5โ€“2 hours.

The dataset roskosmos19/Rhea-Coding was checked but not mixed in: it uses a custom 3-pass format with non-standard pseudo-tokens and zero-width characters that would change the output format away from plain code answers.

Usage

from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "roskosmos19/Rhea-Coder-0.5B"
tok = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype="auto")

messages = [{"role": "user", "content": "Write a Python function that returns the n-th Fibonacci number iteratively."}]
inputs = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt", return_dict=True)
out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
print(tok.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))

Using only the adapter:

from transformers import AutoModelForCausalLM
from peft import PeftModel

base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-0.5B-Instruct", torch_dtype="auto")
model = PeftModel.from_pretrained(base, "roskosmos19/Rhea-Coder-0.5B", subfolder="adapter")

Limitations

  • 0.5B parameters: fine for short functions and explanations, weak on long or multi-file tasks; it can produce wrong code confidently. Always run and test generated code.
  • Trained on English Python instructions; other languages and natural languages were not targeted.
  • Evaluated only on a 40-task HumanEval subset.

License

Apache-2.0, same as the base model Qwen2.5-Coder-0.5B-Instruct. Training data: Magicoder-OSS-Instruct-75K (MIT).

Downloads last month
61
Safetensors
Model size
0.5B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for roskosmos19/Rhea-Coder-0.5B

Finetuned
(125)
this model
Adapters
1 model

Dataset used to train roskosmos19/Rhea-Coder-0.5B