Usage guide

Design Overview

Mark a section of a PyTorch workload to measure its elapsed wall-clock time on each rank. This includes time spent waiting on the host. Asynchronously launched device work can continue after the section exits.

The detector reports two performance scores per section:

  • Relative: the fastest rank’s median duration divided by this rank’s median duration in the current reporting window. The section must have samples on every rank for a relative comparison.

  • Individual: this rank’s best median duration across reporting windows divided by its median duration in the current window.

For example, if a data-loading section takes 20 ms on the fastest rank and 40 ms on rank 7, rank 7’s relative score is 0.5. By default, report.identify_stragglers() returns the rank and hostname for scores below 0.75, grouped by section. Pass section_rel_threshold and section_indiv_threshold by keyword to set different cutoffs.

Usage Overview

Sections of the user code that should be monitored for performance (“detection sections”) can be defined using:
  • Detector.detection_section context manager that allows wrapping a custom code block.

  • Detector.wrap_callables method that wraps given callables within Detector.detection_section.

Both methods yield the same results. Users can choose the API that is most convenient for their needs.

Note

If a detection section is monitored for CPU performance, a given section is supposed to run a similar amount of work on all ranks (e.g., if a significant amount of additional work was conducted on rank 0, rank 0 would be identified as a straggler). The simplest approach might be to wrap the model’s forward call.

Using Detector.detection_section:

import nvidia_resiliency_ext.attribution.straggler as straggler

straggler.Detector.initialize(
   scores_to_compute=["relative_perf_scores", "individual_perf_scores"],
   gather_on_rank0=True # all ranks' results will be available on rank 0
)

for training_iter in range(num_iters):

   ...

   with straggler.Detector.detection_section("data_loading"):
      data, labels = data_loader.get_next_batch()

   with straggler.Detector.detection_section("fwd"):
      out = model(data)
   ...

   if (training_iter % STRAGGLER_REPORT_INTERVAL) == 0:
      report = straggler.Detector.generate_report()
      if rank == 0:
            stragglers = report.identify_stragglers()
            maybe_notify_user(stragglers)

...

straggler.Detector.shutdown()

Using Detector.wrap_callables:

import nvidia_resiliency_ext.attribution.straggler as straggler

straggler.Detector.initialize(
   scores_to_compute=["relative_perf_scores", "individual_perf_scores"],
   gather_on_rank0=True # all ranks' results will be available on rank 0
)

straggler.Detector.wrap_callables(
   callable_ids=[
      straggler.CallableId(DataLoaderClass, "get_next_batch", ignored_args=("self",)),
      straggler.CallableId(ModelClass, "forward", ignored_args=("self",)),
   ]
)

for training_iter in range(num_iters):

   ...

   data, labels = data_loader.get_next_batch()
   out = model(data)

   ...

   if (training_iter % STRAGGLER_REPORT_INTERVAL) == 0:
      report = straggler.Detector.generate_report()
      if rank == 0:
            stragglers = report.identify_stragglers()
            maybe_notify_user(stragglers)

...

straggler.Detector.shutdown()

Alternative Reporting

Besides calling Detector.generate_report after a fixed number of iterations tweaked for a particular workload, users can choose to call .generate_report_if_interval_elapsed along with each training step. The report generation will occur approximately within each time period specified through Detector.initialize(report_time_interval=...).

Note

Straggler detection might involve inter-rank synchronization and should be invoked with reasonable frequency (e.g., every few minutes).

import nvidia_resiliency_ext.attribution.straggler as straggler

straggler.Detector.initialize(report_time_interval=300, ...) # Report every 5 minutes

for training_iter in range(num_iters):

   ...

   # During each training iteration
   report = straggler.Detector.generate_report_if_interval_elapsed()
   if report is not None:
      handle_report(report)

   # Note: straggler.Detector.generate_report() works as usual, users can alternatively use:
   # if (iter_idx % REPORT_INTERVAL) == 0:
   #     straggler.Detector.generate_report()

...

straggler.Detector.shutdown()

Reducing the Overhead

Use Detector.initialize(profiling_interval=...) to sample fewer section entries. If profiling_interval is > 1, only a fraction of section runs are profiled.

Detector.generate_report() overhead depends on the Detector.initialize parameters:
  • Relative performance score calculation (scores_to_compute=["relative_perf_scores", ...]) involves sharing some data between ranks.

  • If gather_on_rank0=True, results from all ranks are gathered on rank 0.

Hence, the following initialization parameters can be used to avoid inter-rank synchronization when calling generate_report():

straggler.Detector.initialize(
   scores_to_compute=["individual_perf_scores"],
   gather_on_rank0=False # each rank will report its own results
)

In that case, all ranks compute and report their own, individual results only.

Integration Guide

Use nvidia_resiliency_ext.attribution.straggler.Detector directly in the training loop: initialize the detector, wrap work in detection sections, generate reports at a consistent cadence across ranks, and shut down on normal exit. See Basic usage example for the DDP integration and API documentation for the reporting API. Application code owns logging and any response to a detected straggler.