From 40b27d818ce6a677c0e6073b7e351ee130aed532 Mon Sep 17 00:00:00 2001 From: Mahmoud Ashraf Date: Wed, 25 Oct 2023 22:25:07 +0300 Subject: [PATCH] fix: handle multiple GPUs in paddle backend `to_device` --- ivy/functional/backends/paddle/device.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ivy/functional/backends/paddle/device.py b/ivy/functional/backends/paddle/device.py index 9360fa702f1cd..3d732ec9ee9af 100644 --- a/ivy/functional/backends/paddle/device.py +++ b/ivy/functional/backends/paddle/device.py @@ -34,7 +34,11 @@ def to_device( device = as_native_dev(device) if device.is_cpu_place() and not x.place.is_cpu_place(): return x.cpu() - elif device.is_gpu_place() and not x.place.is_gpu_place(): + elif (device.is_gpu_place() and not x.place.is_gpu_place()) or ( + x.place.is_gpu_place() + and device.is_gpu_place() + and x.gpu_device_id() != device.gpu_device_id() + ): return x.cuda(device.gpu_device_id()) else: return x