Skip to content

Commit

Permalink
upload pt2 cprofile stats to manifold (#125162)
Browse files Browse the repository at this point in the history
Summary:
https://fb.workplace.com/groups/257735836456307/permalink/657458576484029/

upload cprofile to manifold

D56696397 has a script to convert profiler stats to dot graphs (see its test plan)

Test Plan:
non-MAST
`TORCH_COMPILE_CPROFILE=1 buck2 run mode/opt mode/inplace //pytorch/benchmark:run -- ads_mc_igctr_mc3_v0 -d cuda -t train --torchdynamo inductor --profile --profile-export-chrome-trace`

https://www.internalfb.com/manifold/explorer/pyper_traces/tree/compilation_cprofile/test/20240428_234002_7562397568

MAST
`buck2 run mode/opt aps_models/ads/icvr:icvr_launcher -- mode=mast_ctr_cvr_cmf_rep launcher.fbl_entitlement=ai_infra_training_rnd_tc features=ctr_cvr_conso_cmf_pipeline_features_455876776_3teach model=ctr_cvr_cmf_when_rep_config_msmn_3teach model_name=ctr_cvr_when model.when_arch.use_extended_residual_contexts=True optimizers.dense_default.lr_schedule.0.max_iters=20000 training.planner.storage_reservation_policy=FixedPercentage training.planner.storage_reservation_percentage=0.72 data_loader.dataset.batch_size=2048 trainer.garbage_collection.garbage_collection_interval=100 model.when_arch.layer_norm_init_weight=0.3 optimizers.dense_default.lr_schedule.0.value=0.001 model.when_arch.customized_mlp_init_scale=0.3 launcher.num_workers=128 launcher.max_retries=10 launcher.data_project=oncall_ads_model_platform launcher.hardware=ZIONEX_80G data_loader.dataset.table_ds="[2024-01-01]" launcher.job_name=test_inductor_logging`

https://www.internalfb.com/manifold/explorer/pyper_traces/tree/compilation_cprofile/aps-test_inductor_logging-745febb51a

Generating dotty files from D56696397
```
Generating dot file from cprofile stats /home/daohang/aps-test_inductor_logging-745febb51a/0/0/_compile1.profile ...
P1225733598: https://www.internalfb.com/intern/paste/P1225733598/
Dotty: https://www.internalfb.com/intern/graphviz/?paste=1225733598
Generating dot file from cprofile stats /home/daohang/aps-test_inductor_logging-745febb51a/0/0/_compile10.profile ...
P1225733629: https://www.internalfb.com/intern/paste/P1225733629/
Dotty: https://www.internalfb.com/intern/graphviz/?paste=1225733629
Generating dot file from cprofile stats /home/daohang/aps-test_inductor_logging-745febb51a/0/0/_compile0.profile ...
P1225733649: https://www.internalfb.com/intern/paste/P1225733649/
Dotty: https://www.internalfb.com/intern/graphviz/?paste=1225733649
```

Differential Revision: D56679561

Pull Request resolved: #125162
Approved by: https://github.com/anijain2305
  • Loading branch information
dshi7 authored and pytorchmergebot committed Apr 30, 2024
1 parent 2480e8b commit b7d67e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion torch/_dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
ValuesView,
)

from torch._utils_internal import maybe_upload_prof_stats_to_manifold

from ..utils.hooks import RemovableHandle

try:
Expand Down Expand Up @@ -144,7 +146,7 @@ def cprofile_wrapper(func):
def profile_wrapper(*args, **kwargs):
global timer_counter
profile_cnt = next(timer_counter)
profile_path = Path(func.__name__ + f"{profile_cnt}.profile")
profile_path = Path("/tmp/" + func.__name__ + f"{profile_cnt}.profile")
prof = cProfile.Profile()
prof.enable()
start_ts = time.time()
Expand Down Expand Up @@ -182,6 +184,9 @@ def profile_wrapper(*args, **kwargs):
)
ps.sort_stats(pstats.SortKey.TIME).print_stats(20)
ps.sort_stats(pstats.SortKey.CUMULATIVE).print_stats(20)

maybe_upload_prof_stats_to_manifold(str(profile_path)) # fb-only

return retval

return profile_wrapper
Expand Down
5 changes: 5 additions & 0 deletions torch/_utils_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,8 @@ def max_clock_rate():
# m.set_python_module("mylib.ops") call from C++ that associates
# the C++ op with a python module.
REQUIRES_SET_PYTHON_MODULE = False


def maybe_upload_prof_stats_to_manifold(profile_path: str) -> None:
print("Uploading profile stats (fb-only otherwise no-op)")
pass

0 comments on commit b7d67e4

Please sign in to comment.