File size: 3,618 Bytes
cd3b9c8 0087c8e cd3b9c8 37eae19 86cecf5 37eae19 f150200 37eae19 8aaf671 37eae19 8aaf671 37eae19 cd3b9c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
---
base_model:
- tiiuae/Falcon3-3B-Instruct-1.58bit
tags:
- Repair
- Code
- Test
- Test-case-generation
- Code-Repair
---
# Falcon3-3B-Instruct-RL-CODE-FIX
This repository hosts the **Falcon3-3B-Instruct-RL-CODE-FIX** model — a fine-tuned version of [Falcon3-3B-Instruct](https://huggingface.co/tiiuae/falcon3-3b-instruct), trained using **GRPO (Group Relative Policy Optimization)** to solve programming tasks in the context of automatic program repair.
## 🛠️ Model Purpose
This model is designed to:
- **Understand buggy code snippets**
- **Propose test cases that expose the bugs**
- **Generate fixed versions of the code**
It is particularly useful for:
- **Code contests**
- **Automated debugging**
- **Education and code quality assurance**
## 🧠 Training Details
- **Base model**: Falcon3-3B-Instruct
- **Method**: GRPO
- **Dataset**: Custom dataset of buggy code + test cases + fixes
- **Objective**: Improve model reasoning over structured code repair tasks
## 🚀 Usage Example
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
faulty ="""
def add (x, y):
\"\"\"return sum of x and y\"\"\"
return x * y
"""
PROGRAM_REPAIR_TEMPLATE = f"""
You are an expert in the field of software testing.
You are given a buggy Python program, you are supposed to first generate testcases that can expose the bug,
and then generate the corresponding fixed code. The two tasks are detailed as follows.
1. **Generate a comprehensive set of test cases to expose the bug**:
- Each test case should include an input and the expected output.
- Output the test cases as a JSON list, where each entry is a dictionary with keys `"test_input"` and `"test_output"`.
- Write in ```json ``` block.
2. **Provide a fixed version**:
- Write a correct Python program to fix the bug.
- Write in ```python ``` block.
- The code should read from standard input and write to standard output, matching the input/output format specified in the problem.
Here is an example.
The faulty Python program is:
\`\`\`python
\"\"\"Please write a Python program to sum two integer inputs\"\"\"
def add (x, y):
return x - y
x = int(input())
y = int(input())
print(add(x,y))
\`\`\`
Testcases that can expose the bug:
\`\`\`json
[
{{
\"test_input\":\"1\n2\",
\"test_output\":\"3\"
}},
{{
\"test_input\":\"-1\n1\",
\"test_output\":\"0\"
}},
{{
\"test_input\":\"-1\n2\",
\"test_output\":\"1\"
}}
]
\`\`\`
Fixed code:
\`\`\`python
def add (x, y):
return x + y
x = int(input())
y = int(input())
print(add(x,y))
\`\`\`
Now, you are given a faulty Python function, please return:
1. **Testcases** that helps expose the bug.
2. **Fixed code** that can pass all testcases.
The faulty function is:
\`\`\`python
{faulty}
\`\`\`
<|assistant|>
"""
model = AutoModelForCausalLM.from_pretrained(
"Neo111x/Falcon3-3B-Instruct-RL-CODE-RL",
trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(
"Neo111x/Falcon3-3B-Instruct-RL-CODE-RL",
trust_remote_code=True
)
messages = [
{"role": "user", "content": PROGRAM_REPAIR_TEMPLATE}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=512
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)
``` |