Skip to content

Conversation

timminator
Copy link
Contributor

Adds a GPU compatibility check.
If the specified device is of type "GPU" we check if such a device is actually available before accepting it as the device to be used. If a usable GPU is not available we fall back to using the CPU.

Fixes PaddlePaddle/PaddleOCR#15656

Copy link

paddle-bot bot commented Aug 24, 2025

Thanks for your contribution!

@paddle-bot paddle-bot bot added the contributor External developers label Aug 24, 2025
@timminator timminator changed the base branch from release/3.2 to develop August 24, 2025 22:08
@timminator timminator changed the title GPU compatibility check before accepting as the device to be used GPU compatibility check before accepting GPU as the device to be used Aug 24, 2025
Copy link
Member

@Bobholamovic Bobholamovic left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! The logic you implemented looks mostly good to me. However, I would suggest introducing a global flag (an environment variable) to control the behavior: whether to reject an invalid device (e.g., by raising a RuntimeError/ValueError) or to fall back to the CPU. This is because in some cases—for example, during automated testing—the rejection strategy is more explicit and avoids unexpected results that the fallback strategy might cause. You can define the flag here.

@timminator timminator force-pushed the gpu-compatibility-check branch from 4b4f41a to 6776a20 Compare August 25, 2025 14:15
@timminator
Copy link
Contributor Author

Thanks for the review! I've added such a flag now. By default it will fall back to the CPU but this can be disabled now by setting the new environment variable.

Copy link
Member

@Bobholamovic Bobholamovic left a comment

Choose a reason for hiding this comment

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

LGTM

@Bobholamovic Bobholamovic merged commit 30621ce into PaddlePaddle:develop Aug 25, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No input validation for specified device

2 participants