GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [Fix] Fix data partition bugs and optimizations by baymax591 · Pull Request #100 · TransferQueue/TransferQueue
This repository was archived by the owner on Jan 21, 2026. It is now read-only.
Conversation
|
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThe PR includes English translations of inline comments in demo files, introduces a new async put test workflow with Ray-based distributed data orchestration, adds a documentation note about data ordering in async operations, and refactors the transfer queue controller with signature changes, improved tensor initialization, and stricter error handling. Changes
Sequence DiagramsequenceDiagram
participant Test as test_async_put()
participant Trainer
participant AsyncPutManager
participant APWorker as AsyncPutWorker<br/>(Ray Actor)
participant Controller as TransferQueueController
participant Storage as Storage Units
Test->>Trainer: __init__(config)
Trainer->>Trainer: _initialize_data_system()
Trainer->>Controller: initialize controller
Trainer->>Storage: setup storage units
Test->>Trainer: async_put()
Trainer->>Trainer: build TensorDict batch
Trainer->>AsyncPutManager: put_data(data, partition_id)
AsyncPutManager->>AsyncPutManager: split data across workers
par Parallel Workers
AsyncPutManager->>APWorker: put_data (worker 1)
APWorker->>Controller: async_put operation
Controller->>Storage: write to unit 1
APWorker-->>AsyncPutManager: done
and
AsyncPutManager->>APWorker: put_data (worker 2)
APWorker->>Controller: async_put operation
Controller->>Storage: write to unit 2
APWorker-->>AsyncPutManager: done
end
AsyncPutManager-->>Trainer: all workers complete
Trainer->>Controller: async_get_meta()
Controller-->>Trainer: batch metadata
Trainer->>Controller: async_get_data()
Controller->>Storage: fetch data
Storage-->>Controller: return data
Controller-->>Trainer: data returned
Trainer->>Trainer: validate shape & content
Test->>Test: assertions pass
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This PR refactors the data partition status management and improves consistency across the transfer queue system. The changes focus on simplifying capacity management, improving error handling, and updating comments from Chinese to English.
production_status tensor at declaration time instead of lazilyclear() method to raise exception instead of returning False for missing partitions_update_field_metadata() to use itemgetter for better performanceCopilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| transfer_queue/controller.py | Core refactoring: initializes production_status upfront, simplifies ensure_*_capacity methods, optimizes metadata updates with itemgetter, and changes error handling in clear() |
| transfer_queue/client.py | Adds documentation note about potential data ordering inconsistencies with multiple workers |
| tests/test_async_put.py | New test file for async_put functionality with multiple workers |
| recipe/simple_use_case/sync_demo.py | Translates Chinese comments to English |
| recipe/simple_use_case/async_demo.py | Translates Chinese comments to English |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@coderabbitai review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
✅ Actions performedReview triggered.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
transfer_queue/controller.py (1)
908-928: Critical issue: Three call sites must be updated to handle the new ValueError exception.The breaking change causes the code to crash at runtime:
controller.py:1085(in ZMQ message handler): Assigns return value but will now receive an exception insteadtest_client.py:355: Calls clear without exception handlingsync_demo.py:180: Calls clear without exception handlingAll three require try-except blocks or validation before calling
clear().
recipe/simple_use_case/sync_demo.py (4)
94-94: Comment translation implemented as previously suggested.This change implements the translation suggested in a previous review.
109-109: Comment translation implemented as previously suggested.This change implements the translation suggested in a previous review.
118-118: Comment translation implemented as previously suggested.This change implements the translation suggested in a previous review.
126-126: Comment translation implemented as previously suggested.This change implements the translation suggested in a previous review.
transfer_queue/controller.py (1)
339-356: Critical: itemgetter fails with empty list and None checks are ineffective.Two critical issues persist from previous review:
- Line 339-340:
itemgetter(*global_indices)raisesTypeErrorwhenglobal_indicesis empty- Line 353-355: None checks occur after tuple conversion, making them ineffective. After lines 342-345,
dtype_valueandshape_valueare always tuples, so the None check passes even when containing None elements.Apply this fix:
def _update_field_metadata( self, global_indices: list[int], field_names: list[str], dtypes: Optional[dict[int, dict[str, Any]]] = None, shapes: Optional[dict[int, dict[str, Any]]] = None, ): """Update field dtype and shape metadata.""" - dtype_value = itemgetter(*global_indices)(dtypes) if dtypes else None - shape_value = itemgetter(*global_indices)(shapes) if shapes else None + # Handle empty global_indices + if not global_indices: + return + + dtype_value = itemgetter(*global_indices)(dtypes) if dtypes and global_indices else None + shape_value = itemgetter(*global_indices)(shapes) if shapes and global_indices else None if not isinstance(dtype_value, tuple): dtype_value = (dtype_value,) if not isinstance(shape_value, tuple): shape_value = (shape_value,) for i, global_idx in enumerate(global_indices): if global_idx not in self.field_dtypes: self.field_dtypes[global_idx] = {} if global_idx not in self.field_shapes: self.field_shapes[global_idx] = {} - if dtype_value is not None: + if dtype_value is not None and dtype_value[i] is not None: self.field_dtypes[global_idx].update(dtype_value[i]) - if shape_value is not None: + if shape_value is not None and shape_value[i] is not None: self.field_shapes[global_idx].update(shape_value[i])
tests/test_async_put.py (3)
46-59: Consider making client_id unique per worker instance.All
AsyncPutWorkerinstances share the hardcoded client_id"AsyncvLLMServer", which may cause confusion in logs when multiple workers operate concurrently.Consider passing a unique identifier to each worker:
@ray.remote(num_cpus=1) class AsyncPutWorker: - def __init__(self, config, data_system_controller_info): + def __init__(self, config, data_system_controller_info, worker_id=None): self.config = config + client_id = f"AsyncPutWorker_{worker_id}" if worker_id is not None else "AsyncPutWorker" self.data_system_client = AsyncTransferQueueClient( - client_id="AsyncvLLMServer", + client_id=client_id, controller_info=data_system_controller_info, )Then update the manager to pass worker_id:
for i in range(num_workers): self.async_put_workers.append(AsyncPutWorker.remote(config, data_system_controller_info, worker_id=i))
157-178: LGTM! Test validates async_put workflow effectively.The test correctly validates data integrity by comparing sorted flattened tensors, which accounts for potential ordering inconsistencies from distributed writes.
Consider adding a comment explaining why sorting is necessary:
assert data_fetch.shape == data_origin.shape assert data_fetch["input_ids"].shape == data_origin["input_ids"].shape + # Compare sorted tensors to handle potential ordering differences from distributed async_put assert torch.equal( torch.sort(data_fetch["input_ids"].flatten())[0], torch.sort(data_origin["input_ids"].flatten())[0] )
41-43: Consider moving Ray initialization into test function for better isolation.Module-level
ray.init()may affect test isolation if other tests in the suite have different Ray configuration requirements.Consider using a fixture or setUp method:
@pytest.fixture(scope="module") def ray_cluster(): os.environ["RAY_DEDUP_LOGS"] = "0" os.environ["RAY_DEBUG"] = "1" ray.init() yield ray.shutdown() def test_async_put(ray_cluster): # test implementation ...However, if this pattern is consistent with other tests in the project, the current approach is acceptable.
transfer_queue/controller.py (1)
183-183: Inconsistent initialization: production_status is never None but still typed Optional.The
production_statusis now pre-initialized to a tensor, so it will never beNone. However, the type hint remainsOptional[torch.Tensor]and several methods still perform None checks.Consider one of the following:
Option 1: Remove Optional and None checks
- production_status: Optional[torch.Tensor] = torch.zeros(TQ_INIT_SAMPLE_NUM, TQ_INIT_FIELD_NUM, dtype=torch.int8) + production_status: torch.Tensor = field(default_factory=lambda: torch.zeros(TQ_INIT_SAMPLE_NUM, TQ_INIT_FIELD_NUM, dtype=torch.int8))Then remove None checks in methods like
ensure_fields_capacity(line 256),scan_data_status(line 414), etc.Option 2: Keep Optional for flexibility
If None should be supported, initialize as
Noneand handle the first-use initialization properly.
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
recipe/simple_use_case/async_demo.py (3 hunks)recipe/simple_use_case/sync_demo.py (4 hunks)tests/test_async_put.py (1 hunks)transfer_queue/client.py (1 hunks)transfer_queue/controller.py (9 hunks)recipe/simple_use_case/sync_demo.py (1)
177-186: LGTM! Comment translations improve code readability.The English comments clearly explain the data clearing workflow and system initialization process.
transfer_queue/client.py (1)
247-249: LGTM! Valuable documentation about distributed execution behavior.The note appropriately warns users about potential data ordering inconsistencies when multiple workers perform distributed put operations concurrently.
recipe/simple_use_case/async_demo.py (5)
60-60: LGTM! Comment translation improves readability.The English comment clearly explains the data retrieval step.
75-75: LGTM! Comment translation improves readability.The English comment clearly explains the data writing step.
83-83: LGTM! Comment translation improves readability.The English comment clearly explains the data retrieval step.
91-91: LGTM! Comment translation improves readability.The English comment clearly explains the data writing step.
294-295: LGTM! Comment translation improves readability.The English comments clearly explain the clearing workflow between controller and storage units.
tests/test_async_put.py (1)
87-155: LGTM! Trainer class follows established patterns.The data system initialization and async_put workflow follow the same patterns used in demo files, ensuring consistency across the codebase.
transfer_queue/controller.py (5)
20-20: LGTM! Import added for itemgetter usage.The
itemgetterimport supports the refactored_update_field_metadatamethod.
102-109: LGTM! More idiomatic Python.Using truthiness check instead of length comparison is cleaner and more Pythonic.
210-213: LGTM! New property exposes allocated row count.The
allocated_samples_numproperty follows the same pattern as other properties and provides useful information about tensor capacity.
304-305: LGTM! Logical reordering ensures capacity before operations.Calling
ensure_samples_capacitybefore field registration ensures adequate row capacity is available before performing updates.
451-457: I need to verify there are no other call sites outside the immediate results. Let me search more comprehensively:Let me verify there are no indirect calls or dynamic usages:
Based on the verification of all call sites in the codebase, the signature changes have been properly applied throughout:
- Method definitions (lines 451, 455): Using
(self, global_index: int, field_name: str)- Call sites in main code (lines 871-872, 885-886): All using
partition.get_field_dtype(global_index, field_name)✓- Call sites in tests (lines 50-51, 286-287, 363-364): All using the new signature correctly ✓
No breaking usages remain.
Signature changes verified and consistent across all call sites. All usages of
get_field_dtypeandget_field_shapehave been properly updated to match the new parameter name fromsample_idxtoglobal_index. The refactoring is complete with no orphaned calls.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
7ce72f7 to
1de4405
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.