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

Trainer with logger=False still produces logs #20467

Closed
ValerianRey opened this issue Dec 4, 2024 · 2 comments
Closed

Trainer with logger=False still produces logs #20467

ValerianRey opened this issue Dec 4, 2024 · 2 comments
Labels

Comments

@ValerianRey
Copy link

ValerianRey commented Dec 4, 2024

Bug description

Hi! I need to maintain a test of a usage example of my library torchjd, showing how it can be combined with PyTorch Lightning. To keep my test outputs clean, I would like to disable all logs from PyTorch Lightning, but I can't manage to do so.

Even when passing logger=False to the Trainer, and when manually disabling logs, I can't get rid of the INFO: GPU available: [...] logs. I'm posting this as a bug since I think that passing logger=False is supposed to do precisely what I want, but maybe since a recent release it stopped working?

I only found outdated solutions on stackoverflow and in other issues. Thanks in advance for the help! :)

What version are you seeing the problem on?

v2.4

How to reproduce the bug

This reproducer is the first 4 steps of the tutorial, with 2 changes:

  • The first 5 lines that try to disable logging manually
  • The extra parameters enable_checkpointing=False, logger=False, enable_model_summary=False, enable_progress_bar=False provided to the Trainer
    import logging
    logging.getLogger("lightning_fabric").propagate = False
    logging.getLogger("lightning_fabric").setLevel = False
    logging.getLogger("pytorch_lightning").propagate = False
    logging.getLogger("pytorch_lightning").setLevel = False

    import os
    from torch import optim, nn, utils, Tensor
    from torchvision.datasets import MNIST
    from torchvision.transforms import ToTensor
    import lightning as L

    # define any number of nn.Modules (or use your current ones)
    encoder = nn.Sequential(nn.Linear(28 * 28, 64), nn.ReLU(), nn.Linear(64, 3))
    decoder = nn.Sequential(nn.Linear(3, 64), nn.ReLU(), nn.Linear(64, 28 * 28))

    # define the LightningModule
    class LitAutoEncoder(L.LightningModule):
        def __init__(self, encoder, decoder):
            super().__init__()
            self.encoder = encoder
            self.decoder = decoder

        def training_step(self, batch, batch_idx):
            # training_step defines the train loop.
            # it is independent of forward
            x, _ = batch
            x = x.view(x.size(0), -1)
            z = self.encoder(x)
            x_hat = self.decoder(z)
            loss = nn.functional.mse_loss(x_hat, x)
            # Logging to TensorBoard (if installed) by default
            self.log("train_loss", loss)
            return loss

        def configure_optimizers(self):
            optimizer = optim.Adam(self.parameters(), lr=1e-3)
            return optimizer

    # init the autoencoder
    autoencoder = LitAutoEncoder(encoder, decoder)

    # setup data
    dataset = MNIST(os.getcwd(), download=True, transform=ToTensor())
    train_loader = utils.data.DataLoader(dataset)

    # train the model (hint: here are some helpful Trainer arguments for rapid idea iteration)
    trainer = L.Trainer(limit_train_batches=100, max_epochs=1, enable_checkpointing=False, logger=False, enable_model_summary=False, enable_progress_bar=False)
    trainer.fit(model=autoencoder, train_dataloaders=train_loader)

Error messages and logs

Output (in red in my terminal):

INFO: GPU available: True (cuda), used: True
INFO: TPU available: False, using: 0 TPU cores
INFO: HPU available: False, using: 0 HPUs
INFO: LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
INFO: `Trainer.fit` stopped: `max_epochs=1` reached.

Environment

