Repository navigation
feat: extend DCP to GQA and optimize query communication #4995
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
Open
CUHKSZzxy
wants to merge
17
commits into
InternLM:main
Choose a base branch
from
CUHKSZzxy:feat/dcp-optimizations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,221
−905
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
494aedf
perf: optimize DCP query communication
CUHKSZzxy ab9394c
feat: support GQA DCP with FP8 KV cache
CUHKSZzxy 1cfd056
test: remove standalone GQA DCP tests
CUHKSZzxy cced26e
fix: propagate KV quantization policy to draft attention
CUHKSZzxy a37a37a
refactor: simplify CUDA communicator routing
CUHKSZzxy 525073f
refactor: centralize DCP workspace and collective ownership
CUHKSZzxy cdc3e4b
perf: accelerate DCP top-k candidate gathering with symmetric memory
CUHKSZzxy 4fc799a
perf: skip redundant DCP query-gather entry synchronization
CUHKSZzxy f460e04
test: decouple DCP candidate gathering from DeepGEMM
CUHKSZzxy 9161e64
perf: accelerate DCP LSE gathering with symmetric memory
CUHKSZzxy 24ab1c7
perf: accelerate DCP prefix gathering and reordering
CUHKSZzxy 8ea44bf
test: simplify CUDA communicator tests
CUHKSZzxy ce91b1f
refactor: clarify optimized all-reduce routing
CUHKSZzxy d6f7c1d
style: fix lint issues
CUHKSZzxy 61bf5d6
fix: reject ALiBi for GQA DCP
CUHKSZzxy 188287e
Merge branch 'main' into feat/dcp-optimizations
CUHKSZzxy c0fbb22
Merge branch 'main' into feat/dcp-optimizations
CUHKSZzxy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,57 @@ | ||
| # Copyright (c) OpenMMLab. All rights reserved. | ||
| from typing import Literal | ||
|
|
||
| import torch | ||
| from torch import distributed as dist | ||
|
|
||
|
|
||
| class DeviceCommunicator: | ||
| """Device-neutral collective operations for one process group.""" | ||
| """Device-neutral collective operations for one process group. | ||
|
|
||
| Workspace creation returns a prepared, caller-owned workspace when available. Collective methods execute with native | ||
| fallback when an optimized implementation cannot handle the input. | ||
| """ | ||
|
|
||
| def __init__(self, device_group: dist.ProcessGroup): | ||
| self.device_group = device_group | ||
|
|
||
| def supports_optimized_all_reduce(self) -> bool: | ||
| """Whether an optimized all-reduce implementation is available.""" | ||
| return False | ||
|
|
||
| def supports_fused_all_reduce_residual_rms_norm(self) -> bool: | ||
| """Whether fused all-reduce, residual and RMSNorm is available.""" | ||
| return False | ||
|
|
||
| def try_fused_all_reduce_residual_rms_norm(self, | ||
| input: torch.Tensor, | ||
| residual: torch.Tensor, | ||
| weight: torch.Tensor, | ||
| eps: float): | ||
| """Run fused all-reduce, residual and RMSNorm when eligible.""" | ||
| return None | ||
|
|
||
| def all_reduce_(self, input: torch.Tensor): | ||
| """All-reduce ``input`` in place.""" | ||
| dist.all_reduce(input, group=self.device_group) | ||
|
|
||
| def all_gather(self, input: torch.Tensor, *, dim: int = -1, | ||
| workspace=None, copy_output: bool = True) -> torch.Tensor: | ||
| """Gather 2D inputs along dimension 0 or -1 on every group rank. | ||
|
|
||
| With copy_output=False, optimized output may borrow the workspace until its next use. Consume it on the same | ||
| stream. Native gathering always returns an owned output for multi-rank groups. | ||
| """ | ||
| if input.dim() != 2 or dim not in (0, -1): | ||
| raise ValueError('all_gather requires a 2D input and dim=0 or dim=-1') | ||
| world_size = dist.get_world_size(self.device_group) | ||
| if world_size == 1: | ||
| return input | ||
| input = input.contiguous() | ||
| gathered = input.new_empty(world_size * input.size(0), input.size(1)) | ||
| dist.all_gather_into_tensor(gathered, input, group=self.device_group) | ||
| if dim == 0: | ||
| return gathered | ||
| return gathered.view(world_size, *input.shape).transpose(0, 1).reshape(input.size(0), -1) | ||
|
|
||
| def create_all_gather_workspace(self, gathered_width: int, device: torch.device, dtype: torch.dtype, | ||
| *, dim: int = -1, reuse_sync: bool = True, capacity_bytes: int = 64 * 1024 * 1024): | ||
| """Create a caller-owned workspace. | ||
|
|
||
| Disable reuse_sync only when a subsequent same-group collective orders all consumers before the next gather. | ||
| """ | ||
| return None | ||
|
|
||
| def close(self): | ||
| """Release communicator-owned resources.""" | ||
| pass | ||
| """Release group-owned resources; gather workspaces belong to | ||
| callers.""" | ||
|
|
||
|
|
||
| def build_communicator(cpu_group: dist.ProcessGroup, device_group: dist.ProcessGroup, | ||
| dist_config): | ||
| dist_config, *, group_name: Literal['tp', 'dcp'] = 'tp'): | ||
| """Build the default process-group communicator.""" | ||
| return DeviceCommunicator(device_group=device_group) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.