[MoE][ddp] Enable distributed MoE calibration replacement#2449
[MoE][ddp] Enable distributed MoE calibration replacement#2449dichn wants to merge 3 commits intovllm-project:mainfrom
Conversation
Extends moe_calibration_context to support PyTorch DDP for parallel MoE module replacement across multiple ranks during calibration. Key changes: - Pre-replacement verification: all_gather to ensure consistent module counts across ranks, preventing structure mismatch errors - Post-replacement barrier: synchronizes all ranks before calibration begins - Post-restoration barrier: ensures clean context manager exit - Rank-aware logging: only rank 0 shows progress bars and info logs Tests include single-rank and DDP integration coverage.
|
👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review. Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively extends moe_calibration_context to support distributed data parallel (DDP) environments. The changes, including pre-replacement verification of module counts, proper synchronization with barriers, and rank-aware logging, are well-implemented. The addition of both single-rank and DDP tests is also a great improvement. I've identified a potential issue in both the implementation and the new DDP test related to device placement for tensors used in distributed communication, which could lead to runtime errors with certain backends like nccl. My review includes suggestions to make the code more robust in this regard.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Di Chen <dichen@redhat.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Di Chen <dichen@redhat.com>
kylesayrs
left a comment
There was a problem hiding this comment.
Seems like you still need to actually implement the distributed workload logic, ie assigning modules to ranks, processing them, then broadcasting the results.
I recommend looking at the following algorithm, as I think this may be the best way to support distributed MoE Calibration Replacement: vllm-project/compressed-tensors#624
| all_counts = [torch.zeros_like(num_modules) for _ in range(world_size)] | ||
| dist.all_gather(all_counts, num_modules) | ||
|
|
||
| if not all(count.item() == num_modules.item() for count in all_counts): |
There was a problem hiding this comment.
Sometimes, the number of modules will be not evenly divisible by the number of ranks, so this check can be harmful.
There was a problem hiding this comment.
This is just checking that each rank has the same number of modules total, not assigned I think
| if _is_registered(class_name, MoECalibrationModule): | ||
| modules_to_replace.append((name, module, class_name)) | ||
|
|
||
| # Step 1.5: Verify all ranks have same number of modules (distributed mode) |
There was a problem hiding this comment.
It doesn't look like you actually assign modules to ranks. It seems like right now, all ranks are still doing duplicate work.
| if modules_to_replace: | ||
| logger.info(f"Found {len(modules_to_replace)} MoE modules to replace") | ||
| # Only rank 0 shows progress bar and logs | ||
| show_progress = not is_distributed() or dist.get_rank() == 0 |
There was a problem hiding this comment.
Can use is_rank0, also probably simpler to just inline this into the if statement
| if _is_registered(class_name, MoECalibrationModule): | ||
| modules_to_replace.append((name, module, class_name)) | ||
|
|
||
| # Step 1.5: Verify all ranks have same number of modules (distributed mode) |
There was a problem hiding this comment.
I also don't think this check is necessary
SUMMARY:
Extends moe_calibration_context to support PyTorch DDP for parallel MoE module replacement across multiple ranks during calibration.
Key changes:
TEST PLAN:
Tests include single-rank and DDP integration coverage.