Skip to content

Commit ed318b5

Browse files
Shuangping Liumeta-codesync[bot]
authored andcommitted
Helper function to generate trace file name (#3456)
Summary: Pull Request resolved: #3456 Add a helper function to generate trace file name, which will be later used in manifold uploader. Also add a `.gz` suffix to the trace file name, this will enable trace compression according to https://github.com/pytorch/pytorch/blob/v2.8.0/torch/profiler/profiler.py#L257 Reviewed By: TroyGarden Differential Revision: D84548870 fbshipit-source-id: a81b490e51761b21b050277517f62c0d1653fb49
1 parent 9ee9e64 commit ed318b5

File tree

1 file changed

+7
-1
lines changed
  • torchrec/distributed/benchmark

1 file changed

+7
-1
lines changed

torchrec/distributed/benchmark/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,11 @@ def main(self) -> None:
571571
)
572572

573573

574+
def create_trace_file_name(profile_name: str, rank: int) -> str:
575+
"""Create a unique trace file name for the given rank and profile name."""
576+
return f"trace-{profile_name}-rank{rank}.json.gz"
577+
578+
574579
def init_argparse_and_args() -> argparse.Namespace:
575580
parser = argparse.ArgumentParser()
576581

@@ -727,9 +732,10 @@ def _trace_handler(prof: torch.profiler.profile) -> None:
727732
if not all_rank_traces and rank > 0:
728733
# only save trace for rank 0 when all_rank_traces is disabled
729734
return
730-
trace_file = f"{output_dir}/trace-{name}-rank{rank}.json"
735+
trace_file = f"{output_dir}/{create_trace_file_name(name, rank)}"
731736
logger.info(f" PROFILE[{name}].chrome_trace:{trace_file}")
732737
prof.export_chrome_trace(trace_file)
738+
733739
if export_stacks:
734740
prof.export_stacks(
735741
f"{output_dir}/stacks-cpu-{name}.stacks", "self_cpu_time_total"

0 commit comments

Comments
 (0)