Commit c2bb0fa
[feat] Support
## Title
Add reset_consumption Interface for Reusing Data in TransferQueue
## Description
### Overview
This PR adds the `reset_consumption` interface to TransferQueue,
allowing users to reset the consumption status of data samples without
clearing the actual data. This is particularly useful for debugging
scenarios where the same rollout data needs to be processed multiple
times without regenerating it.
### Changes Made
#### 1. **Core Controller Implementation**
(`transfer_queue/controller.py`)
- Added `reset_consumption()` method in `DataPartitionStatus` class to
reset consumption status for specific tasks or all tasks
- Added `reset_consumption()` method in `TransferQueueController` class
to handle partition-level consumption reset
- Added request handling for `RESET_CONSUMPTION` and
`RESET_CONSUMPTION_RESPONSE` message types in the controller's request
processing logic
#### 2. **Client API** (`transfer_queue/client.py`)
- Added `async_reset_consumption()` async method for resetting
consumption status via async operations
- Added `reset_consumption()` synchronous wrapper method for convenience
- Both methods support resetting consumption for a specific task or all
tasks in a partition
#### 3. **Protocol Extensions** (`transfer_queue/utils/zmq_utils.py`)
- Added `RESET_CONSUMPTION` and `RESET_CONSUMPTION_RESPONSE` request
types to `ZMQRequestType` enum
#### 4. **Comprehensive Testing**
**In `tests/test_client.py`:**
- Added `MockController` support for `RESET_CONSUMPTION` requests
- Added `test_reset_consumption()` - Tests synchronous reset with
specific task name
- Added `test_reset_consumption_all_tasks()` - Tests synchronous reset
for all tasks
- Added `test_async_reset_consumption()` - Tests async reset with
specific task name
- Added `test_async_reset_consumption_all_tasks()` - Tests async reset
for all tasks
**In `tests/test_controller.py`:**
- Added `test_controller_reset_consumption()` - Comprehensive
integration test that verifies:
- Consumption status before and after data consumption
- Reset functionality for specific tasks
- Reset functionality for all tasks (task_name=None)
- Multi-task consumption scenarios
### Usage Examples
**Synchronous API:**
```python
from transfer_queue import TransferQueueClient
client = TransferQueueClient(client_id="client_0", controller_info=controller_info)
# Reset consumption for a specific task
success = client.reset_consumption(partition_id="train_0", task_name="generate_sequences")
# Reset consumption for all tasks in a partition
success = client.reset_consumption(partition_id="train_0")
```
**Asynchronous API:**
```python
import asyncio
# Reset consumption for a specific task
success = await client.async_reset_consumption(partition_id="train_0", task_name="generate_sequences")
# Reset consumption for all tasks
success = await client.async_reset_consumption(partition_id="train_0")
```
**Use Case Example:**
```python
# Scenario: Re-train on the same rollout data without regeneration
# Step 1: Fetch data and train
batch_meta = client.get_meta(
data_fields=["prompts", "attention_mask"],
batch_size=32,
partition_id="train_0",
mode="fetch",
task_name="training"
)
batch_data = client.get_data(batch_meta)
# ... perform training ...
# Step 2: Reset consumption to allow re-training on same data
client.reset_consumption(partition_id="train_0", task_name="training")
# Step 3: Fetch and train again on the same data
batch_meta = client.get_meta(
data_fields=["prompts", "attention_mask"],
batch_size=32,
partition_id="train_0",
mode="fetch",
task_name="training"
)
batch_data = client.get_data(batch_meta)
# ... perform training again ...
```
Signed-off-by: yuetian <zhangliujie@xiaohongshu.com>
Co-authored-by: yuetian <zhangliujie@xiaohongshu.com>async_reset_consumption to reuse data (#25)1 parent fbdb58e commit c2bb0fa
5 files changed
Lines changed: 352 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
140 | 147 | | |
141 | 148 | | |
142 | 149 | | |
| |||
531 | 538 | | |
532 | 539 | | |
533 | 540 | | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
534 | 587 | | |
535 | 588 | | |
536 | 589 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
201 | 358 | | |
202 | 359 | | |
203 | 360 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
768 | 768 | | |
769 | 769 | | |
770 | 770 | | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
771 | 828 | | |
772 | 829 | | |
773 | 830 | | |
| |||
917 | 974 | | |
918 | 975 | | |
919 | 976 | | |
| 977 | + | |
920 | 978 | | |
921 | 979 | | |
922 | 980 | | |
| |||
1138 | 1196 | | |
1139 | 1197 | | |
1140 | 1198 | | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
1141 | 1211 | | |
1142 | 1212 | | |
1143 | 1213 | | |
| |||
0 commit comments