---
base_model: Qwen/Qwen2.5-Coder-1.5B-Instruct
base_model_relation: finetune
library_name: peft
language:
- en
tags:
- code
- codeqwen
- chat
- qwen
- qwen-coder
license: gpl-3.0
datasets:
- nvidia/OpenCodeReasoning
pipeline_tag: text-generation
license_link: https://huggingface.co/bunyaminergen/Qwen2.5-Coder-1.5B-Instruct-Reasoning/blob/main/LICENSE
---
# Qwen2.5-Coder-1.5B-Instruct-Reasoning
The `Qwen2.5-Coder-1.5B-Instruct-Reasoning` model has been supervised fine-tuned (SFT) on the `nvidia/OpenCodeReasoning`
dataset to enhance its reasoning capabilities.
---
### TableofContents
- [Usage](#usage)
- [Comparison](#comparison)
- [Dataset](#dataset)
- [Training](#training)
- [License](#licence)
- [Links](#links)
- [Team](#team)
- [Contact](#contact)
- [Reference](#reference)
- [Citation](#citation)
---
### Usage
#### Hugging Face
```python
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base_model_name = "Qwen/Qwen2.5-Coder-1.5B-Instruct"
adapter_repo = "bunyaminergen/Qwen2.5-Coder-1.5B-Instruct-Reasoning"
tokenizer = AutoTokenizer.from_pretrained(adapter_repo, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
base_model_name,
device_map="auto",
torch_dtype="auto",
)
model.resize_token_embeddings(len(tokenizer))
model = PeftModel.from_pretrained(model, adapter_repo)
model.eval()
messages = [
{"role": "system", "content": "You are a helpful coding assistant."},
{"role": "user", "content": "Please provide a Python script that checks whether a number is prime."}
]
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=2048
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```
---
### Comparison
- Please pay attention to the ` ` special tokens in the [Reasoning Model](#reasoning-model). As you can
see, the `Reasoning Model` can now _“think”_.
#### Base Model
`System:` You are a helpful coding assistant.
`User:` Please provide a Python script that checks whether a number is prime.
`Assistant:`
```python
def check_prime(num):
# Check if the number is less than 2
if num < 2:
return False
# Check for factors from 2 to the square root of the number
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
# If no factors were found, the number is prime
return True
# Example usage
number = 7
if check_prime(number):
print(f"{number} is a prime number.")
else:
print(f"{number} is not a prime number.")
```
In this Python script, the function `check_prime` takes an integer as input and returns `True` if the number is prime,
otherwise it returns `False`. The function first checks if the number is less than 2, which means it cannot be prime.
Then, it iterates from 2 up to the square root of the number (inclusive). If any factor of the number is found within
this range, the function immediately returns `False`, indicating that the number is not prime. If no factors are found
after checking all possible divisors, the function concludes that the number is prime and returns `True`.
The example usage demonstrates how to call the `check_prime` function with the number 7. The output will indicate
whether 7 is a prime number or not.
#### Reasoning Model
`System:` You are a helpful coding assistant.
`User:` Please provide a Python script that checks whether a number is prime.
`Assistant:`
``
Okay, I need to write a Python program that checks if a given number is prime. Hmm, what's a prime number? Oh right, a
prime number has exactly two distinct positive divisors: 1 and itself. So for a number to be prime, it must not have any
divisors other than those two.
First, let's think about the steps involved. The first thing is to determine if there are any divisors other than 1 and
the number itself. How do I check that?
Well, for a number n, starting from 2 up to sqrt(n), check if any of them divide n. If any do, then it's not prime. But
wait, maybe even before checking up to the square root, some numbers might have factors beyond that. For example, take
9. The square root is 3. So checking 2,3,4 would catch 9's factors. Wait, but 3 divides 9, so the loop from 2 to sqrt(
n) (which is 3 in this case) will check 2 and 3. So yes, checking up to the square root is sufficient because any
composite number has at least one factor less than or equal to its square root.
So the plan is:
1. Read an integer from input.
2. Check if the number is less than 2. If so, it's not prime.
3. Otherwise, check from 2 up to the square root of the number. For each i, if the number mod i is zero, return False.
4. If none of the numbers in this range divide the number, return True.
Wait, but what about 0 and 1? Well, according to the problem statement, the input could be 0 or 1, which are not primes.
So we should handle those cases separately.
Let me outline the code structure.
Read the input number as an integer. Let's call it num.
Handle edge cases first:
- If num < 2: print "No" (since primes are >=2)
Else:
Compute sqrt_num = int(math.sqrt(num))
Then loop from 2 to sqrt_num inclusive. For each i, check if num % i ==0. If any such i exists, return False. Else,
after checking all, return True.
But how to compute the square root accurately in Python? Using math.isqrt for integers, which returns the floor of the
square root. That's better than using ** operator since it avoids floating point inaccuracies.
Wait, but what if the number is a perfect square? Like 9. Then math.isqrt(9) is 3. So in that case, the loop would check
up to 3. But when i reaches 3, 9%3 is 0, so it would return False, which is correct.
So the code would look something like this:
import math
n = int(input())
if n < 2:
print("No")
else:
sqrt_n = math.isqrt(n)
is_prime = True
for i in range(2, sqrt_n +1):
if n % i == 0:
is_prime = False
break
print("Yes" if is_prime else "No")
Wait, but wait, what about numbers like 25. The square root is 5. So the loop runs from 2 to 5. When i=5, 25%5 is 0, so
returns false. Correct.
This logic seems solid. Let me test some examples.
Test case 1: input 7. The loop runs up to 2. 2 to 2. Check 2. 7%2 is 1, so returns true. Output Yes.
Test case 2: input 6. sqrt(6) is ~2.449. So sqrt_n is 2. Loop from 2 to 2. Check 2. 6%2 is 0. So returns false. Output
No.
Another test case: 8. sqrt(8) is ~2.828. So sqrt_n is 2. Check 2. 8%2 is 0. So output No.
What about a prime number like 13. sqrt(13) is ~3.605. So loop up to 3. Check 2 and 3. 13%2 is 1, 13%3 is 1. So returns
true. Correct.
Edge case: 1. Output No.
Another edge case: 2. Output Yes.
What about a very large number, say 999983 (a prime). The code should check up to sqrt(999983) which is around 999.9. So
the loop runs 2 to 999. It will check all possible factors. Since it's a prime, none will divide it. So returns Yes.
So the code seems to handle all cases correctly.
I think that's the solution. Now, writing the code accordingly.
``
```python
import math
n = int(input())
if n < 2:
print("No")
else:
sqrt_n = math.isqrt(n)
is_prime = True
for i in range(2, sqrt_n + 1):
if n % i == 0:
is_prime = False
break
print("Yes" if is_prime else "No")
```
---
### Dataset
- [nvidia/OpenCodeReasoning](https://huggingface.co/datasets/nvidia/OpenCodeReasoning)
---
### Training
#### Base
| Parameter | Value |
|-----------------------------|------------------------------------|
| Base Model | `Qwen/Qwen2.5-Coder-1.5B-Instruct` |
| Fine-tuning Method | QLoRA |
| Task Type | `CAUSAL_LM` |
| Number of Epochs | `3` |
| Batch Size | `1` |
| Gradient Accumulation Steps | `1` |
| Effective Batch Size | `1` |
| Learning Rate | `2e-4` |
| LR Scheduler Type | `cosine` |
| Warmup Ratio | `0.05` |
| Precision | `FP16 Mixed Precision` |
| Gradient Checkpointing | `True` |
| Completion-Only Loss | `True` |
| Packing | `False` |
| Max Sequence Length | `8192 tokens` |
| Logging Steps | every `10000` steps |
| Save Checkpoint Steps | every `10000` steps |
| Output Directory | `.model` |
#### PEFT/LoRA
| Parameter | Value |
|-----------------|-----------------------------------------------------------------------------|
| LoRA Rank (`r`) | `16` |
| LoRA Alpha | `32` |
| LoRA Dropout | `0.05` |
| LoRA Bias | `none` |
| Task Type | `CAUSAL_LM` |
| Target Modules | `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj` |
| Modules to Save | `embed_tokens`, `lm_head` |
#### Model
| Parameter | Value |
|---------------------------|------------------------------------|
| Name | `Qwen/Qwen2.5-Coder-1.5B-Instruct` |
| Attention Implementation | `flash_attention_2` |
| load_in_4bit | `true` |
| bnb_4bit_quant_type | `nf4` |
| bnb_4bit_use_double_quant | `true` |
#### Dataset
| Parameter | Value |
|---------------------|----------------------------|
| Dataset Name | `nvidia/OpenCodeReasoning` |
| Split | `split_0` |
| Number of Rows | `8000` |
| Max Token Length | `8192` |
| Shuffle | `True` |
| Number of Processes | `4` |
#### Tokenizer
| Parameter | Value |
|--------------------------------|-----------------------------|
| Truncation | Enabled (`max_length=8192`) |
| Masked Language Modeling (MLM) | `False` |
#### Speeds, Sizes, Times
| Parameter | Value |
|----------------------|------------------------------------------------------------|
| Total Training Time | ~3.5 hours |
| Checkpoint Frequency | every `10000` steps |
| Checkpoint Steps | `checkpoint-10000`, `checkpoint-20000`, `checkpoint-24000` |
#### Compute Infrastructure
| Parameter | Value |
|--------------|----------------------------------|
| GPU | 1 × NVIDIA H100 SXM (80 GB VRAM) |
| RAM | 125 GB |
| CPU | 16 vCPU |
| OS | Ubuntu 22.04 |
| Frameworks | PyTorch 2.4.0 |
| CUDA Version | 12.4.1 |
---
### Licence
- [LICENSE](LICENSE)
---
### Links
- [Github](https://github.com/bunyaminergen/)
- [Website](https://bunyaminergen.com)
- [Linkedin](https://www.linkedin.com/in/bunyaminergen)
---
### Team
- [Bunyamin Ergen](https://www.linkedin.com/in/bunyaminergen)
---
### Contact
- [Mail](mailto:info@bunyaminergen.com)
---
### Reference
- This model has been fine-tuned using Supervised Fine Tuning (SFT) method from the original
model [Qwen/Qwen2.5-Coder-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-1.5B-Instruct).
---
### Citation
```bibtex
@software{ Qwen2.5-Coder-1.5B-Instruct-Reasoning,
author = {Bunyamin Ergen},
title = {{Qwen2.5-Coder-1.5B-Instruct-Reasoning}},
year = {2025},
month = {04},
}
```
---