Skip to content

Commit

Permalink
Add inductor_fx_graph_cache stats to dynamo_utils
Browse files Browse the repository at this point in the history
Summary:
X-link: pytorch/pytorch#141190

Add the following inductor fx graph cache stats to dynamo compile

- inductor_fx_cache_hit_count
- inductor_fx_cache_miss_count
- inductor_fx_cache_backend_type
- inductor_fx_cache_hit_keys
- inductor_fx_cache_miss_keys
- remote_cache_version

Reviewed By: masnesral

Differential Revision: D66232206

fbshipit-source-id: 6f969460ca54c94d2df7c7506aafa97d7bb9dde3
  • Loading branch information
ppanchalia authored and facebook-github-bot committed Nov 21, 2024
1 parent 1de25b5 commit 6c438b7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions userbenchmark/dynamo/dynamobench/_dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,12 @@ class CompilationMetrics:
joint_graph_pass_time_us: Optional[int] = None
log_format_version: int = LOG_FORMAT_VERSION
inductor_config: Optional[str] = None
remote_cache_version: Optional[int] = None
inductor_fx_remote_cache_hit_count: Optional[int] = None
inductor_fx_remote_cache_miss_count: Optional[int] = None
inductor_fx_remote_cache_backend_type: Optional[str] = None
inductor_fx_remote_cache_hit_keys: Optional[str] = None
inductor_fx_remote_cache_miss_keys: Optional[str] = None


DEFAULT_COMPILATION_METRICS_LIMIT = 64
Expand Down Expand Up @@ -961,8 +967,31 @@ def us_to_ms(field):
metric = metrics.get(field, None)
return metric // 1000 if metric is not None else None

def _convert_collection_to_str(field: str) -> Optional[str]:
def safe_str(item: Any) -> str:
try:
return str(item)
except Exception:
return str(None)

metric = metrics.get(field, None)
if metric is None:
return None

# Remove this field (list/set) from metrics to avoid clashes
del metrics[field]
if not isinstance(metric, set) and not isinstance(metric, list):
return None
return ",".join(safe_str(item) for item in metric)

common_metrics = {
"inductor_config": _scrubbed_inductor_config_for_logging(),
"inductor_fx_remote_cache_hit_keys": _convert_collection_to_str(
"inductor_fx_remote_cache_hit_keys"
),
"inductor_fx_remote_cache_miss_keys": _convert_collection_to_str(
"inductor_fx_remote_cache_miss_keys"
),
# -------- Any future common metircs go here --------
#
# Legacy metircs go here(TODO: Temporary; populate legacy fields from their replacements.)
Expand Down

0 comments on commit 6c438b7

Please sign in to comment.