Skip to content

Conversation

@wanfengcxz
Copy link
Contributor

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

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  3. If the modification has a dependency on downstream projects of a newer version, this PR should be tested with all supported versions of downstream projects.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@lvhan028 lvhan028 requested a review from jinminxi104 November 28, 2025 06:28
@jinminxi104 jinminxi104 requested a review from Copilot December 4, 2025 08:05
Copilot finished reviewing on behalf of jinminxi104 December 4, 2025 08:07
Copy link
Contributor

Copilot AI left a 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_environment method
  • Improved memory synchronization by using pre-computed q_start_loc from 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.

Comment on lines 599 to 602
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)])
Copy link

Copilot AI Dec 4, 2025

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)

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants