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

add memory metrics to TensorBoard #60

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions torchtrain/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ def get_current_stats(self, return_data: bool = False):
)

display_str = ""
display_str += f"Current Memory: {self.device_name} ({self.device_index}): Reserved: {self.device_reserved_memory_pct}%,"
display_str += f"Alloc {self.device_alloc_memory_pct}%, Active: {self.device_active_memory_pct}%\n"
display_str += f"Current Memory: {self.device_name} ({self.device_index}): Reserved: {self.device_reserved_memory_pct}%, "
display_str += f"Alloc {self.device_alloc_memory_pct}%, Active: {self.device_active_memory_pct}%\n"

self.get_peak_stats(curr_mem)

peak_active_pct = self.get_pct_memory(self.peak_active_memory)
peak_allocated_pct = self.get_pct_memory(self.peak_allocated_memory)
peak_reserved_pct = self.get_pct_memory(self.peak_reserved_memory)
display_str += f"Peak Memory: Reserved {peak_reserved_pct}%, Alloc {peak_allocated_pct}%, Active: {peak_active_pct}%\n"
display_str += f"Peak Memory: Reserved {peak_reserved_pct}%, Alloc {peak_allocated_pct}%, Active: {peak_active_pct}%\n"

display_str += f"num retries: {self.num_retries}, num ooms: {self.num_ooms}"
if self.num_retries > 0:
Expand Down
12 changes: 10 additions & 2 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,18 @@ def main(args):
time_delta * parallel_dims.model_parallel_size
)

gpu_mem_stats = gpu_metrics.get_current_stats(return_data=True)

metrics = {
"global_avg_loss": global_avg_loss,
"global_max_loss": global_max_loss,
"loss/global_avg": global_avg_loss,
"loss/global_max": global_max_loss,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - using the / here is confusing to me...I thought it represented the loss divided by the global avg, and same for max...
maybe consider just an _ or : or even :: as the separator? (loss:global_avg, loss::global_max, memory_current_active).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh good point. I use [tag]/[metric] here because TB collects plots under the same [tag] together in a row, so that they form a visual group. Just like in the picture in PR summary, memory metrics are grouped into memory_current, and memory_peak. I'll explore a way that can achieve this but without ambiguity for losses.

Copy link
Contributor Author

@tianyu-l tianyu-l Feb 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some exploration, e.g. tried to put related metrics into a single plot. The options we have are add_scalars and add_custom_scalars, and it seems neither is ideal (e.g.). I'm changing loss/global_avg to loss_metrics/global_avg for now to make it less ambiguous.

"wps": wps,
"memory_current/active(%)": gpu_mem_stats.active_curr,
"memory_current/allocated(%)": gpu_mem_stats.allocated_curr,
"memory_current/reserved(%)": gpu_mem_stats.reserved_curr,
"memory_peak/active(%)": gpu_mem_stats.active_peak,
"memory_peak/allocated(%)": gpu_mem_stats.allocated_peak,
"memory_peak/reserved(%)": gpu_mem_stats.reserved_peak,
}
metric_logger.log(metrics, step=train_state.step)

Expand Down
Loading