Create the logger. Args: log_filename: Filename to save the log. None: do not save to a file. Remember to account for the rank of the thread so they don't write to the same file. tensorboard_dir: The folder to save the
(
self,
log_filename=None,
tensorboard_dir=None,
tensorboard_num_history_figures=100,
tensorboard_max_reload_threads=1,
tensorboard_exe_path="/venv/bin/tensorboard",
open_tensorboard=False,
tensorboard_port=22222,
rank=0,
launch_tensorboard_at_parent_dir: bool = True,
)
| 249 | """ |
| 250 | |
| 251 | def __init__( |
| 252 | self, |
| 253 | log_filename=None, |
| 254 | tensorboard_dir=None, |
| 255 | tensorboard_num_history_figures=100, |
| 256 | tensorboard_max_reload_threads=1, |
| 257 | tensorboard_exe_path="/venv/bin/tensorboard", |
| 258 | open_tensorboard=False, |
| 259 | tensorboard_port=22222, |
| 260 | rank=0, |
| 261 | launch_tensorboard_at_parent_dir: bool = True, |
| 262 | ): |
| 263 | """Create the logger. |
| 264 | |
| 265 | Args: |
| 266 | log_filename: |
| 267 | Filename to save the log. None: do not save to a file. |
| 268 | Remember to account for the rank of the thread so they don't write to the same file. |
| 269 | tensorboard_dir: |
| 270 | The folder to save the tensorboard file. None: do not save to tensorboard. |
| 271 | Remember to account for the rank of the thread so they don't write to the same folder. |
| 272 | tensorboard_num_history_figures: |
| 273 | Number of historic figures shown in tensorboard. |
| 274 | tensorboard_max_reload_threads: |
| 275 | Number of thread to load existing tensorboard files. |
| 276 | tensorboard_exe_path: |
| 277 | Path of the tensorboard exe file. |
| 278 | open_tensorboard: |
| 279 | Whether to open the tensorboard in a thread as a module. |
| 280 | tensorboard_port: |
| 281 | Port to open the tensorboard if open_tensorboard=True. |
| 282 | rank: |
| 283 | The rank of the current thread. None: ignored. |
| 284 | launch_tensorboard_at_parent_dir: |
| 285 | whether to launch the tensorboard at the parent folder of tensorboard_dir |
| 286 | (so that we can compare multiple experiments). |
| 287 | """ |
| 288 | self.log_filename = log_filename |
| 289 | self.tensorboard_dir = tensorboard_dir |
| 290 | self.rank = rank |
| 291 | |
| 292 | # create logger |
| 293 | logger_name = "global" |
| 294 | if rank is not None: |
| 295 | logger_name = f"{logger_name}.rank{rank:d}" |
| 296 | self.logger = self._create_logger(log_file=self.log_filename, logger_name=logger_name) |
| 297 | |
| 298 | # create tensorboard |
| 299 | if self.tensorboard_dir is not None and rank is not None and rank == 0: |
| 300 | os.makedirs(self.tensorboard_dir, exist_ok=True) |
| 301 | self.tb_logger = SummaryWriter(log_dir=self.tensorboard_dir) |
| 302 | else: |
| 303 | self.tb_logger = None |
| 304 | |
| 305 | # start tensorboard if asked |
| 306 | self.tensorboard_process = None |
| 307 | if open_tensorboard and rank == 0: |
| 308 | if launch_tensorboard_at_parent_dir: |
nothing calls this directly
no test coverage detected