Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] About the logger #1997

Closed
4 tasks done
XiaobenLi00 opened this issue Sep 2, 2024 · 1 comment
Closed
4 tasks done

[Question] About the logger #1997

XiaobenLi00 opened this issue Sep 2, 2024 · 1 comment
Labels
question Further information is requested

Comments

@XiaobenLi00
Copy link

❓ 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

@XiaobenLi00 XiaobenLi00 added the question Further information is requested label Sep 2, 2024
@XiaobenLi00 XiaobenLi00 reopened this Sep 3, 2024
@araffin araffin added the Maintainers on vacation Maintainers are on vacation so they can recharge their batteries, we will be back soon ;) label Sep 3, 2024
@araffin
Copy link
Member

araffin commented Sep 10, 2024

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)

@araffin araffin removed the Maintainers on vacation Maintainers are on vacation so they can recharge their batteries, we will be back soon ;) label Sep 10, 2024
@araffin araffin closed this as completed Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants