DLR-RM/stable-baselines3

[Question] About the logger

XiaobenLi00 opened this issue · 1 comments

❓ Question

In the doc https://stable-baselines3.readthedocs.io/en/master/common/logger.html, there is a warning
image
I am wondering that if I a custom logger object like

logger = configure(f'results_{job_data.env}')
model = PPO(job_data.policy, env,  verbose=1,
                    tensorboard_log=f"wandb/{run.id}",
                    learning_rate=job_data.learning_rate, 
                    batch_size=job_data.batch_size, 
                    policy_kwargs=policy_kwargs,
                    gamma=job_data.gamma, **job_data.alg_hyper_params)
...
model.set_logger(logger)
model.learn(
    total_timesteps=config["total_timesteps"],
    callback=callback,
)

How should I set tensorboard_log and verbose? Because I notice that in the code below, the settings is overwritten and no info is logged.

Checklist

why do you need a custom logger in your case? it seems that you just want to change the name, we have tb_log_name parameter (to the learn() method) for that.

Nothing is logged in your case because you didn't specify any logger format...

def configure(folder: Optional[str] = None, format_strings: Optional[List[str]] = None) -> Logger:

the built-in configure is here:

def configure_logger(
verbose: int = 0,
tensorboard_log: Optional[str] = None,
tb_log_name: str = "",
reset_num_timesteps: bool = True,
) -> Logger:
"""
Configure the logger's outputs.
:param verbose: Verbosity level: 0 for no output, 1 for the standard output to be part of the logger outputs
:param tensorboard_log: the log location for tensorboard (if None, no logging)
:param tb_log_name: tensorboard log
:param reset_num_timesteps: Whether the ``num_timesteps`` attribute is reset or not.
It allows to continue a previous learning curve (``reset_num_timesteps=False``)
or start from t=0 (``reset_num_timesteps=True``, the default).
:return: The logger object
"""
save_path, format_strings = None, ["stdout"]
if tensorboard_log is not None and SummaryWriter is None:
raise ImportError("Trying to log data to tensorboard but tensorboard is not installed.")
if tensorboard_log is not None and SummaryWriter is not None:
latest_run_id = get_latest_run_id(tensorboard_log, tb_log_name)
if not reset_num_timesteps:
# Continue training in the same directory
latest_run_id -= 1
save_path = os.path.join(tensorboard_log, f"{tb_log_name}_{latest_run_id + 1}")
if verbose >= 1:
format_strings = ["stdout", "tensorboard"]
else:
format_strings = ["tensorboard"]
elif verbose == 0:
format_strings = [""]
return configure(save_path, format_strings=format_strings)