Lightning-AI / Lightning-AI/pytorch-lightning

Log to remote FS azure fails when LightningModule uses the `self.log` method

Open
#18,445 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug logger logging ver: 2.1.x
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

### Bug description

Hi all! While trying to log to a remote file system, specifically in Azure, I found that when my `LightningModule` uses the `self.log` method it fails at the end of the first epoch. Removing the `TensorBoard` logger, this is where the error seemed to be generated from, also did not help as it fails to save the checkpoint of the model.

Strangely, when the `LightningModule` does not use the `self.log`, it works perfectly (create files, saves config, tfevent and chackpoints) of when the tensorboard package is not installed.

It would be great if the `self.log` did not run though tensorboard if I haven't include it in the trainer loggers.

The following, for example, works as expected (for the version that is not, please see bellow):
```python3
# main.py
"""
Execute:
>>> export FSSPEC_ABFS='{"anon": false}'
>>> python main.py
"""
# pip install pytorch_lightning adlfs
# main.py
import pytorch_lightning as pl
from pytorch_lightning.demos import boring_classes

OUTPUT_DIR = "az://@.blob.core.windows.net/tmp/"

class TestModel(boring_classes.BoringModel):
def training_step(self, batch, batch_idx):
loss = self.step(batch)
self.log("train/StepLoss", loss, prog_bar=True) # <-- this is the line that causes the issue
return {"loss": loss}

model = TestModel()
trainer = pl.Trainer(
max_epochs=10,
default_root_dir=OUTPUT_DIR,
)
trainer.fit(model)
```

### What version are you seeing the problem on?

master

### How to reproduce the bug
```python3
# pip install pytorch_lightning adlfs tensorboard
# main.py
import pytorch_lightning as pl
from pytorch_lightning.demos import boring_classes

OUTPUT_DIR = "az://@.blob.core.windows.net/tmp/"

class TestModel(boring_classes.BoringModel):
def training_step(self, batch, batch_idx):
loss = self.step(batch)
self.log("train/StepLoss", loss, prog_bar=True) # <-- this is the line that causes the issue
return {"loss": loss}

model = TestModel()
trainer = pl.Trainer(
max_epochs=10,
default_root_dir=OUTPUT_DIR,
)
trainer.fit(model)
```

On terminal, execute
```sh
$ export FSSPEC_ABFS='{"anon": false}'
$ python main.py
```

### Error messages and logs

```sh
azure.core.exceptions.ResourceExistsError: The blob type is invalid for this operation.
```

### Environment

Current environment

* CUDA:
- GPU: None
- available: False
- version: None
* Lightning:
- lightning: 2.1.0rc0
- lightning-cloud: 0.5.37
- lightning-utilities: 0.9.0
- pytorch-lightning: 2.0.7
- torch: 2.0.1
- torchmetrics: 1.1.1
* Packages:
- absl-py: 1.4.0
- adlfs: 2023.8.0
- aiohttp: 3.8.5
- aiosignal: 1.3.1
- annotated-types: 0.5.0
- anyio: 4.0.0
- arrow: 1.2.3
- async-timeout: 4.0.3
- attrs: 23.1.0
- azure-core: 1.29.3
- azure-datalake-store: 0.0.53
- azure-identity: 1.12.0
- azure-storage-blob: 12.17.0
- backoff: 2.2.1
- beautifulsoup4: 4.12.2
- blessed: 1.20.0
- bs4: 0.0.1
- cachetools: 5.3.1
- certifi: 2023.7.22
- cffi: 1.15.1
- charset-normalizer: 3.2.0
- click: 8.1.6
- croniter: 1.4.1
- cryptography: 41.0.3
- dateutils: 0.6.12
- deepdiff: 6.3.1
- docstring-parser: 0.15
- fastapi: 0.99.1
- filelock: 3.12.3
- frozenlist: 1.4.0
- fsspec: 2023.6.0
- google-auth: 2.22.0
- google-auth-oauthlib: 1.0.0
- grpcio: 1.57.0
- h11: 0.14.0
- idna: 3.4
- importlib-resources: 6.0.1
- iniconfig: 2.0.0
- inquirer: 3.1.3
- isodate: 0.6.1
- itsdangerous: 2.1.2
- jinja2: 3.1.2
- jsonargparse: 4.24.0
- lightning: 2.1.0rc0
- lightning-cloud: 0.5.37
- lightning-utilities: 0.9.0
- markdown: 3.4.4
- markdown-it-py: 3.0.0
- markupsafe: 2.1.3
- mdurl: 0.1.2
- mpmath: 1.3.0
- msal: 1.23.0
- msal-extensions: 1.0.0
- multidict: 6.0.4
- networkx: 3.1
- numpy: 1.25.2
- oauthlib: 3.2.2
- ordered-set: 4.1.0
- packaging: 23.1
- pip: 23.2.1
- pluggy: 1.3.0
- portalocker: 2.7.0
- protobuf: 4.24.2
- psutil: 5.9.5
- pyasn1: 0.5.0
- pyasn1-modules: 0.3.0
- pycparser: 2.21
- pydantic: 1.10.12
- pydantic-core: 2.6.3
- pygments: 2.16.1
- pyjwt: 2.8.0
- pytest: 7.4.0
- python-dateutil: 2.8.2
- python-editor: 1.0.4
- python-multipart: 0.0.6
- pytorch-lightning: 2.0.7
- pytz: 2023.3
- pyyaml: 6.0.1
- readchar: 4.0.5
- requests: 2.31.0
- requests-oauthlib: 1.3.1
- rich: 13.5.2
- rsa: 4.9
- setuptools: 65.5.0
- six: 1.16.0
- sniffio: 1.3.0
- soupsieve: 2.4.1
- starlette: 0.27.0
- starsessions: 1.3.0
- sympy: 1.12
- tensorboard: 2.14.0
- tensorboard-data-server: 0.7.1
- torch: 2.0.1
- torchmetrics: 1.1.1
- tqdm: 4.66.1
- traitlets: 5.9.0
- typeshed-client: 2.3.0
- typing-extensions: 4.7.1
- urllib3: 1.26.16
- uvicorn: 0.23.2
- wcwidth: 0.2.6
- websocket-client: 1.6.1
- websockets: 11.0.3
- werkzeug: 2.3.7
- wheel: 0.41.2
- yarl: 1.9.2
* System:
- OS: Darwin
- architecture:
- 64bit
-
- processor: arm
- python: 3.11.5
- release: 22.6.0
- version: Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000

### More info

_No response_

cc @lantiga @borda

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

Start with the supplied main.py reproduction, using an Azure az:// output path and self.log with TensorBoard installed, then compare it with the version that omits self.log. Trace the failure reported at the end of the first epoch and during checkpoint saving; done means logging and checkpoint creation work on Azure without routing self.log through an unconfigured TensorBoard logger.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, python
Domain
cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.