Skip to content
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

[attn] fix device of tensors in attention #25

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

MengqingCao
Copy link
Contributor

What this PR does / why we need it?

Fix device of tensors created in AscendAttentionBackendImpl.

While specifying device to cards except card-0, there'll cause an device conflict because the tensors (such as attn_mask) will be put on card-0 by default.

This pr creates these tensors on the correct card corresponding to the input.

Does this PR introduce any user-facing change?

User could specify device with local rank by this pr, and a modify on vLLM is also needed, will related to this pr when created.

How was this patch tested?

This is tested by the following code locally. Will add a test case when the modify in vLLM is also completed.

from vllm import LLM, SamplingParams

prompts = [
    "Hello, my name is",
    "The president of the United States is",
    "The capital of France is",
    "The future of AI is",
]

# Create a sampling params object.
sampling_params = SamplingParams(max_tokens=100, temperature=0.0)
# Create an LLM.
llm = LLM(model="~/.cache/modelscope/hub/Qwen/Qwen2___5-7B-Instruct", device="npu:1")

# Generate texts from the prompts.
outputs = llm.generate(prompts, sampling_params)
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

Results

image

@MengqingCao
Copy link
Contributor Author

cc @ji-huazhong

Signed-off-by: MengqingCao <cmq0113@163.com>
@MengqingCao
Copy link
Contributor Author

related pr on vllm: vllm-project/vllm#13027

@wangxiyuan wangxiyuan merged commit 7006835 into vllm-project:main Feb 10, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants