[XPU] Fix FLAGS_enable_api_kernel_fallback does not take effect in XPU
#76635
+38
−1
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.
PR Category
User Experience
PR Types
Bug fixes
Description
Pcard-75624
修复
FLAGS_enable_api_kernel_fallback变量在XPU设备上不起效的问题,具体表现为:设置为false或0后,仍然会fallback到CPU上,核心原因在于原先的分支逻辑错误地使用了||,这会导致一旦出现kernel不支持,一定会进入fallback分支。This pull request improves the handling and testing of the
FLAGS_enable_api_kernel_fallbackflag for XPU kernel selection in PaddlePaddle. The main changes include a bug fix to the flag logic in the kernel factory and the addition of a new unit test to verify the flag's behavior.Kernel fallback flag logic:
KernelFactory::SelectKernelOrThrowErrorto ensure that kernel fallback is only attempted whenFLAGS_enable_api_kernel_fallbackis enabled and the kernel is unsupported on XPU. This prevents unintended fallback behavior.Testing:
test/xpu/test_fallback_flag.pythat verifies disablingFLAGS_enable_api_kernel_fallbackraises a runtime error when running an unsupported operation, and restores the flag to its previous state after the test.