Skip to content

Commit f6420f9

Browse files
committed
fix(profiling): preserve instance isolation when decorating methods
1 parent e9c092d commit f6420f9

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

examples/profiling/profiling_utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,18 @@ def annotate_pipeline(pipe):
4545
method = getattr(component, method_name, None)
4646
if method is None:
4747
continue
48-
setattr(component, method_name, annotate(method, label))
48+
49+
# Extract underlying function (avoid bound-method issue)
50+
func = getattr(method, "__func__", method)
51+
52+
# Wrap function
53+
wrapped = annotate(func, label)
54+
55+
# Rebind to THIS instance only (preserve descriptor behavior)
56+
bound_method = wrapped.__get__(component, type(component))
57+
58+
# Set back
59+
setattr(component, method_name, bound_method)
4960

5061
# Annotate pipeline-level methods
5162
if hasattr(pipe, "encode_prompt"):

0 commit comments

Comments
 (0)