-
Notifications
You must be signed in to change notification settings - Fork 239
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 TensorBoard logging with loss and wps #57
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ torch >= 2.2.0.dev | |
sentencepiece | ||
datasets | ||
tomli >= 1.1.0 ; python_version < "3.11" | ||
tensorboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement. | ||
|
||
import os | ||
from datetime import datetime | ||
from typing import Any, Dict, Optional | ||
|
||
import torch | ||
from torch.utils.tensorboard import SummaryWriter | ||
|
||
from torchtrain.logging_utils import rank0_log | ||
from torchtrain.profiling import get_config_from_toml | ||
|
||
|
||
class MetricLogger: | ||
def __init__(self, log_dir, tag, enable_tb): | ||
self.tag = tag | ||
self.writer: Optional[SummaryWriter] = None | ||
if enable_tb: | ||
self.writer = SummaryWriter(log_dir, max_queue=1000) | ||
|
||
def log(self, metrics: Dict[str, Any], step: int): | ||
if self.writer is not None: | ||
for k, v in metrics.items(): | ||
tag = k if self.tag is None else f"{self.tag}/{k}" | ||
self.writer.add_scalar(tag, v, step) | ||
|
||
def close(self): | ||
if self.writer is not None: | ||
self.writer.close() | ||
|
||
|
||
def build_metric_logger(tag: Optional[str] = None): | ||
config = get_config_from_toml() | ||
|
||
dump_dir = config["global"]["dump_folder"] | ||
save_tb_folder = config["metrics"]["save_tb_folder"] | ||
# since we don't have run id yet, use current minute as identifier | ||
datetime_str = datetime.now().strftime("%Y%m%d-%H%M") | ||
log_dir = os.path.join(dump_dir, save_tb_folder, datetime_str) | ||
|
||
enable_tb = config["metrics"].get("enable_tensorboard", False) | ||
if enable_tb: | ||
rank0_log( | ||
f"Metrics logging active. Tensorboard logs will be saved at {log_dir}." | ||
) | ||
|
||
rank_str = f"rank_{torch.distributed.get_rank()}" | ||
return MetricLogger(os.path.join(log_dir, rank_str), tag, enable_tb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement. | ||
|
||
from typing import Union | ||
|
||
import torch | ||
import torch.distributed._functional_collectives as funcol | ||
import torch.distributed.distributed_c10d as c10d | ||
from torch.distributed.device_mesh import DeviceMesh | ||
|
||
|
||
def dist_max(x: Union[int, float], mesh: DeviceMesh) -> float: | ||
tensor = torch.tensor(x).cuda() | ||
return funcol.all_reduce(tensor, reduceOp=c10d.ReduceOp.MAX.name, group=mesh) | ||
|
||
|
||
def dist_mean(x: Union[int, float], mesh: DeviceMesh) -> float: | ||
tensor = torch.tensor(x).cuda() | ||
return funcol.all_reduce(tensor, reduceOp=c10d.ReduceOp.AVG.name, group=mesh) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a neater way is to define a
model_parallel_size
in theparallel_dims
class that return this number directly (i.e. a cached property)