Skip to content

Keras 3 may not work with PyTorch DirectML #21228

Open
@TaiXeflar

Description

@TaiXeflar

I think this might be a tech issue so I opened issue from disscutions to here.

Issue description:
My test on Keras 3 may cannot set selected device correctly with DirectML based PyTorch backend. I looked #21190 and still can't find some useful anwers.

Backgrounds:
I have a Windows 11 Machine, contains 2 cards with NVIDIA GeForce RTX 4070ti Super and AMD Radeon RX 7800XT respectively.
Then I deployed a Python 3.11.9 env installed torch-directml, by using DirectML backend to use PyTorch. In PyTorch we can manually use .to(device) to set GPU device, and can do check like this:

import torch_directml

# List all available DML devices
device_count = torch_directml.device_count()
print(f"Available DirectML devices: {device_count}")

# Loop over devices and print info
for i in range(device_count):
    dml_device = torch_directml.device(i)
    print(f"Device {i}: {dml_device}")

# Select device 1 (example)
dml = torch_directml.device(1)
Available DirectML devices: 2
Device 0: privateuseone:0
Device 1: privateuseone:1

From the above codes and the result, we can know that device 1 is the AMD card.
How can I manage/add preprocess "on DirectML device select" in Keras? If we just do nothing, the model will be run on CPU only.

Hardware and Software/Environ:

Intel Xeon W-3175X
NVIDIA GeForce RTX 4070ti Super
AMD Radeon RX 7800XT

Windows 11 24H2
Python 3.13.2 ---> PyTorch 2.6.0+cu126, Keras 3            # The NVIDIA CUDA one
Python 3.11.9 ---> PyTorch-DirectML, Keras 3                 # The DirectML for AMD card environment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions