Skip to content

auto_scale_batch_size fails with datamodule in pl==1.2.*, succeeds in pl==1.1.8 #6335

@colllin

Description

@colllin

🐛 Bug

Running trainer = pl.Trainer(auto_scale_batch_size=True); trainer.tune(model, datamodule=dm) succeeds in pl==1.1.8, but fails in pl==1.2.* (tested both 1.2.0 and 1.2.1) with error:

Traceback (most recent call last):
  File "train.py", line 42, in <module>
    trainer.tune(model, datamodule=dm)
  File "/home/ubuntu/.local/share/virtualenvs/__project__/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1062, in tune
    self.tuner.tune(model, train_dataloader, val_dataloaders, datamodule)
  File "/home/ubuntu/.local/share/virtualenvs/__project__/lib/python3.8/site-packages/pytorch_lightning/tuner/tuning.py", line 46, in tune
    self.scale_batch_size(
  File "/home/ubuntu/.local/share/virtualenvs/__project__/lib/python3.8/site-packages/pytorch_lightning/tuner/tuning.py", line 104, in scale_batch_size
    return scale_batch_size(
  File "/home/ubuntu/.local/share/virtualenvs/__project__/lib/python3.8/site-packages/pytorch_lightning/tuner/batch_size_scaling.py", line 79, in scale_batch_size
    raise MisconfigurationException(f'Field {batch_arg_name} not found in both `model` and `model.hparams`')
pytorch_lightning.utilities.exceptions.MisconfigurationException: Field batch_size not found in both `model` and `model.hparams` 

Please reproduce using the BoringModel

https://colab.research.google.com/drive/1vgPLCwLg7uACtb3fxVp-t-__NtZ3onsD?usp=sharing

Expected behavior

Prior to pl==1.2.0, it successfully detected and tuned the dm.batch_size property.

Environment

  • CUDA:
    • GPU:
      • Tesla T4
    • available: True
    • version: 10.1
  • Packages:
    • numpy: 1.19.5
    • pyTorch_debug: False
    • pyTorch_version: 1.7.1+cu101
    • pytorch-lightning: 1.2.1
    • tqdm: 4.41.1
  • System:
    • OS: Linux
    • architecture:
      • 64bit
    • processor: x86_64
    • python: 3.7.10
    • version: Proposal for help #1 SMP Thu Jul 23 08:00:38 PDT 2020

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedOpen to be worked onpriority: 1Medium priority tasktuner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions