Check if the devices of the input tensor are the same. Keep the device where each tensors is located the same as the first tensor. Copy data to the device of the first tensor if the device does not match. Args: *inputs: input args consisting of only PyT
(self, *inputs)
| 185 | inputs[0].device.EnableGraph(flag) |
| 186 | |
| 187 | def device_check(self, *inputs): |
| 188 | """ Check if the devices of the input tensor are the same. |
| 189 | |
| 190 | Keep the device where each tensors is located the same as the |
| 191 | first tensor. Copy data to the device of the first tensor if |
| 192 | the device does not match. |
| 193 | |
| 194 | Args: |
| 195 | *inputs: input args consisting of only PyTensors |
| 196 | """ |
| 197 | # disabled the graph to prevent buffering data transfer operator |
| 198 | x_device = inputs[0].device |
| 199 | prev_state = x_device.graph_enabled() |
| 200 | x_device.EnableGraph(False) |
| 201 | x_dev_id = x_device.id() |
| 202 | for var in inputs: |
| 203 | if var.device.id() != x_dev_id: |
| 204 | var.to_device(x_device) |
| 205 | x_device.EnableGraph(prev_state) |
| 206 | |
| 207 | def _has_layer_param(self, layer, names): |
| 208 | """ Determine whether names contains parameter names in the layer |