Flush the buffer to console and tensorboard. Note: It uses the latest epoch, global_step, and batch_idx, so it should be called every iteration.
(self)
| 438 | self.logger.info(text) |
| 439 | |
| 440 | def flush(self): |
| 441 | """Flush the buffer to console and tensorboard. |
| 442 | |
| 443 | Note: |
| 444 | It uses the latest epoch, global_step, and batch_idx, so it should be called every iteration. |
| 445 | """ |
| 446 | # print to console and log file |
| 447 | if self.buffer is not None: |
| 448 | text = f"[gstep {self.global_step}, epoch {self.epoch}, batch {self.batch_idx}] " |
| 449 | for key in sorted(self.buffer.keys()): |
| 450 | text += f"{key}={self.buffer[key]:.3e} " |
| 451 | self.info(text) |
| 452 | |
| 453 | # send to tensorboard |
| 454 | if self.buffer is not None and self.tb_logger is not None: |
| 455 | for tag, scalar_value in self.buffer.items(): |
| 456 | self.tb_logger.add_scalar(tag=tag, scalar_value=scalar_value, global_step=self.global_step) |
| 457 | |
| 458 | if self.tb_logger is not None: |
| 459 | self.tb_logger.flush() |
| 460 | |
| 461 | # clear the buffer |
| 462 | self.buffer = None |
| 463 | |
| 464 | def close(self): |
| 465 | """Close the logger and terminates the tensorboard.""" |
no test coverage detected