Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: type object 'Trainer' has no attribute 'add_argparse_args' #19905

Closed
Park-yebin opened this issue May 24, 2024 · 1 comment
Closed
Labels
question Further information is requested ver: 2.0.x ver: 2.1.x working as intended Working as intended

Comments

@Park-yebin
Copy link

Park-yebin commented May 24, 2024

Bug description

When trying to run

parser = argparse.ArgumentParser()
parser = Trainer.add_argparse_args(parser)
args = parser.parse_args([])

AttributeError: type object 'Trainer' has no attribute 'add_argparse_args'
That error message appears.

What version are you seeing the problem on?

v2.0, v2.1, v2.2

How to reproduce the bug

import argparse
import pytorch_lightning
from pytorch_lightning.trainer import Trainer
from pytorch_lightning.callbacks import ModelCheckpoint, Callback, LearningRateMonitor

parser = argparse.ArgumentParser()
parser.add_argument(
        "--gpus",
        type=int,
        default=1,
        help="num of gpus to use",
)
parser = Trainer.add_argparse_args(parser)
args = parser.parse_args()
AttributeError: type object 'Trainer' has no attribute 'add_argparse_args'

#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow): Trainer
#- PyTorch Lightning Version (e.g., 1.5.0): 2.0.0
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 2.0): 2.0.1
#- Python version (e.g., 3.9): 3.8.8
#- OS (e.g., Linux): Linux
#- CUDA/cuDNN version: 12.0
#- GPU models and configuration:
#- How you installed Lightning(conda, pip, source): conda install pytorch-lightning=2.0.0 -c conda-forge
#- Running environment of LightningApp (e.g. local, cloud):

More info

When I first encountered the error, I thought it might be a version conflict issue between internal programs, so I installed 'pytorch_lightning' anew by referring to the link('https://lightning.ai/docs/pytorch/stable/versioning.html').
I finished reinstalling, but that didn't solve the problem. What's the problem?
(At first, I've installed ver 2.2 then, I convert to 2.0. For test I've done the same thing at ver 2.1)

@Park-yebin Park-yebin added bug Something isn't working needs triage Waiting to be triaged by maintainers labels May 24, 2024
@awaelchli
Copy link
Contributor

Hi
The method removed in 2.0, so the AttributeError is expected.
The change is documented in the migration guide.
In the release notes, we give some more details for the reason of the change (section "The brittle argument parsing utilities").

@awaelchli awaelchli closed this as not planned Won't fix, can't repro, duplicate, stale Jun 6, 2024
@awaelchli awaelchli added working as intended Working as intended question Further information is requested and removed needs triage Waiting to be triaged by maintainers bug Something isn't working labels Jun 6, 2024
weiji14 added a commit to weiji14/ctcorenet that referenced this issue Nov 1, 2024
Fix the following errors

- AttributeError: type object 'Trainer' has no attribute 'add_argparse_args' (need to change from Pytorch Lightning 1.0 to Lightning 2.0 style, see Lightning-AI/pytorch-lightning#19905)
- ValueError: Cannot find 8ef2e2d423b67b53ec8113fc71a9b968bb0f66e7 in https://github.com/mateuszbuda/brain-segmentation-pytorch (change to use v1.0 tag)
- AttributeError: module 'torchmetrics' has no attribute 'IoU' (renamed to JaccardIndex, see Lightning-AI/torchmetrics#662)

Also gitignoring __pycache__/ folder.
weiji14 added a commit to weiji14/ctcorenet that referenced this issue Nov 3, 2024
* 📝 Add installation instructions and update Binder link

Some more getting started instructions to install the package, and updated the quickstart button from Pangeo Binder to regular Binder.

* ⬆️ Bump pytorch and other dependencies

Upgrading pytorch, torchvision and other dependencies to newer versions in 2024. Simplified the conda environment.yml file to use conda-forge channel only and remove the md5 hash (put in the lock file instead). Not installing black and codecarbon as required dependencies anymore. Installing ONNX so model export will work.

* 👽 Update CTCoreUnet to handle newer pytorch* library versions

Fix the following errors

- AttributeError: type object 'Trainer' has no attribute 'add_argparse_args' (need to change from Pytorch Lightning 1.0 to Lightning 2.0 style, see Lightning-AI/pytorch-lightning#19905)
- ValueError: Cannot find 8ef2e2d423b67b53ec8113fc71a9b968bb0f66e7 in https://github.com/mateuszbuda/brain-segmentation-pytorch (change to use v1.0 tag)
- AttributeError: module 'torchmetrics' has no attribute 'IoU' (renamed to JaccardIndex, see Lightning-AI/torchmetrics#662)

Also gitignoring __pycache__/ folder.

* ⬆️ Bump setup-miniconda from 2.1.1 to 3.0.4 and other Actions

Bumps [conda-incubator/setup-miniconda](https://github.com/conda-incubator/setup-miniconda) from 2.2.0 to 3.0.4.
- [Release notes](https://github.com/conda-incubator/setup-miniconda/releases)
- [Changelog](https://github.com/conda-incubator/setup-miniconda/blob/main/CHANGELOG.md)
- [Commits](conda-incubator/setup-miniconda@v2.2.0...v3.0.4)

Also bumped actions/checkout from v2.3.4 to v4.2.2, and ubuntu from 20.04 to 24.04. Commented out `black` code quality check for now.

* 🛂 Remove sha256 hashsum in explicit lockfile

Getting this error on CI: `ParseError: Could not parse explicit URL: https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2#fe51de6107f9edc7aa4f786a70f4a883943bc9d39b3bb7307c04c41410990726`. Try without the sha256 hashsum suffix to see if setup-miniconda works.

* 🛂 Trust downloading UNet model from torch.hub.load

Assuming that mateuszbuda/brain-segmentation-pytorch is a trusted source to download the UNet model, so that Continuous Integration can work without a Y/N prompt.

* 🔇 Only log to tensorboard if activated

Fix `AttributeError: 'ExperimentWriter' object has no attribute 'add_scalar'` by gating the `self.logger.experiment.add_scalar` call behind an if-condition. Logging can be activated if tensorboard is installed, and the `--logger=True` flag is passed via the command-line.

* 🔍 Add teaser img of sediment core with IRD clasts to main README.md

Include a teaser image of a sediment core with Ice-Rafted Debris (IRD) clasts highlighted in red to the main README.md file. Also fixed a small typo.

* 📌 Use CUDA build of pytorch instead of CPU build

Re-created conda environment by running `CONDA_OVERRIDE_CUDA=12.6 conda env create --file=environment.yml --solver=libmamba` and re-locking with `conda list --explicit > environment-linux-64.lock`. Unsure why it's giving us CUDA 11.8 instead of CUDA 12, but oh well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested ver: 2.0.x ver: 2.1.x working as intended Working as intended
Projects
None yet
Development

No branches or pull requests

2 participants