fix(profiling): patch sub-component methods at class level to prevent instance-isolation bug#13468
Open
Anai-Guo wants to merge 1 commit intohuggingface:mainfrom
Open
Conversation
… instance-isolation bugs
sayakpaul
reviewed
Apr 14, 2026
| continue | ||
| setattr(component, method_name, annotate(method, label)) | ||
| if inspect.ismethod(method): | ||
| # Wrap the underlying function and patch at the class level so |
Member
There was a problem hiding this comment.
Class-level patches should be avoided as they're not transient.
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.
Fixes #13462
Root cause
annotate_pipelinecalledsetattr(component, method_name, annotate(method, label))wheremethodis a bound method (retrieved viagetattr(component, method_name)). The resulting wrapper is a plain function that closes over the original bound method — and thus retains a hard reference to the original component instance.When a pipeline internally copies a sub-component (e.g.
audio_scheduler = copy.copy(self.scheduler)inpipeline_ltx2.py), the copy's instance__dict__inherits the wrapper. Callingaudio_scheduler.step(...)then silently dispatches toself.scheduler.step(...), sharing internal state (_step_index) between the two schedulers and producing index-out-of-bounds errors.Fix
Detect bound methods with
inspect.ismethodand patch at the class level instead:Because the wrapper is now set as a class attribute (an unbound function), Python's descriptor protocol re-binds it to whichever instance accesses it — including copies. Both the original scheduler and
audio_schedulerwill have properly isolatedstepcalls.Impact
examples/profiling/profiling_utils.pyonly (no production pipeline code changed)import inspectand a 5-lineif/elseguard