Skip to content

Conversation

@danghoangnhan
Copy link

Replaced np.where(temp.cpu().numpy() == True) with paddle.where(temp == True)
to maintain computation on the PaddlePaddle device (GPU/CPU) without converting to NumPy.
This avoids unnecessary data transfer between devices and keeps the operation within Paddle’s tensor graph.

@paddle-bot
Copy link

paddle-bot bot commented Nov 10, 2025

Thanks for your contribution!

@CLAassistant
Copy link

CLAassistant commented Nov 10, 2025

CLA assistant check
All committers have signed the CLA.

@paddle-bot paddle-bot bot added the contrib/contributor Contributor-related discussion or task. label Nov 10, 2025
@danghoangnhan danghoangnhan marked this pull request as draft November 13, 2025 07:44
@danghoangnhan danghoangnhan marked this pull request as ready for review November 13, 2025 13:33
@GreatV GreatV requested a review from Copilot November 25, 2025 10:35
Copilot finished reviewing on behalf of GreatV November 25, 2025 10:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR attempts to optimize tensor operations by replacing np.where() with paddle.where() to avoid unnecessary device transfers between CPU and GPU. However, the implementation contains a critical bug due to API differences between NumPy and PaddlePaddle.

Key Changes:

  • Modified forward_test method in rec_parseq_head.py to use paddle.where() instead of np.where() with CPU transfer

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +368 to 369
posi = paddle.where(temp == True)
query_mask[posi] = 0
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

The replacement of np.where with paddle.where is incorrect. When called with only a condition argument, np.where(condition) returns a tuple of arrays (one per dimension), while paddle.where(condition) returns a single tensor with shape [N, rank]. This breaks the indexing operation on line 369 query_mask[posi] = 0. Consider using paddle.nonzero(temp).T which returns indices in a format compatible with tuple-style indexing, or use paddle.nonzero(temp) and adjust the indexing accordingly.

Suggested change
posi = paddle.where(temp == True)
query_mask[posi] = 0
posi = paddle.nonzero(temp).T
query_mask[tuple(posi)] = 0

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contrib/contributor Contributor-related discussion or task. contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants