Verified Solution[pytorch/pytorch] Feature Request: Extend device checks to support privateuse1 for shared at::native operators logic
Sponsored Content
### ROOT CAUSE
The issue arises because the device checks in the `at::native` operators (core PyTorch functions) do not account for the `privateuse1` device type, which is used for special GPU devices. Currently, the device validation assumes standard integer device indices, but `privateuse1` requires special handling to avoid validation errors.
### CODE FIX
```cpp
// In torch/csrc/autograd/functions.cpp, modify the device validation in at::native operators
// Example for aten::add: replace the device check with the following logic
auto self_device = self.device();
auto other_device = other.device();
// Check device type and index
if (self_device.type() != other_device.type()) {
// Handle device type mismatch
return at::autograd::_VariableFunctionFlagsGuard::allowUnderflow(
[&]() -> at::Tensor {
return at::add(self, other, out_opt);
}
);
}
if (self_device.type() == DeviceType::CUDA) {
// Allow privateuse1 device by checking for its special code point
if (self_device.index() == DeviceIndex::PRIVATEUSE1) {
// Proceed with the operation, bypassing standard validation
return at::autograd::_VariableFunctionFlagsGuard::allowUnderflow(
[&]() -> at::Tensor {
return at::add(self, other, out_opt);
}
);
}
}
// Standard device validation for other devices
if (self_device != other_device) {
// Raise error for unsupported device combinations
throw std::runtime_error("aten::add: Expected self and other to have same device");
}
```
This fix extends device checks to explicitly handle `privateuse1` devices by adding a conditional branch that bypasses standard validation for these special devices.
Deploy on DigitalOcean ($200 Credit)
Related Fixes
[docker/cli] Support accessing sandbox-internal services from the host machine
[StackOverflow/kubernetes] Readiness probe failing for pod
[StackOverflow/go] Optional query parameter in http signature of proto rpc is not mapped as expected