Skip to content

Lightning log always log in working dir, together with the dir I specify #21118

@Mo-Junyang

Description

@Mo-Junyang

Bug description

I write the code likes this:

    log_dir = os.path.join(config.result_dir, "logs")
    tb_logger = pl_loggers.TensorBoardLogger(save_dir=log_dir)

    ckpt_dir = os.path.join(config.result_dir, "checkpoint")
    checkpoint_callback = ModelCheckpoint(
        dirpath=ckpt_dir,
        every_n_epochs=config.checkpoint_epoch,
        save_on_train_epoch_end=True,
        save_top_k=-1
    )
    step_save_callback = ModelCheckpoint(
        dirpath=ckpt_dir,
        every_n_train_steps=20000,
        save_top_k=1,
        save_weights_only=True
    )
    trainer = L.Trainer(
        default_root_dir=None,
        accelerator='gpu',
        devices=config.cuda_idx,
        max_epochs=config.num_epoch,
        # max_steps=config.num_steps,
        # max_steps=20,
        check_val_every_n_epoch=config.check_val_every_n_epoch,
        logger=tb_logger,
        enable_checkpointing=True,
        log_every_n_steps=1,
        callbacks=[checkpoint_callback,step_save_callback],
        # ========dev option========
        # precision="bf16-mixed",
        num_sanity_val_steps=1,
        # fast_dev_run = 1,
        # limit_train_batches=20,
        # limit_val_batches=20,
        # profiler='advanced'
    )

I will have a log folder saved in my result_dir, and it's working correctly.
But the log file was also saved in my code running directory likes /data/code/project/lightning_logs
I tried define default_root_dir=None, but I still got 2 folder of log file.
How to not log in the running directory

What version are you seeing the problem on?

v2.5

Reproduced in studio

No response

How to reproduce the bug

Error messages and logs

# Error messages and logs here please

Environment

Current environment
#- PyTorch Lightning Version (e.g., 2.5.0):
#- PyTorch Version (e.g., 2.5):
#- Python version (e.g., 3.12):
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source):

More info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingloggingRelated to the `LoggerConnector` and `log()`ver: 2.5.x

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions