-   Notifications  You must be signed in to change notification settings 
- Fork 5.9k
 [SOT] Non-break support for paddle.get_device #72004 
 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
  [SOT] Non-break support for paddle.get_device  #72004 
 Conversation
| 你的PR提交成功,感谢你对开源项目的贡献! | 
There was a problem hiding this 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 adds support for non-breakgraph execution of place.get_device_id by introducing a new PlaceVariable type and updating related dispatchers.
- Introduces PlaceVariable to handle get_device_id operations.
- Registers place_get_device_id within the dispatcher and updates import statements accordingly.
- Removes a redundant line in paddle/device/init.py to clean up duplicate formatting.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description | 
|---|---|
| python/paddle/jit/sot/opcode_translator/executor/variables/basic.py | Adds the PlaceVariable class and implements get_device_id logic. | 
| python/paddle/jit/sot/opcode_translator/executor/variables/init.py | Exports the new PlaceVariable. | 
| python/paddle/jit/sot/opcode_translator/executor/variable_dispatch.py | Registers place_get_device_id for PlaceVariable. | 
| python/paddle/jit/sot/opcode_translator/executor/dispatch_functions.py | Adds a stub for place_get_device_id. | 
| python/paddle/device/init.py | Removes a duplicate device string formatting line. | 
   python/paddle/jit/sot/opcode_translator/executor/variables/basic.py  Outdated   Show resolved Hide resolved  
 |  | ||
|  | ||
| def place_get_device_id(x): | ||
| pass | 
     Copilot AI  Mar 31, 2025  
 There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function 'place_get_device_id' is currently a stub (using 'pass'). If this function is meant to be implemented in this PR, consider raising a NotImplementedError or adding a TODO comment to clarify its intended behavior.
| pass | |
| raise NotImplementedError("place_get_device_id function is not yet implemented.") | 
…ic.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
place.get_device_idplace.get_device_id place.get_device_idpaddle.get_device There was a problem hiding this 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 adds non-break support for paddle.get_device by introducing a new PlaceVariable for device dispatching and by updating tests to verify that device switching triggers a rebuild of the graph.
- Added unit tests to validate the new device guard and expected behavior for different device types (cpu, gpu, xpu).
- Added a new PlaceVariable in the opcode translator to support get_device_id and get_device_type dispatch.
- Updated variable dispatch and removed duplicate assignment for IPUPlace in paddle.get_device.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description | 
|---|---|
| test/sot/test_sot_place.py | Added tests for device guard and ensuring graph rebuild after switching device | 
| python/paddle/jit/sot/opcode_translator/executor/variables/basic.py | Introduced PlaceVariable and updated import order to support new dispatch functions | 
| python/paddle/jit/sot/opcode_translator/executor/variables/init.py | Registered PlaceVariable for use in the translator | 
| python/paddle/jit/sot/opcode_translator/executor/variable_dispatch.py | Registered dispatcher functions for PlaceVariable operations | 
| python/paddle/jit/sot/opcode_translator/executor/dispatch_functions.py | Added stubs for place_get_device_id and place_get_device_type | 
| python/paddle/device/init.py | Removed a duplicate assignment in device string formatting | 
|  | ||
|  | ||
| def place_get_device_id(): | ||
| pass | 
     Copilot AI  Apr 1, 2025  
 There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function 'place_get_device_id' remains unimplemented. Add an appropriate implementation or provide a comment explaining why it is intentionally left as a stub.
| pass | |
| import paddle | |
| device = paddle.device.get_device() | |
| device_id = int(device.split(':')[-1]) if ':' in device else 0 | |
| return device_id | 
| def place_get_device_type(): | ||
| pass | 
     Copilot AI  Apr 1, 2025  
 There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function 'place_get_device_type' remains unimplemented. Add an appropriate implementation or provide a comment explaining why it is intentionally left as a stub.
| def place_get_device_type(): | |
| pass | |
| def place_get_device_type(place): | |
| if place.is_gpu_place(): | |
| return "GPU" | |
| elif place.is_cpu_place(): | |
| return "CPU" | |
| else: | |
| raise ValueError("Unsupported place type") | 
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
paddle.get_devicepaddle.get_device paddle.get_devicepaddle.get_device --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
PR Category
Execute Infrastructure
PR Types
Performance
Description
为
paddle.get_device添加非打断支持,模拟的函数只有CUDAPlace.get_device_id不支持,添加 dispatch 后可以确保无打断,且 guard 能正常工作,切换 place 能重新触发组网