-
Notifications
You must be signed in to change notification settings - Fork 631
[Maca] fix ray and memory sync #4164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes ray executor initialization and memory synchronization issues for the Maca device backend. The changes ensure proper device-specific initialization and add CPU synchronization to prevent potential race conditions during tensor operations.
- Separated Maca from CUDA initialization path and added dedicated
_init_maca_distributed_environmentmethod - Improved memory synchronization by using pre-computed
q_start_locfrom step context - Added explicit CPU synchronization (
.cpu().item()) when computing max sequence lengths during prefill stage
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lmdeploy/pytorch/engine/executor/ray_executor.py | Adds dedicated Maca distributed environment initialization method, separating it from CUDA handling |
| lmdeploy/pytorch/backends/dlinfer/maca/op_backend.py | Fixes memory sync issues by using pre-computed values, adds CPU sync for max length computation, and optimizes by skipping unnecessary calculations during decoding |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def _init_maca_distributed_environment(self, driver_ip): | ||
| """Init maca distributed environment.""" | ||
| self.workers = self._sort_workers(driver_ip, self.workers) | ||
| ray.get([worker.set_device.remote(idx) for idx, worker in enumerate(self.workers)]) |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _init_maca_distributed_environment method is identical to _init_camb_distributed_environment. Consider extracting this common logic into a shared helper method to reduce code duplication. For example:
def _init_generic_distributed_environment(self, driver_ip):
"""Init generic distributed environment for device types."""
self.workers = self._sort_workers(driver_ip, self.workers)
ray.get([worker.set_device.remote(idx) for idx, worker in enumerate(self.workers)])
def _init_camb_distributed_environment(self, driver_ip):
self._init_generic_distributed_environment(driver_ip)
def _init_maca_distributed_environment(self, driver_ip):
"""Init maca distributed environment."""
self._init_generic_distributed_environment(driver_ip)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch
Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily receiving feedbacks. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
Motivation
Please describe the motivation of this PR and the goal you want to achieve through this PR.
Modification
Please briefly describe what modification is made in this PR.
BC-breaking (Optional)
Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.
Use cases (Optional)
If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.
Checklist