-
Notifications
You must be signed in to change notification settings - Fork 325
import flashqla and support cudagraph for gdn #1292
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
WANDY666
wants to merge
6
commits into
main
Choose a base branch
from
flashqla
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.
+619
−6
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| # ruff: noqa: E501 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import torch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from einops import rearrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import functools | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from lightllm.utils.log_utils import init_logger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from .chunk_delta_h import chunk_gated_delta_rule_fwd_h | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from .chunk_o import chunk_fwd_o | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -19,6 +22,36 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| from .utils import SUPPRESS_LEVEL, input_guard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from .wy_fast import recompute_w_u_fwd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger = init_logger(__name__) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @functools.lru_cache(maxsize=1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _flashqla_chunk_gated_delta_rule(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if os.environ.get("LIGHTLLM_DISABLE_FLASHQLA", "0").lower() in ["1", "true", "yes"]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import flash_qla | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except ImportError: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not torch.cuda.is_available(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if torch.cuda.get_device_capability() < (9, 0): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tv = torch.__version__.split("+")[0].split(".") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (int(tv[0]), int(tv[1])) < (2, 8): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cv = torch.version.cuda | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if cv is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cv_parts = cv.split(".") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (int(cv_parts[0]), int(cv_parts[1])) < (12, 8): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "qwen3next chunk_gated_delta_rule: using FlashQLA backend (flash_qla.chunk_gated_delta_rule); " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "set LIGHTLLM_DISABLE_FLASHQLA=1 to fall back to the FLA Triton kernels." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flash_qla.chunk_gated_delta_rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def chunk_gated_delta_rule_fwd( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| q: torch.Tensor, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -183,6 +216,22 @@ def chunk_gated_delta_rule( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| cu_seqlens=cu_seqlens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| flashqla_fn = _flashqla_chunk_gated_delta_rule() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if flashqla_fn is not None and not head_first: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return flashqla_fn( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| q=q.contiguous(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| k=k.contiguous(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| v=v.contiguous(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| g=g.contiguous(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| beta=beta.contiguous(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scale=scale, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initial_state=initial_state.contiguous() if initial_state is not None else None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| output_final_state=output_final_state, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cu_seqlens=cu_seqlens, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| head_first=head_first, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use_qk_l2norm_in_kernel=use_qk_l2norm_in_kernel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+221
to
+233
Contributor
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. If
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert q.dtype == k.dtype == v.dtype | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert q.dtype != torch.float32, "ChunkGatedDeltaRuleFunction does not support float32. Please use bfloat16." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert len(beta.shape) == 3, "beta must be of shape [B, T, H] if head_first=False, or [B, H, T] otherwise." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
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 version requirements for PyTorch (
2.8) and CUDA (12.8) appear to be typos, as these versions are either not yet released or do not exist (CUDA 12.8). This will cause the FlashQLA backend to be disabled on all current environments. Additionally, the parsing logic is fragile and may raiseIndexErrororValueErrordepending on the version string format (e.g., if it contains non-numeric suffixes likerc1).