Current environment
  • CUDA:
    - GPU:
    - NVIDIA GeForce GTX 1080
    - available: True
    - version: 12.4
  • Lightning:
    - lightning: 2.4.0
    - lightning-utilities: 0.11.8
    - pytorch-lightning: 2.4.0
    - torch: 2.5.1
    - torchjd: 0.2.2
    - torchmetrics: 1.6.0
    - torchvision: 0.20.1
  • Packages:
    - aiohappyeyeballs: 2.4.3
    - aiohttp: 3.11.2
    - aiosignal: 1.3.1
    - alabaster: 0.7.16
    - attrs: 24.2.0
    - autocommand: 2.2.2
    - babel: 2.16.0
    - backports.tarfile: 1.2.0
    - beautifulsoup4: 4.12.3
    - blinker: 1.9.0
    - certifi: 2024.8.30
    - cfgv: 3.4.0
    - charset-normalizer: 3.4.0
    - clarabel: 0.9.0
    - click: 8.1.7
    - coverage: 7.6.7
    - cvxpy: 1.6.0
    - dash: 2.18.2
    - dash-core-components: 2.0.0
    - dash-html-components: 2.0.0
    - dash-table: 5.0.0
    - distlib: 0.3.9
    - docutils: 0.21.2
    - ecos: 2.0.14
    - filelock: 3.16.1
    - flask: 3.0.3
    - frozenlist: 1.5.0
    - fsspec: 2024.10.0
    - furo: 2024.1.29
    - identify: 2.6.2
    - idna: 3.10
    - imagesize: 1.4.1
    - importlib-metadata: 8.5.0
    - inflect: 7.3.1
    - iniconfig: 2.0.0
    - itsdangerous: 2.2.0
    - jaraco.collections: 5.1.0
    - jaraco.context: 5.3.0
    - jaraco.functools: 4.0.1
    - jaraco.text: 3.12.1
    - jinja2: 3.1.4
    - kaleido: 0.2.1
    - lightning: 2.4.0
    - lightning-utilities: 0.11.8
    - markdown-it-py: 3.0.0
    - markupsafe: 3.0.2
    - mdit-py-plugins: 0.4.2
    - mdurl: 0.1.2
    - more-itertools: 10.3.0
    - mpmath: 1.3.0
    - multidict: 6.1.0
    - myst-parser: 4.0.0
    - nest-asyncio: 1.6.0
    - networkx: 3.4.2
    - nodeenv: 1.9.1
    - numpy: 2.1.3
    - nvidia-cublas-cu12: 12.4.5.8
    - nvidia-cuda-cupti-cu12: 12.4.127
    - nvidia-cuda-nvrtc-cu12: 12.4.127
    - nvidia-cuda-runtime-cu12: 12.4.127
    - nvidia-cudnn-cu12: 9.1.0.70
    - nvidia-cufft-cu12: 11.2.1.3
    - nvidia-curand-cu12: 10.3.5.147
    - nvidia-cusolver-cu12: 11.6.1.9
    - nvidia-cusparse-cu12: 12.3.1.170
    - nvidia-nccl-cu12: 2.21.5
    - nvidia-nvjitlink-cu12: 12.4.127
    - nvidia-nvtx-cu12: 12.4.127
    - osqp: 0.6.7.post3
    - packaging: 24.2
    - pillow: 11.0.0
    - platformdirs: 4.3.6
    - plotly: 5.24.1
    - pluggy: 1.5.0
    - pre-commit: 4.0.1
    - propcache: 0.2.0
    - pygments: 2.18.0
    - pytest: 8.3.3
    - pytest-cov: 6.0.0
    - pytorch-lightning: 2.4.0
    - pyyaml: 6.0.2
    - qdldl: 0.1.7.post4
    - qpsolvers: 4.4.0
    - quadprog: 0.1.13
    - requests: 2.32.3
    - retrying: 1.3.4
    - scipy: 1.14.1
    - scs: 3.2.7
    - setuptools: 75.6.0
    - six: 1.16.0
    - snowballstemmer: 2.2.0
    - soupsieve: 2.6
    - sphinx: 7.4.7
    - sphinx-autodoc-typehints: 2.3.0
    - sphinx-basic-ng: 1.0.0b2
    - sphinx-design: 0.6.1
    - sphinxcontrib-applehelp: 2.0.0
    - sphinxcontrib-devhelp: 2.0.0
    - sphinxcontrib-htmlhelp: 2.1.0
    - sphinxcontrib-jsmath: 1.0.1
    - sphinxcontrib-qthelp: 2.0.0
    - sphinxcontrib-serializinghtml: 2.0.0
    - sympy: 1.13.1
    - tenacity: 9.0.0
    - tomli: 2.1.0
    - torch: 2.5.1
    - torchjd: 0.2.2
    - torchmetrics: 1.6.0
    - torchvision: 0.20.1
    - tqdm: 4.67.0
    - triton: 3.1.0
    - typeguard: 4.3.0
    - typing-extensions: 4.12.2
    - urllib3: 2.2.3
    - virtualenv: 20.27.1
    - werkzeug: 3.0.6
    - wheel: 0.43.0
    - yarl: 1.17.1
    - zipp: 3.21.0
  • System:
    - OS: Linux
    - architecture:
    - 64bit
    - ELF
    - processor: x86_64
    - python: 3.12.3
    - release: 5.15.0-126-generic
    - version: tensorboarX to tensorboardX #136~20.04.1-Ubuntu SMP Thu Nov 14 16:38:05 UTC 2024

More info

No response

@ValerianRey ValerianRey added bug Something isn't working needs triage Waiting to be triaged by maintainers labels Dec 4, 2024
@tshu-w
Copy link
Contributor

tshu-w commented Dec 5, 2024

As documented, the logger parameter in Trainer is specifically for controlling experiment tracking loggers (like Tensorboard), not Python's logging system.

For Python logging messages:

  1. To disable INFO level logs, use Python's logging:
import logging
logging.disable(logging.INFO)
  1. For warnings, please refer to the documentation on managing warnings:
    https://lightning.ai/docs/pytorch/stable/advanced/warnings.html

The logger=False parameter is working as intended - it only controls experiment tracking loggers, not python logging.

@lantiga lantiga added working as intended Working as intended and removed bug Something isn't working needs triage Waiting to be triaged by maintainers labels Dec 5, 2024
@ValerianRey
Copy link
Author

Thanks, your solution works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants