Skip to content

Commit

Permalink
Measure Dynamo cache latency lookup (#121604)
Browse files Browse the repository at this point in the history
Summary:
X-link: pytorch/pytorch#121604
Approved by: https://github.com/jansel
ghstack dependencies: #121614, #121622

Reviewed By: osalpekar

Differential Revision: D54875725

Pulled By: anijain2305

fbshipit-source-id: d8cd464d3bf889f5cbcd64192f3c498da163c066
  • Loading branch information
anijain2305 authored and facebook-github-bot committed Mar 14, 2024
1 parent 0ea6f93 commit 6ea22b3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions userbenchmark/dynamo/dynamobench/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,11 @@ def maybe_mark_profile(*args, **kwargs):
row.append(kwargs["compression_ratio"])
row.append(kwargs["eager_peak_mem"])
row.append(kwargs["dynamo_peak_mem"])

if "cache_lookup_latency" in kwargs:
headers.append("cache_lookup_latency")
row.append(kwargs["cache_lookup_latency"])

if "dynamo_stats" in kwargs:
for k, v in kwargs["dynamo_stats"].items():
headers.append(k)
Expand Down Expand Up @@ -2678,6 +2683,21 @@ def warmup(fn, model, example_inputs, mode, niters=5):
optimized_model_iter_fn, model, example_inputs, "dynamo"
)

if self.args.profile_dynamo_cache_lookup:
with torch.profiler.profile(
activities=[torch.profiler.ProfilerActivity.CPU]
) as prof:
with maybe_enable_compiled_autograd(self.args.compiled_autograd):
warmup(optimized_model_iter_fn, model, example_inputs, "dynamo")

events = list(
filter(
lambda event: "TorchDynamo Cache Lookup" in event.key,
prof.key_averages(),
)
)
dynamo_cache_lookup_latency = events[0].self_cpu_time_total

compilation_time = dynamo_latency - eager_latency + aot_compilation_time
compression_ratio = (
eager_peak_mem / dynamo_peak_mem if dynamo_peak_mem else 0.0
Expand All @@ -2695,6 +2715,10 @@ def warmup(fn, model, example_inputs, mode, niters=5):
experiment_kwargs["eager_peak_mem"] = eager_peak_mem
experiment_kwargs["dynamo_peak_mem"] = dynamo_peak_mem
experiment_kwargs["dynamo_stats"] = dynamo_stats
if self.args.profile_dynamo_cache_lookup:
experiment_kwargs[
"cache_lookup_latency"
] = dynamo_cache_lookup_latency

if experiment.func is coverage_experiment:
ok, total = Stats.reset_counters()
Expand Down Expand Up @@ -3201,6 +3225,13 @@ def get_example_inputs(self):
help="Enables compiled autograd on compiled benchmark",
)

parser.add_argument(
"--profile_dynamo_cache_lookup",
"--profile-dynamo-cache-lookup",
action="store_true",
help="profiles TorchDynamo cache lookup",
)

group_fuser = parser.add_mutually_exclusive_group()
# --nvfuser is now the default, keep the option to not break scripts
group_fuser.add_argument("--nvfuser", action="store_true", help=argparse.SUPPRESS)
Expand Down

0 comments on commit 6ea22b3

Please sign in to comment.