-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Implements dual-chunk-flash-attn backend for dual chunk attention with sparse attention support #11844
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
Merged
Merged
Implements dual-chunk-flash-attn backend for dual chunk attention with sparse attention support #11844
Changes from all commits
Commits
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import os | ||
from urllib.request import urlopen | ||
|
||
from vllm import LLM, SamplingParams | ||
|
||
os.environ["VLLM_ATTENTION_BACKEND"] = "DUAL_CHUNK_FLASH_ATTN" | ||
os.environ["VLLM_ALLOW_LONG_MAX_MODEL_LEN"] = "1" | ||
|
||
|
||
def load_prompt() -> str: | ||
# Test cases with various lengths can be found at: | ||
# | ||
# https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/64k.txt | ||
# https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/200k.txt | ||
# https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/600k.txt | ||
# https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen2.5-1M/test-data/1m.txt | ||
|
||
with urlopen( | ||
"https://qianwen-res.oss-cn-beijing.aliyuncs.com" | ||
"/Qwen2.5-1M/test-data/600k.txt", | ||
timeout=5) as response: | ||
prompt = response.read().decode('utf-8') | ||
return prompt | ||
|
||
|
||
# Processing the prompt. | ||
def process_requests(llm: LLM, prompts: list[str]) -> None: | ||
# Create a sampling params object. | ||
sampling_params = SamplingParams( | ||
temperature=0.7, | ||
top_p=0.8, | ||
top_k=20, | ||
repetition_penalty=1.05, | ||
detokenize=True, | ||
max_tokens=256, | ||
) | ||
# Generate texts from the prompts. | ||
outputs = llm.generate(prompts, sampling_params) | ||
# Print the outputs. | ||
for output in outputs: | ||
prompt_token_ids = output.prompt_token_ids | ||
generated_text = output.outputs[0].text | ||
print(f"Prompt length: {len(prompt_token_ids)}, " | ||
f"Generated text: {generated_text!r}") | ||
|
||
|
||
# Create an LLM. | ||
def initialize_engine() -> LLM: | ||
llm = LLM(model="Qwen/Qwen2.5-7B-Instruct-1M", | ||
max_model_len=1048576, | ||
tensor_parallel_size=4, | ||
enforce_eager=True, | ||
enable_chunked_prefill=True, | ||
max_num_batched_tokens=131072) | ||
return llm | ||
|
||
|
||
def main(): | ||
llm = initialize_engine() | ||
prompt = load_prompt() | ||
process_requests(llm, [prompt]) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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.
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.
Could you add some comments describing what the functions in this file are doing? Comments describing what blocks of code within
convert_vertical_slash_indexes_kernel
would be helpful as well