Lightning-AI / Lightning-AI/pytorch-lightning

Using `pyg` sampler causes lightning to skip validation step

Open
#18,058 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

3rd party bug help wanted ver: 2.1.x
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

Bug description

I am trying to use the dynamic batch sampler from torch_geometric (link) for my regression task on graphs. For some reason, using the batch sampler as follows skips the validation step. I think this is linked to this issue. This is how I am setting up my batch sampler,

from torch_geometric.loader import DataLoader
import pytorch_lightning as pl

class BaseDataModule(pl.LightningModule):
    # usual init, setup, ....

    def train_dataloader(self):
        batch_sampler = <instantiate_dynamic_batch_sampler>

        return DataLoader(
            self.train_dataset,
            batch_size=batch_size,
            shuffle=shuffle,
            batch_sampler=batch_sampler,
            **self.kwargs,
        )

    def val_dataloader(self):
        """Creates val dataloader"""
        batch_sampler = <instantiate_dynamic_batch_sampler>

        return DataLoader(
            self.val_dataset,
            batch_size=batch_size,
            shuffle=shuffle,
            batch_sampler=batch_sampler,
            **self.kwargs,
        )
What version are you seeing the problem on?

version 2.0.4

How to reproduce the bug

No response

Error messages and logs
# Error messages and logs here please
Environment
Current environment
#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow):
#- PyTorch Lightning Version (e.g., 1.5.0):
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 2.0):
#- Python version (e.g., 3.9):
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source):
#- Running environment of LightningApp (e.g. local, cloud):
More info

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report names the train_dataloader and val_dataloader entry points but provides no reproduction, test, logs, or environment details. Start by creating a minimal case around these entry points using the torch_geometric dynamic batch sampler and compare validation behavior. Done means a regression test demonstrates that validation runs when this sampler is used.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.