roskosmos19 commited on
Commit
0e65b0d
·
verified ·
1 Parent(s): 68f1180

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +151 -16
README.md CHANGED
@@ -1,3 +1,4 @@
 
1
  ---
2
  datasets:
3
  - Aquiles-ai/Athenea-Coding-100k
@@ -8,29 +9,38 @@ tags:
8
  - merge
9
  - uncensored
10
  - Rhea
 
 
11
  language:
12
  - en
13
  pipeline_tag: text-generation
14
  library_name: transformers
15
  ---
16
 
17
- <h1 align="center">Rhea 4BCoding</h1>
18
 
19
  ![image](atheneamodel.png)
20
 
21
- **Rhea-4B-Coding** is a optimized version of [Aquiles-ai/Athenea-4B-Coding](https://huggingface.co/Aquiles-ai/Athenea-4B-Coding), specialized in **code reasoning, debugging, agentic tools and problem solving**.
22
- Trained on high-quality programming data with explicit reasoning traces using `<think>` and `</think>` tags, the model is designed to perform detailed step-by-step reasoning for software development, algorithm design, and code comprehension tasks.
 
 
 
 
 
23
 
24
  > ⚠️ **Important Note:** This model uses an *uncensored* base version, providing full expressive freedom and unrestricted output generation. Users are fully responsible for any use or content produced by the model. It is intended exclusively for research and experimentation purposes.
25
 
26
  ## 🎯 Model Description
27
 
28
- Rhea-4B-Coding extends Athenea-4B-Codings structured reasoning capabilities into programming-related domains, showing strong performance on logical problem-solving, code completion, and debugging scenarios.
29
 
30
  Key features:
31
 
 
32
  * **Agentic Tools** for AI Agents
33
- * **Step-by-step code reasoning** within `<think>` blocks
 
34
  * **Specialization in algorithmic and debugging tasks**
35
  * **Uncensored output generation** for full reasoning visibility
36
  * **Improved logical consistency** through focused fine-tuning
@@ -38,7 +48,20 @@ Key features:
38
 
39
  The model was fine-tuned using the dataset [Aquiles-ai/Athenea-Coding-100k](https://huggingface.co/datasets/Aquiles-ai/Athenea-Coding-100k), which includes diverse programming challenges, structured reasoning chains, and natural language explanations across multiple programming languages.
40
 
 
 
 
41
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  ## 💻 Usage
44
 
@@ -83,13 +106,101 @@ inputs = tokenizer.apply_chat_template(
83
  with torch.no_grad():
84
  output = model.generate(
85
  **inputs,
86
- max_new_tokens=8092,
87
- pad_token_id=tokenizer.eos_token_id,
88
  eos_token_id=tokenizer.eos_token_id,
89
  )
90
 
91
  # Decode and print the output
92
- print(tokenizer.decode(output[0], skip_special_tokens=True))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  ```
94
 
95
  ### Streaming Inference
@@ -99,13 +210,13 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStream
99
  import torch
100
  from threading import Thread
101
 
102
- model = AutoModelForCausalLM.from_pretrained("Aquiles-ai/Athenea-4B-Coding",
103
  dtype=torch.bfloat16,
104
  trust_remote_code=True,
105
  device_map="auto",
106
  attn_implementation="flash_attention_2")
107
 
108
- tokenizer = AutoTokenizer.from_pretrained("Aquiles-ai/Athenea-4B-Coding", trust_remote_code=True)
109
 
110
  messages = [
111
  {"role": "user", "content": "Hey, write a Python function that implements the binary search algorithm recursively."}
@@ -120,13 +231,13 @@ inputs = tokenizer.apply_chat_template(
120
  ).to('cuda')
121
 
122
  # Create the streamer
123
- streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
124
 
125
  # Build kwargs for generate
126
  generate_kwargs = dict(
127
  **inputs,
128
- max_new_tokens=8092,
129
- pad_token_id=tokenizer.eos_token_id,
130
  eos_token_id=tokenizer.eos_token_id,
131
  streamer=streamer,
132
  )
@@ -151,7 +262,7 @@ vllm serve Roskosmos19/Rhea-4B-Coding \
151
  --host 0.0.0.0 \
152
  --port 8000 \
153
  --api-key dummyapikey \
154
- --max-model-len=16384 \
155
  --async-scheduling \
156
  --gpu-memory-utilization=0.90
157
  ```
@@ -167,7 +278,7 @@ stream = client.chat.completions.create(
167
  "role": "user",
168
  "content": "Hey, write a Python function that determines if a string is a palindrome, ignoring case, spaces, and punctuation."
169
  }],
170
- max_tokens=8092,
171
  stream=True
172
  )
173
  for chunk in stream:
@@ -177,8 +288,32 @@ for chunk in stream:
177
 
178
  **vLLM Benefits:** 20-30x faster inference, OpenAI-compatible API, continuous batching, async scheduling.
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
 
 
 
 
181
 
182
  <p align="center">
183
  Roskosmos19
184
- </p>
 
1
+
2
  ---
3
  datasets:
4
  - Aquiles-ai/Athenea-Coding-100k
 
9
  - merge
10
  - uncensored
11
  - Rhea
12
+ - multi-pass
13
+ - reasoning
14
  language:
15
  - en
16
  pipeline_tag: text-generation
17
  library_name: transformers
18
  ---
19
 
20
+ <h1 align="center">Rhea 4B Coding</h1>
21
 
22
  ![image](atheneamodel.png)
23
 
24
+ **Rhea-4B-Coding** is an optimized version of [Aquiles-ai/Athenea-4B-Coding](https://huggingface.co/Aquiles-ai/Athenea-4B-Coding), specialized in **code reasoning, debugging, agentic tools and multi-pass problem solving**.
25
+
26
+ Trained on high-quality programming data with explicit reasoning traces using ` thinking` and ` 思考结束` tags, the model is designed to perform detailed **3-pass reasoning** for software development, algorithm design, and code comprehension tasks:
27
+
28
+ 1. **Pass 1**: First implementation
29
+ 2. **Pass 2**: Self-review for bugs, edge cases, security, performance
30
+ 3. **Pass 3**: Final optimized version with identical functionality
31
 
32
  > ⚠️ **Important Note:** This model uses an *uncensored* base version, providing full expressive freedom and unrestricted output generation. Users are fully responsible for any use or content produced by the model. It is intended exclusively for research and experimentation purposes.
33
 
34
  ## 🎯 Model Description
35
 
36
+ Rhea-4B-Coding extends Athenea-4B-Coding's structured reasoning capabilities into programming-related domains with **multi-pass processing**, showing strong performance on logical problem-solving, code completion, debugging scenarios, and iterative code refinement.
37
 
38
  Key features:
39
 
40
+ * **Multi-Pass Processing**: 3-step reasoning with `<think>`, `<review>`, and `<final>` tags
41
  * **Agentic Tools** for AI Agents
42
+ * **Step-by-step code reasoning** within ` thinking` blocks
43
+ * **Self-review capabilities** for bug detection and optimization
44
  * **Specialization in algorithmic and debugging tasks**
45
  * **Uncensored output generation** for full reasoning visibility
46
  * **Improved logical consistency** through focused fine-tuning
 
48
 
49
  The model was fine-tuned using the dataset [Aquiles-ai/Athenea-Coding-100k](https://huggingface.co/datasets/Aquiles-ai/Athenea-Coding-100k), which includes diverse programming challenges, structured reasoning chains, and natural language explanations across multiple programming languages.
50
 
51
+ ## 🔄 Multi-Pass Architecture
52
+
53
+ The model uses special tokens for structured reasoning:
54
 
55
+ | Token | Purpose |
56
+ |-------|---------|
57
+ | `<think>` | Start of self-review phase (Pass 2) |
58
+ | `</think>` | End of self-review phase |
59
+ | `<review>` | Start of review results documentation |
60
+ | `</review>` | End of review results |
61
+ | `<final>` | Start of final optimized version (Pass 3) |
62
+ | `</final>` | End of final version |
63
+
64
+ This structure ensures **identical functionality** across all passes while improving **code structure, comments, and robustness**.
65
 
66
  ## 💻 Usage
67
 
 
106
  with torch.no_grad():
107
  output = model.generate(
108
  **inputs,
109
+ max_new_tokens=16384, # Increased for multi-pass output
110
+ pad_token_id=tokenizer.pad_token_id,
111
  eos_token_id=tokenizer.eos_token_id,
112
  )
113
 
114
  # Decode and print the output
115
+ print(tokenizer.decode(output[0], skip_special_tokens=False))
116
+ ```
117
+
118
+ ### Multi-Pass Inference (Recommended)
119
+
120
+ ```python
121
+ from transformers import AutoModelForCausalLM, AutoTokenizer
122
+ import torch
123
+
124
+ model = AutoModelForCausalLM.from_pretrained("Roskosmos19/Rhea-4B-Coding",
125
+ dtype=torch.bfloat16,
126
+ trust_remote_code=True,
127
+ device_map="auto")
128
+
129
+ tokenizer = AutoTokenizer.from_pretrained("Roskosmos19/Rhea-4B-Coding", trust_remote_code=True)
130
+
131
+ def generate_multi_pass(prompt, max_tokens_per_pass=4096):
132
+ """
133
+ Generate code with 3-pass reasoning:
134
+ Pass 1: First implementation
135
+ Pass 2: Self-review
136
+ Pass 3: Final optimized version
137
+ """
138
+
139
+ # Pass 1: First implementation
140
+ messages = [{"role": "user", "content": prompt}]
141
+ inputs = tokenizer.apply_chat_template(
142
+ messages,
143
+ add_generation_prompt=True,
144
+ tokenize=True,
145
+ return_dict=True,
146
+ return_tensors="pt",
147
+ ).to('cuda')
148
+
149
+ with torch.no_grad():
150
+ output1 = model.generate(
151
+ **inputs,
152
+ max_new_tokens=max_tokens_per_pass,
153
+ temperature=0.4,
154
+ pad_token_id=tokenizer.pad_token_id,
155
+ eos_token_id=tokenizer.eos_token_id,
156
+ )
157
+
158
+ pass1 = tokenizer.decode(output1[0], skip_special_tokens=False)
159
+
160
+ # Pass 2: Self-review
161
+ review_prompt = pass1 + "\n<<think>\n### PASS 2 - Self-Review:\n"
162
+ inputs2 = tokenizer(review_prompt, return_tensors="pt").to('cuda')
163
+
164
+ with torch.no_grad():
165
+ output2 = model.generate(
166
+ **inputs2,
167
+ max_new_tokens=2048,
168
+ temperature=0.3,
169
+ pad_token_id=tokenizer.pad_token_id,
170
+ eos_token_id=tokenizer.eos_token_id,
171
+ )
172
+
173
+ review = tokenizer.decode(output2[0], skip_special_tokens=False)
174
+
175
+ # Pass 3: Final version
176
+ final_prompt = review + "\n<<final>\n### PASS 3 - Final Version:\n"
177
+ inputs3 = tokenizer(final_prompt, return_tensors="pt").to('cuda')
178
+
179
+ with torch.no_grad():
180
+ output3 = model.generate(
181
+ **inputs3,
182
+ max_new_tokens=max_tokens_per_pass,
183
+ temperature=0.2,
184
+ pad_token_id=tokenizer.pad_token_id,
185
+ eos_token_id=tokenizer.eos_token_id,
186
+ )
187
+
188
+ final = tokenizer.decode(output3[0], skip_special_tokens=False)
189
+
190
+ return {
191
+ "pass1": pass1,
192
+ "review": review,
193
+ "pass3": final
194
+ }
195
+
196
+ # Example usage
197
+ result = generate_multi_pass("Write a Python function for binary search")
198
+ print("=== PASS 1 ===")
199
+ print(result["pass1"])
200
+ print("\n=== REVIEW ===")
201
+ print(result["review"])
202
+ print("\n=== FINAL ===")
203
+ print(result["pass3"])
204
  ```
205
 
206
  ### Streaming Inference
 
210
  import torch
211
  from threading import Thread
212
 
213
+ model = AutoModelForCausalLM.from_pretrained("Roskosmos19/Rhea-4B-Coding",
214
  dtype=torch.bfloat16,
215
  trust_remote_code=True,
216
  device_map="auto",
217
  attn_implementation="flash_attention_2")
218
 
219
+ tokenizer = AutoTokenizer.from_pretrained("Roskosmos19/Rhea-4B-Coding", trust_remote_code=True)
220
 
221
  messages = [
222
  {"role": "user", "content": "Hey, write a Python function that implements the binary search algorithm recursively."}
 
231
  ).to('cuda')
232
 
233
  # Create the streamer
234
+ streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=False)
235
 
236
  # Build kwargs for generate
237
  generate_kwargs = dict(
238
  **inputs,
239
+ max_new_tokens=16384, # Increased for multi-pass output
240
+ pad_token_id=tokenizer.pad_token_id,
241
  eos_token_id=tokenizer.eos_token_id,
242
  streamer=streamer,
243
  )
 
262
  --host 0.0.0.0 \
263
  --port 8000 \
264
  --api-key dummyapikey \
265
+ --max-model-len=262144 \
266
  --async-scheduling \
267
  --gpu-memory-utilization=0.90
268
  ```
 
278
  "role": "user",
279
  "content": "Hey, write a Python function that determines if a string is a palindrome, ignoring case, spaces, and punctuation."
280
  }],
281
+ max_tokens=16384, # Increased for multi-pass output
282
  stream=True
283
  )
284
  for chunk in stream:
 
288
 
289
  **vLLM Benefits:** 20-30x faster inference, OpenAI-compatible API, continuous batching, async scheduling.
290
 
291
+ ## 📝 Model Configuration
292
+
293
+ | Parameter | Value | Description |
294
+ |-----------|-------|-------------|
295
+ | `temperature` | 0.4 | Balanced creativity and consistency |
296
+ | `max_new_tokens` | 32768 | Full multi-pass output capacity |
297
+ | `repetition_penalty` | 1.0 | No penalty for intentional code repetition |
298
+ | `no_repeat_ngram_size` | 0 | Allows code structure repetition |
299
+ | `use_cache` | true | Faster inference for long outputs |
300
+
301
+ ## ⚙️ Files Modified for Multi-Pass
302
+
303
+ | File | Changes |
304
+ |------|---------|
305
+ | `generation_config.json` | Extended tokens, optimized for multi-pass |
306
+ | `config.json` | Enabled caching, full context window |
307
+ | `tokenizer_config.json` | Added `<think>`, `<review>`, `<final>` tokens |
308
+ | `special_tokens_map.json` | Registered new special tokens |
309
+ | `chat_template.jinja` | 3-pass prompt structure |
310
+
311
+ ## 🤝 Credits
312
 
313
+ - Base model: [Aquiles-ai/Athenea-4B-Coding](https://huggingface.co/Aquiles-ai/Athenea-4B-Coding)
314
+ - Dataset: [Aquiles-ai/Athenea-Coding-100k](https://huggingface.co/datasets/Aquiles-ai/Athenea-Coding-100k)
315
+ - Architecture: Qwen3 4B
316
 
317
  <p align="center">
318
  Roskosmos19
319
+ </p>