Skip to content

DataLoader wrapping, re-instantiation and patching  #10329

@awaelchli

Description

@awaelchli

🐛 Bug

Recent changes to the Lite DataLoader in #10279 have not been properly reviewed and tested. Several clean ups need to be done and better tests need to be written.

The following issue exists:

To Reproduce

def test_setup_custom_dataloaders_new():

    class DataLoaderSubclass1(DataLoader):
        def __init__(self, attribute1, *args, **kwargs):
            # UNCOMMENT THE LINE BELOW, NO DIFFERENCE (EXPECTED)
            # self.attribute1 = attribute1
            super().__init__(*args, **kwargs)

    class DataLoaderSubclass2(DataLoaderSubclass1):
        def __init__(self, attribute1, attribute2, *args, **kwargs):
            # UNCOMMENT THE LINE BELOW, TEST PASSES
            # self.attribute2 = attribute2
            super().__init__(attribute1, *args, **kwargs)

    class LiteWithCustomDataLoader(LightningLite):
        def run(self):
            dataloader = DataLoaderSubclass2("attribute1", "attribute2", dataset=range(4), batch_size=2)
            lite_dataloader = self.setup_dataloaders(dataloader)
            
            # THIS ASSERTION PASSES
            assert lite_dataloader._dataloader.attribute1 == "attribute1"
            
            # THIS ASSERTION FAILS
            assert lite_dataloader._dataloader.attribute2 == "attribute2"

    LiteWithCustomDataLoader().run()

Expected behavior

According to the changes in the PR #10279, this is supposed to work and was the main motivation of it. But it does not because the tests were insufficient. This issue was found by me in #10297 while trying to clean up the code.

Environment

Lightning v1.5.0!

cc @tchaton @rohitgr7 @carmocca @justusschock @awaelchli

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfabriclightning.fabric.Fabrichelp wantedOpen to be worked onpriority: 2Low priority taskwon't fixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions