Skip to content

self.device is not correct during setupΒ #13108

@carmocca

Description

@carmocca

πŸ› Bug

To Reproduce

import os

from pytorch_lightning import Trainer
from pytorch_lightning.demos.boring_classes import BoringModel


class BugReportModel(BoringModel):
    def setup(self, stage=None):
        # current workaround
        assert self.trainer.strategy.root_device.type == "cuda"
        # error! it is on cpu
        assert self.device.type == "cuda"


def run():
    model = BugReportModel()
    trainer = Trainer(
        default_root_dir=os.getcwd(),
        fast_dev_run=True,
        accelerator="gpu",
        devices=1,
    )
    trainer.fit(model)


if __name__ == "__main__":
    run()

Expected behavior

lightning_module.device and strategy.device point to the same device

Additional context

Reported in Slack by Joshua Chia

cc @tchaton @rohitgr7 @justusschock @kaushikb11 @awaelchli @akihironitta

Metadata

Metadata

Assignees

Labels

accelerator: cudaCompute Unified Device Architecture GPUbugSomething isn't workinghelp wantedOpen to be worked on

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions