Skip to content

Add DeferrableMetrics class#3812

Open
jeffkbkim wants to merge 1 commit intometa-pytorch:mainfrom
jeffkbkim:export-D94254756
Open

Add DeferrableMetrics class#3812
jeffkbkim wants to merge 1 commit intometa-pytorch:mainfrom
jeffkbkim:export-D94254756

Conversation

@jeffkbkim
Copy link
Contributor

Summary:
Add DeferrableMetrics, a unified metrics container that wraps either a resolved
dict or a pending Future. Provides subscribe()/resolve()/update()/is_resolved()
APIs for async-safe metric access.

Key design decisions:

  • bool always returns True to prevent metrics or {} from replacing the container
  • Does NOT implement Mapping; callers must use resolve() or subscribe()
  • subscribe() fires synchronously when already resolved
  • update() supports both dict and DeferrableMetrics inputs with deferred merge
  • update() propagates errors from upstream DeferrableMetrics via on_error handler

This is the foundation for the ZORM APS integration. Subsequent diffs will
migrate RecMetricModule, ITrainModule, and all callers to use this type.

Design Doc: https://docs.google.com/document/d/1V7CQEABwyPAYQLg51yVQ61sCASyHUP1O5oZBNd1743s/edit

Differential Revision: D94254756

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 26, 2026
@meta-codesync
Copy link
Contributor

meta-codesync bot commented Feb 26, 2026

@jeffkbkim has exported this pull request. If you are a Meta employee, you can view the originating Diff in D94254756.

jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Mar 5, 2026
…rch#3812)

Summary:

Add DeferrableMetrics, a unified metrics container that wraps either a resolved
dict or a pending Future. Provides subscribe()/resolve()/update()/is_resolved()
APIs for async-safe metric access.

Key design decisions:
- __bool__ always returns True to prevent `metrics or {}` from replacing the container
- subscribe() fires synchronously when already resolved
- update() supports both dict and DeferrableMetrics inputs with deferred merge
- update() propagates errors from upstream DeferrableMetrics via on_error handler

Deletes metrics_output_util.py entirely. All callers migrated:
- memcpy_compute.py: get_metrics_async() -> DeferrableMetrics.subscribe()
- test_metrics_output_util.py: deleted (coverage now in test_deferrable_metrics.py)

This is the foundation for the ZORM APS integration. Subsequent diffs will
migrate RecMetricModule, ITrainModule, and all callers to use this type.

Design Doc: https://docs.google.com/document/d/1V7CQEABwyPAYQLg51yVQ61sCASyHUP1O5oZBNd1743s/edit

Differential Revision: D94254756
@jeffkbkim jeffkbkim force-pushed the export-D94254756 branch 2 times, most recently from fdf9982 to 4bedb20 Compare March 6, 2026 19:27
jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Mar 6, 2026
…rch#3812)

Summary:

Add DeferrableMetrics, a unified metrics container that wraps either a resolved
dict or a pending Future. Provides subscribe()/resolve()/update()/is_resolved()
APIs for async-safe metric access. Implements Mapping for backward compatibility
during the transition period.

Differential Revision: D94254756
jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Mar 6, 2026
…rch#3812)

Summary:

Add DeferrableMetrics, a unified metrics container that wraps either a resolved
dict or a pending Future. Provides subscribe()/resolve()/update()/is_resolved()
APIs for async-safe metric access. Implements Mapping for backward compatibility
during the transition period.

Differential Revision: D94254756
jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Mar 9, 2026
Summary:

Add DeferrableMetrics, a unified metrics container that wraps either a resolved
dict or a pending Future. Provides subscribe()/resolve()/update()/is_resolved()
APIs for async-safe metric access. Implements Mapping for backward compatibility
during the transition period.

Differential Revision: D94254756
jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Mar 9, 2026
Summary:

Add DeferrableMetrics, a unified metrics container that wraps either a resolved
dict or a pending Future. Provides subscribe()/resolve()/update()/is_resolved()
APIs for async-safe metric access. Implements Mapping for backward compatibility
during the transition period.

Differential Revision: D94254756
jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Mar 9, 2026
Summary:

Add DeferrableMetrics, a unified metrics container that wraps either a resolved
dict or a pending Future. Provides subscribe()/resolve()/update()/is_resolved()
APIs for async-safe metric access.

Differential Revision: D94254756
jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Mar 10, 2026
Summary:

Add DeferrableMetrics, a unified metrics container that wraps either a resolved
dict or a pending Future. Provides subscribe()/resolve()/update()/is_resolved()
APIs for async-safe metric access.

Differential Revision: D94254756
jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Mar 10, 2026
Summary:
Pull Request resolved: meta-pytorch#3812

Add DeferrableMetrics, a unified metrics container that wraps either a resolved
dict or a pending Future. Provides subscribe()/resolve()/update()/is_resolved()
APIs for async-safe metric access.

Differential Revision: D94254756
jeffkbkim added a commit to jeffkbkim/torchrec that referenced this pull request Mar 10, 2026
Summary:
Pull Request resolved: meta-pytorch#3812

Add DeferrableMetrics, a unified metrics container that wraps either a resolved
dict or a pending Future. Provides subscribe()/resolve()/update()/is_resolved()
APIs for async-safe metric access.

Differential Revision: D94254756
Summary:

Add DeferrableMetrics, a unified metrics container that wraps either a resolved
dict or a pending Future. Provides subscribe()/resolve()/update()/is_resolved()
APIs for async-safe metric access.

Differential Revision: D94254756
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant