Dragon is a lightweight code reasoning and generation model built upon the base
Qwen2-0.5B-instruct model. It offers accurate and quick code snippet and long-form code generation in all major programming languages.
It's small size (0.5B parameters) allows it to run comfortably on most laptop/commercial grade GPUs.
This model also offers Q/A and subject matter expert capabilities on code related subjects.
The Dragon-1 is the pilot model for the
Dragon-1/1.5 series which incorporates high-end reasoning capabilities into the standard Qwen2 and Qwen2.5 architectures.
The 0.5B variant has been SFT trained on code reasoning traces found
here with further RL training carried out via. a GRPO algorithm. This endows the model with enhanced reasoning capabilities which allows it to serve higher quality and hallucination-free generations.
1pip install -r requirements.txt
2pip install transformers datasets accelerate safetensors
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
3
4
5device = "cuda" if torch.cuda.is_available() else "cpu"
6
7model_id = "DireDreadlord/Dragon-1-0.5B"
8model = AutoModelForCausalLM.from_pretrained(
9 model_id,
10 device_map="auto",
11 dtype="auto"
12)
13model.to(device)
14tokenizer = AutoTokenizer.from_pretrained(model_id)
15streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=False)
16
17prompt = "Can you reason about the following leetcode question: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Please provide a detailed reasoning and explanation for your answer."
18
19input_ids = tokenizer.apply_chat_template(
20 [{"role": "user", "content": prompt}],
21 add_generation_prompt=True,
22 return_tensors="pt",
23 tokenize=True,
24)["input_ids"].to(device)
25
26output = model.generate(
27 input_ids,
28 do_sample=True,
29 temperature=0.4,
30 top_k=50,
31 repetition_penalty=1.05,
32 max_new_tokens=2048,
33 streamer=streamer,
34)