Skip to content

how to use find_usable_cuda_devices in lightning cli config.yaml? #18622

Discussion options

You must be logged in to vote

Unfortunately that is not supported. Though, you could do the following workaround. First subclass the trainer:

import re
from lightning.fabric.accelerators import find_usable_cuda_devices

class CustomTrainer(Trainer):
    def __init__(self, *args, **kwargs):
        devices = kwargs.get("devices")
        if (
            isinstance(devices, str)
            and re.match("^find_usable_cuda_devices\([0-9]*\)$", devices)
        ):
            kwargs["devices"] = eval(devices)
        super().__init__(*args, **kwargs)

Then provide trainer_class=CustomTrainer when instantiating the LightningCLI class. In the config.yaml then it could be written as devices: find_usable_cuda_devices(1).

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Jackiexiao
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants