# Unable to log each run when using pytorch lightning integration

**URL:** <https://community.wandb.ai/t/unable-to-log-each-run-when-using-pytorch-lightning-integration/3443>\
**Category:** W&B Help\
**Tags:** wandb\
**Created:** [November 18, 2022, 10:42pm UTC](https://community.wandb.ai/t/unable-to-log-each-run-when-using-pytorch-lightning-integration/3443 "2022-11-18T22:42:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tleyden](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/tleyden/32/1140_2.png) [@tleyden](https://community.wandb.ai/u/tleyden)\
**Post date:** [November 18, 2022, 10:42pm UTC](https://community.wandb.ai/t/unable-to-log-each-run-when-using-pytorch-lightning-integration/3443/1 "2022-11-18T22:42:35Z")

</div>

I’m able to log a training run with pytorch lightning + wandb based on [these instructions](https://docs.wandb.ai/guides/integrations/lightning) in google colab. Here’s a snippet of code I’m running:

```auto
wandb_logger = WandbLogger(project="p", entity="e")
trainer = pl.Trainer(
    logger=wandb_logger, # W&B integration
    ..
)
trainer.fit(model)

```

it outputs the link to the run and I can see all of the stats etc.

However, how can I retrain? If I try re-training with:

```auto
trainer = pl.Trainer(
    logger=wandb_logger, # W&B integration
    ..
)
trainer.fit(model)

```

It doesn’t seem to log a new run. It looks like it doesn’t even log the data to the existing run, it is just completely lost.

If I try to create a new wandb logger before the re-training:

```auto
wandb_logger = WandbLogger(project="p", entity="e")
trainer = pl.Trainer(
    logger=wandb_logger, # W&B integration
    ..
)
trainer.fit(model)

```

it times out after 1 minute with this error:

````auto
andb: ERROR Error communicating with wandb process
wandb: ERROR For more info see: https://docs.wandb.ai/library/init#init-start-error
Problem at: /usr/local/lib/python3.7/dist-packages/pytorch_lightning/loggers/wandb.py 406 experiment
---------------------------------------------------------------------------
UsageError Traceback (most recent call last)
<ipython-input-44-6016437e3426> in <module>
----> 1 wandb_logger = WandbLogger(project="p", entity="e")

6 frames
/usr/local/lib/python3.7/dist-packages/wandb/sdk/wandb_init.py in init(self)
    717 backend.cleanup()
    718 self.teardown()
--> 719 raise UsageError(error_message)
    720 assert run_result and run_result.run
    721 if run_result.run.resumed:

UsageError: Error communicating with wandb process
For more info see: https://docs.wandb.ai/library/init#init-start-error```

Am I using wandb + pytorch lightning the correct way? What is the expected lifecycle of the wandb logger in relation to the pl training object?
````

---

<div class="post-metadata">

**Author:** ![tleyden](https://sea2.discourse-cdn.com/flex020/user_avatar/community.wandb.ai/tleyden/32/1140_2.png) [@tleyden](https://community.wandb.ai/u/tleyden)\
**Post date:** [November 19, 2022, 12:32am UTC](https://community.wandb.ai/t/unable-to-log-each-run-when-using-pytorch-lightning-integration/3443/2 "2022-11-19T00:32:56Z")

</div>

Actually nevermind, it’s working now! I don’t know what I changed that fixed it while I was trying to debug, maybe I had forgotten to call .finish() on the first run.

Here’s the gist of the code I’m running:

```auto
wandb_logger = WandbLogger(project="p", entity="e", log_model=True)
trainer = pl.Trainer(
    logger=wandb_logger, # W&B integration
    ..
)
trainer.fit(model)
wandb.finish()

```

I’m able to run the above snippet repeatedly and it creates a new run each time.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [January 18, 2023, 12:33am UTC](https://community.wandb.ai/t/unable-to-log-each-run-when-using-pytorch-lightning-integration/3443/3 "2023-01-18T00:33:02Z")

</div>

Closed on January 18, 2023, 12:33am UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
