Skip to content
Discussion options

You must be logged in to vote

Hey!
You can use the rank id to determine in which process you are, like so:

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__))))

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@awaelchli
Comment options

Answer selected by ItamarKanter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment