-
Notifications
You must be signed in to change notification settings - Fork 84
[bug fix] Dispatch FP8 #296
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
kaniel-outis
wants to merge
11
commits into
sgl-project:main
Choose a base branch
from
kaniel-outis:0104_dispatch_fp8
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.
Open
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5d3ba92
dispatch fp8
6f37be9
fix
36136c3
fix
e68796f
Merge remote-tracking branch 'refs/remotes/origin/main' into 0104_dis…
4eae815
Merge remote-tracking branch 'refs/remotes/origin/main' into 0104_dis…
da5a0e3
SyncFunc<AscendC::HardEvent::V_MTE2>();
6abb089
add debug mode
c3169a6
fix
c4d7af2
fix lint
30105a9
fix commit
bc5a3b1
fix
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,9 +243,18 @@ def check_layout_a2_data(notify_send_data): | |
| for i in range(num_ranks): | ||
| num_tokens_per_rank[i] = (rank_idx == i).sum() | ||
| token_sel = (rank_idx == i).max(dim=-1)[0] | ||
| count = token_sel.sum().item() | ||
| tokens = torch.sort(token_sel.to(torch.int), descending=True)[1] | ||
| tokens[:count] = torch.sort(tokens[:count])[0] | ||
| count = token_sel.sum().cpu().item() | ||
|
|
||
| # Perform sorting on CPU | ||
| token_sel_cpu = token_sel.to(torch.int).cpu() | ||
| tokens_cpu = torch.sort(token_sel_cpu, descending=True)[1] | ||
| sorted_tokens = torch.sort(tokens_cpu[:count])[0] | ||
|
|
||
| # Put the results back into the NPU | ||
| tokens = tokens_cpu.to("npu") | ||
| tokens[:count] = sorted_tokens.to("npu") | ||
|
|
||
| # Ensure the size of arrange matches the count. | ||
| token_idx_in_rank[i][tokens[:count]] = torch.arange( | ||
| count, dtype=torch.long, device="npu" | ||
| ) | ||
|
|
@@ -430,14 +439,25 @@ def test_correctness(): | |
| combined_x, combined_topk_weights, event = buffer.combine(**combine_args) | ||
| check_x = combined_x.float() | ||
| ref_x = x_pure_rand if current_x is x_pure_rand else x | ||
| assert ( | ||
| calc_diff( | ||
| check_x, | ||
| ref_x | ||
| * handle[4].masked_fill(topk_idx == -1, 0).sum(dim=1).view(-1, 1), | ||
| ) | ||
| < 5e-5 | ||
| # Calculate the intermediate values of each item | ||
| masked_values = ( | ||
| handle[4].masked_fill(topk_idx == -1, 0).sum(dim=1).view(-1, 1) | ||
| ) | ||
| scaled_ref_x = ref_x * masked_values | ||
|
|
||
| # Calculate the difference | ||
| diff_result = calc_diff(check_x, scaled_ref_x) | ||
|
|
||
| if args.debug: | ||
| print(f"Debug - diff_result: {diff_result}, threshold: {5e-5}") | ||
| print( | ||
| f"Debug - masked_values (first 10): {masked_values.flatten()[:10]}" | ||
| ) | ||
| print(f"Debug - ref_x (first 10): {ref_x.flatten()[:10]}") | ||
| print(f"Debug - scaled_ref_x (first 10): {scaled_ref_x.flatten()[:10]}") | ||
| print(f"Debug - check_x (first 10): {check_x.flatten()[:10]}") | ||
|
|
||
| assert diff_result < 5e-5 | ||
|
|
||
| if local_rank == 0: | ||
| print(" passed", flush=True) | ||
|
|
@@ -587,6 +607,13 @@ def test_loop(local_rank: int, num_local_ranks: int, args: argparse.Namespace): | |
| action="store_true", | ||
| help="Whether to enable diagnose for testing", | ||
| ) | ||
| parser.add_argument( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The switch for enabling or disabling quantization needs to be added to the test script.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
| "--debug", | ||
| action="store_true", | ||
| default=False, | ||
| help="Enable debug logging.", | ||
| ) | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| num_processes = args.num_processes | ||
|
|
||
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.
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.
Add a comment explaining what problems would occur if this synchronization is not added, and why adding this synchronization would prevent these problems.
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.
added