How to save a copy of the running script into the log folder? #7310
Answered
by
awaelchli
ItamarKanter
asked this question in
Lightning Trainer API: Trainer, LightningModule, LightningDataModule
-
Hi,
The problem is that I ended up with two copies of my running script under two different folders (I'm using the ddp backend) Any ideas on how to solve this issue? |
Beta Was this translation helpful? Give feedback.
Answered by
awaelchli
May 3, 2021
Replies: 1 comment 1 reply
-
Hey! if trainer.global_rank == 0:
# do something only on first process In your example, this could make sense: import os
from pathlib import Path
class MyCopyingCallback(pl.Callback):
def on_init_end(self, trainer):
if trainer.global_rank != 0:
return
log_dir = trainer.logger.log_dir
Path(log_dir).mkdir(parents=True, exist_ok=True)
shutil.copy2(os.path.realpath(__file__), os.path.join(log_dir, os.path.basename(os.path.realpath(__file__)))) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ItamarKanter
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey!
You can use the rank id to determine in which process you are, like so:
In your example, this could make sense: