fix(profiling): preserve instance isolation when decorating methods#13471
Merged
sayakpaul merged 3 commits intohuggingface:mainfrom Apr 15, 2026
Merged
Conversation
sayakpaul
reviewed
Apr 15, 2026
| method = getattr(component, method_name, None) | ||
| if method is None: | ||
| continue | ||
| setattr(component, method_name, annotate(method, label)) |
Member
There was a problem hiding this comment.
Since the example only supports a few pipeline types, we could condition this if "LTX2" in pipe.__class__.__name__ just to be cautious.
Contributor
Author
There was a problem hiding this comment.
I have scoped the fix to only apply to LTX2 pipelines to keep the change conservative.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Member
|
It's a profiling side PR. Doesn't impact any core code. So, merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #13462
This PR resolves an issue where profiling decorators wrap bound methods, capturing the original instance and breaking instance isolation when components are deep-copied.
Previously, decorating a bound method caused the
selfreference to be frozen inside the wrapper closure. When the component (e.g., scheduler) was deep-copied, the wrapped method still referenced the original instance, leading to shared internal state and incorrect behavior.This fix extracts the underlying function using
__func__, applies the decorator, and rebinds it to the instance using__get__. This preserves descriptor behavior and ensures each instance maintains its own state.The solution avoids class-level patching and keeps the modification local to each instance.
Motivation
Ensures correct behavior when components are deep-copied (e.g., multiple schedulers in pipelines), preventing shared state issues and potential runtime errors.
Notes
@sayakpaul