Yes – you can make TensorBoard show the continuation of a run in the very same curve instead of giving you a “new-colour” line.
The trick is simply to write all events that belong to ONE training run into ONE run-directory.
TensorBoard merges every .tfevents. file that lives inside the same sub-folder, so there is no separate “combine” tool you have to call.
─────────────────────────────────────────────────────────────────────────
- Use the same log directory when you resume
─────────────────────────────────────────────────────────────────────────
# -------------- first launch --------------
writer = SummaryWriter(log_dir="runs/exp1") # NOTE: pick an explicit name
...
for step in range(start_step, max_step):
writer.add_scalar("loss/train", loss, step)
writer.close()
# ------------ after an unexpected restart -----------
ckpt = torch.load("checkpoint.pt")
start_step = ckpt["global_step"] # e.g. 17_600
model.load_state_dict(ckpt["model"])
writer = SummaryWriter(
log_dir="runs/exp1", # <── same directory as above
purge_step=start_step) # <── tells TB to ignore earlier
# duplicates if you re-log them
...
for step in range(start_step, max_step):
writer.add_scalar("loss/train", loss, step)
writer.close()
• log_dir="runs/exp1" makes the second writer drop its new
events file right next to the first one.
• purge_step=start_step (added in PyTorch 1.7) prevents TensorBoard from
complaining about duplicate steps if you accidentally re-emit metrics for
steps you had already logged before the crash.
When you now run
tensorboard --logdir runs
everything under runs/exp1 is aggregated and plotted as a single curve.
─────────────────────────────────────────────────────────────────────────
2. Already have two separate run-folders? Just move the files
─────────────────────────────────────────────────────────────────────────
Suppose you ended up with
runs/
exp1/
events.out.tfevents.168...
exp1_2/
events.out.tfevents.169...
You can merge them by hand:
mv runs/exp1_2/events.out.tfevents.* runs/exp1/
rm -r runs/exp1_2 # optional – keep things tidy
Restart TensorBoard → one curve.
─────────────────────────────────────────────────────────────────────────
3. Recap / Checklist
─────────────────────────────────────────────────────────────────────────
✔ Save / reuse the same log_dir string when you checkpoint.
✔ Pass purge_step=<last_logged_step> on resume (optional but tidy).
✔ Keep your global_step counter increasing monotonically after a resume.
✔ If you’ve already produced separate directories, just copy/move the event
files into a single directory – TensorBoard will handle the rest.
That’s all there is to it – no external merging script required. Happy training!