Skip to content

[Bugfix][MM] Move grid_thw tensor to cpu before directly converting to numpy#29770

Closed
shen-shanshan wants to merge 1 commit intovllm-project:mainfrom
shen-shanshan:bugfix
Closed

[Bugfix][MM] Move grid_thw tensor to cpu before directly converting to numpy#29770
shen-shanshan wants to merge 1 commit intovllm-project:mainfrom
shen-shanshan:bugfix

Conversation

@shen-shanshan
Copy link
Copy Markdown
Contributor

@shen-shanshan shen-shanshan commented Dec 1, 2025

Purpose

When grid_thw in ViT forward is a tensor, it should be moved to cpu before directly converting to numpy, otherwise there could be error like:

TypeError: can't convert npu:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

Test Plan

Test Result


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Signed-off-by: shen-shanshan <467638484@qq.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@mergify mergify bot added the qwen Related to Qwen models label Dec 1, 2025
@shen-shanshan shen-shanshan changed the title [Bugfix] Move tensor to cpu before directly converting to numpy [Bugfix][MM] Move grid_thw tensor to cpu before directly converting to numpy Dec 1, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes a TypeError that occurs when converting a tensor to a NumPy array on a non-CPU device. The change introduces a .to("cpu") call to move the grid_thw tensor to the CPU before the conversion, which is the proper way to handle this. The fix is targeted and effective. I have no further comments.

@Isotr0py Isotr0py enabled auto-merge (squash) December 1, 2025 06:35
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Dec 1, 2025
@lgeiger
Copy link
Copy Markdown
Contributor

lgeiger commented Dec 1, 2025

I'm a bit confused where this error is coming from. Shouldn't #28168 prevent grid_thw from being moved to the GPU in the first place?
@shen-shanshan do you mind sharing a reproduction in where you are seeing this issue pop up?

@shen-shanshan
Copy link
Copy Markdown
Contributor Author

I'm a bit confused where this error is coming from. Shouldn't #28168 prevent grid_thw from being moved to the GPU in the first place? @shen-shanshan do you mind sharing a reproduction in where you are seeing this issue pop up?

After discussing with @DarkLight1337 , this error is because the model_runner in vllm-ascend didn't implement multimodal_cpu_fields, which has defined what tensor should be moved to cpu for different multi-modal models. I will solve this problem just in vllm-ascend, thanks for reviewing.

auto-merge was automatically disabled December 1, 2025 15:13

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

qwen Related to Qwen models ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants