-
Notifications
You must be signed in to change notification settings - Fork 62
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 support to metrics calculation #196
Open
shengfukevin
wants to merge
1
commit into
main
Choose a base branch
from
sanshang/calc_metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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 |
---|---|---|
|
@@ -19,11 +19,12 @@ | |
from io import StringIO | ||
from typing import Any | ||
|
||
from torch._C._profiler import ProfilerActivity | ||
|
||
try: | ||
from param_bench.train.comms.pt.fb.internals import ( | ||
fbInitProfiler, | ||
fbSampleProfiler, | ||
fbStartProfiler, | ||
from et_replay.fb.internals import ( | ||
get_fb_profiler_activities, | ||
get_fb_profiler_trace_handler, | ||
initialize_collectiveArgs_internal, | ||
remove_quantization_handlers, | ||
) | ||
|
@@ -390,45 +391,79 @@ def ensureTensorFlush(tensors: list[torch.Tensor] | torch.Tensor) -> Any: | |
return x | ||
|
||
|
||
def startProfiler(rank: int, device: str, numWarmupIters: int, numIters: int) -> bool: | ||
_torch_profiler = None | ||
|
||
|
||
def startProfiler( | ||
rank: int, device: str, numWarmupIters: int, numIters: int, output_path: str | ||
): | ||
""" | ||
Starts internal profiler with given parameters. | ||
Starts pytorch profiler with given parameters. | ||
|
||
Args: | ||
rank: Global rank. | ||
device: Type of device "cuda", "cpu", etc. | ||
numWarmupIters: Number of warmup iterations. | ||
numIters: Number of real iterations. | ||
Returns: | ||
bool: Returns if internal profile was able to start or not. | ||
output_path: Path to save profiler trace. | ||
""" | ||
global _torch_profiler | ||
|
||
if has_internal_libs: | ||
fbInitProfiler( | ||
rank=rank, | ||
device=device, | ||
activities = get_fb_profiler_activities() | ||
trace_handler = get_fb_profiler_trace_handler() | ||
else: | ||
activities = ([ProfilerActivity.CPU, ProfilerActivity.CUDA],) | ||
|
||
def trace_handler(p): | ||
import pathlib | ||
|
||
folder_path = os.path.join(output_path, "profiler_trace") | ||
try: | ||
pathlib.Path(folder_path).mkdir(parents=True, exist_ok=True) | ||
except PermissionError: | ||
logger.error(f"Permission denied to create directory {folder_path}") | ||
p.export_chrome_trace(os.path.join(folder_path, f"rank-{rank}.json")) | ||
|
||
logger.debug("GPU Trace Collection: Enabled") | ||
_torch_profiler = torch.profiler.profile( | ||
schedule=torch.profiler.schedule( | ||
wait=1, | ||
warmup=numWarmupIters, | ||
iters=numIters, | ||
) | ||
fbStartProfiler() | ||
active=numIters, | ||
repeat=1, | ||
), | ||
on_trace_ready=trace_handler, | ||
activities=activities, | ||
) | ||
|
||
if _torch_profiler: | ||
logger.debug("GPU Trace Profiler: Start") | ||
_torch_profiler.start() | ||
return True | ||
else: | ||
logger.debug("Internal profiler is not available, skip...") | ||
logger.debug("GPU Trace Profiler: Fail to start") | ||
return False | ||
|
||
|
||
def sampleProfiler(stop: bool = False) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where to invoke this function with stop=true? |
||
""" | ||
Starts internal sample profiler. | ||
Starts sample profiler. | ||
|
||
Args: | ||
stop: Bool to be passed into sample profiler. | ||
Returns: | ||
None | ||
""" | ||
if has_internal_libs: | ||
fbSampleProfiler(stop) | ||
global _torch_profiler | ||
if _torch_profiler: | ||
_torch_profiler.step() | ||
if stop: | ||
_torch_profiler.stop() | ||
_torch_profiler = None | ||
logger.debug("GPU Trace Profiler: Stop") | ||
else: | ||
logger.debug("Internal profiler is not available, skip...") | ||
logger.debug("GPU Trace Profiler: not enabled") | ||
|
||
|
||
class commsArgs: | ||
|
Oops, something went wrong.
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.
Where to invoke this?