nnsight 0.5.0.dev7__tar.gz → 0.5.0.dev9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/PKG-INFO +1 -1
  2. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/__init__.py +23 -0
  3. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/envoy.py +40 -8
  4. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/interleaver.py +134 -150
  5. nnsight-0.5.0.dev9/src/nnsight/intervention/tracing/backwards.py +54 -0
  6. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/tracing/iterator.py +7 -12
  7. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/language.py +10 -2
  8. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight.egg-info/PKG-INFO +1 -1
  9. nnsight-0.5.0.dev9/src/nnsight.egg-info/SOURCES.txt +69 -0
  10. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/tests/test_lm.py +5 -6
  11. nnsight-0.5.0.dev7/docs/.DS_Store +0 -0
  12. nnsight-0.5.0.dev7/docs/Makefile +0 -28
  13. nnsight-0.5.0.dev7/docs/contributing.md +0 -31
  14. nnsight-0.5.0.dev7/docs/make.bat +0 -35
  15. nnsight-0.5.0.dev7/docs/requirements.txt +0 -8
  16. nnsight-0.5.0.dev7/docs/source/.DS_Store +0 -0
  17. nnsight-0.5.0.dev7/docs/source/_static/.DS_Store +0 -0
  18. nnsight-0.5.0.dev7/docs/source/_static/css/custom.css +0 -65
  19. nnsight-0.5.0.dev7/docs/source/_static/css/home.css +0 -28
  20. nnsight-0.5.0.dev7/docs/source/_static/css/pygments.css +0 -75
  21. nnsight-0.5.0.dev7/docs/source/_static/css/status.css +0 -13
  22. nnsight-0.5.0.dev7/docs/source/_static/images/.DS_Store +0 -0
  23. nnsight-0.5.0.dev7/docs/source/_static/images/execution.png +0 -0
  24. nnsight-0.5.0.dev7/docs/source/_static/images/icon.ico +0 -0
  25. nnsight-0.5.0.dev7/docs/source/_static/images/interleaved.png +0 -0
  26. nnsight-0.5.0.dev7/docs/source/_static/images/ioi.png +0 -0
  27. nnsight-0.5.0.dev7/docs/source/_static/images/nnsight_logo.svg +0 -1
  28. nnsight-0.5.0.dev7/docs/source/_static/images/tutorials/.DS_Store +0 -0
  29. nnsight-0.5.0.dev7/docs/source/_static/images/tutorials/activation_patching.webp +0 -0
  30. nnsight-0.5.0.dev7/docs/source/_static/images/tutorials/attribution_patching.webp +0 -0
  31. nnsight-0.5.0.dev7/docs/source/_static/images/tutorials/dictionary_learning.webp +0 -0
  32. nnsight-0.5.0.dev7/docs/source/_static/images/tutorials/function_vectors.webp +0 -0
  33. nnsight-0.5.0.dev7/docs/source/_static/images/tutorials/future_lens.webp +0 -0
  34. nnsight-0.5.0.dev7/docs/source/_static/images/tutorials/logit_lens.webp +0 -0
  35. nnsight-0.5.0.dev7/docs/source/_static/images/tutorials/walkthrough.webp +0 -0
  36. nnsight-0.5.0.dev7/docs/source/_static/js/.DS_Store +0 -0
  37. nnsight-0.5.0.dev7/docs/source/_static/js/code.js +0 -82
  38. nnsight-0.5.0.dev7/docs/source/_static/js/custom.js +0 -81
  39. nnsight-0.5.0.dev7/docs/source/_templates/layout.html +0 -7
  40. nnsight-0.5.0.dev7/docs/source/_templates/ndif_status.html +0 -35
  41. nnsight-0.5.0.dev7/docs/source/about.rst +0 -102
  42. nnsight-0.5.0.dev7/docs/source/conf.py +0 -76
  43. nnsight-0.5.0.dev7/docs/source/documentation/intervention.rst +0 -77
  44. nnsight-0.5.0.dev7/docs/source/documentation/modeling.rst +0 -19
  45. nnsight-0.5.0.dev7/docs/source/documentation/schema.rst +0 -22
  46. nnsight-0.5.0.dev7/docs/source/documentation/tracing.rst +0 -41
  47. nnsight-0.5.0.dev7/docs/source/documentation/util.rst +0 -6
  48. nnsight-0.5.0.dev7/docs/source/documentation.rst +0 -12
  49. nnsight-0.5.0.dev7/docs/source/features.rst +0 -359
  50. nnsight-0.5.0.dev7/docs/source/index.rst +0 -18
  51. nnsight-0.5.0.dev7/docs/source/notebooks/features/conditionals.ipynb +0 -173
  52. nnsight-0.5.0.dev7/docs/source/notebooks/features/cross_prompt.ipynb +0 -150
  53. nnsight-0.5.0.dev7/docs/source/notebooks/features/custom_functions.ipynb +0 -102
  54. nnsight-0.5.0.dev7/docs/source/notebooks/features/early_stopping.ipynb +0 -260
  55. nnsight-0.5.0.dev7/docs/source/notebooks/features/editing_tutorial.ipynb +0 -213
  56. nnsight-0.5.0.dev7/docs/source/notebooks/features/getting.ipynb +0 -96
  57. nnsight-0.5.0.dev7/docs/source/notebooks/features/gradients.ipynb +0 -214
  58. nnsight-0.5.0.dev7/docs/source/notebooks/features/iterator.ipynb +0 -173
  59. nnsight-0.5.0.dev7/docs/source/notebooks/features/lora_training.ipynb +0 -2967
  60. nnsight-0.5.0.dev7/docs/source/notebooks/features/model_editing.ipynb +0 -158
  61. nnsight-0.5.0.dev7/docs/source/notebooks/features/modules.ipynb +0 -103
  62. nnsight-0.5.0.dev7/docs/source/notebooks/features/multiple_token.ipynb +0 -361
  63. nnsight-0.5.0.dev7/docs/source/notebooks/features/operations.ipynb +0 -107
  64. nnsight-0.5.0.dev7/docs/source/notebooks/features/remote_execution.ipynb +0 -167
  65. nnsight-0.5.0.dev7/docs/source/notebooks/features/scan_validate.ipynb +0 -381
  66. nnsight-0.5.0.dev7/docs/source/notebooks/features/sessions.ipynb +0 -167
  67. nnsight-0.5.0.dev7/docs/source/notebooks/features/setting.ipynb +0 -104
  68. nnsight-0.5.0.dev7/docs/source/notebooks/features/streaming.ipynb +0 -448
  69. nnsight-0.5.0.dev7/docs/source/notebooks/features/vllm_support.ipynb +0 -3213
  70. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/LoRA_tutorial.ipynb +0 -12235
  71. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/activation_patching.ipynb +0 -4391
  72. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/attribution_patching.ipynb +0 -9038
  73. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/boundless_DAS.ipynb +0 -578
  74. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/dict_learning.ipynb +0 -369
  75. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/diffusion_lens.ipynb +0 -713
  76. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/images/Activation_patching-figure1.png +0 -0
  77. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/images/LoRA_tutorial_figure_1.png +0 -0
  78. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/images/LoRA_tutorial_figure_2.png +0 -0
  79. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/logit_lens.ipynb +0 -3431
  80. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/start_remote_access.ipynb +0 -3159
  81. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/tutorial_price_tagging_utils.py +0 -439
  82. nnsight-0.5.0.dev7/docs/source/notebooks/tutorials/walkthrough.ipynb +0 -6445
  83. nnsight-0.5.0.dev7/docs/source/pages/home.html +0 -159
  84. nnsight-0.5.0.dev7/docs/source/start.rst +0 -78
  85. nnsight-0.5.0.dev7/docs/source/status.rst +0 -290
  86. nnsight-0.5.0.dev7/docs/source/tutorials.rst +0 -174
  87. nnsight-0.5.0.dev7/docs/sourcelatex/conf.py +0 -52
  88. nnsight-0.5.0.dev7/docs/sourcelatex/documentation/contexts.rst +0 -16
  89. nnsight-0.5.0.dev7/docs/sourcelatex/documentation/intervention.rst +0 -5
  90. nnsight-0.5.0.dev7/docs/sourcelatex/documentation/models.rst +0 -18
  91. nnsight-0.5.0.dev7/docs/sourcelatex/documentation/module.rst +0 -5
  92. nnsight-0.5.0.dev7/docs/sourcelatex/documentation/patching.rst +0 -6
  93. nnsight-0.5.0.dev7/docs/sourcelatex/documentation/tracing.rst +0 -14
  94. nnsight-0.5.0.dev7/docs/sourcelatex/documentation/util.rst +0 -6
  95. nnsight-0.5.0.dev7/docs/sourcelatex/index.rst +0 -13
  96. nnsight-0.5.0.dev7/src/nnsight/intervention/tracing/backwards.py +0 -38
  97. nnsight-0.5.0.dev7/src/nnsight.egg-info/SOURCES.txt +0 -154
  98. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/.github/workflows/publish.yml +0 -0
  99. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/.github/workflows/python-app.yml +0 -0
  100. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/.gitignore +0 -0
  101. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/CHANGELOG.md +0 -0
  102. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/CODE_OF_CONDUCT.md +0 -0
  103. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/LICENSE +0 -0
  104. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/NNsight_Walkthrough.ipynb +0 -0
  105. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/NNsight_v0_3_guide.ipynb +0 -0
  106. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/NNsight_v0_4_guide.ipynb +0 -0
  107. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/README.md +0 -0
  108. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/conftest.py +0 -0
  109. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/pyproject.toml +0 -0
  110. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/pytest.ini +0 -0
  111. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/setup.cfg +0 -0
  112. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/setup.py +0 -0
  113. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/_c/__init__.py +0 -0
  114. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/_c/py_mount.c +0 -0
  115. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/config.yaml +0 -0
  116. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/__init__.py +0 -0
  117. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/backends/__init__.py +0 -0
  118. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/backends/base.py +0 -0
  119. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/backends/editing.py +0 -0
  120. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/backends/execution.py +0 -0
  121. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/backends/remote.py +0 -0
  122. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/batching.py +0 -0
  123. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/inject.py +0 -0
  124. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/serialization.py +0 -0
  125. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/tracing/__init__.py +0 -0
  126. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/tracing/base.py +0 -0
  127. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/tracing/editing.py +0 -0
  128. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/tracing/globals.py +0 -0
  129. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/tracing/invoker.py +0 -0
  130. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/tracing/tracer.py +0 -0
  131. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/intervention/tracing/util.py +0 -0
  132. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/log.py +0 -0
  133. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/__init__.py +0 -0
  134. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/base.py +0 -0
  135. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/diffusion.py +0 -0
  136. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/mixins/__init__.py +0 -0
  137. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/mixins/loadable.py +0 -0
  138. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/mixins/meta.py +0 -0
  139. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/mixins/remoteable.py +0 -0
  140. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/vllm/__init__.py +0 -0
  141. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/vllm/model_runners/GPUModelRunner.py +0 -0
  142. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/vllm/model_runners/__init__.py +0 -0
  143. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/vllm/sampling.py +0 -0
  144. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/vllm/vllm.py +0 -0
  145. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/vllm/workers/GPUWorker.py +0 -0
  146. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/modeling/vllm/workers/__init__.py +0 -0
  147. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/schema/__init__.py +0 -0
  148. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/schema/config.py +0 -0
  149. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/schema/request.py +0 -0
  150. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/schema/response.py +0 -0
  151. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight/util.py +0 -0
  152. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight.egg-info/dependency_links.txt +0 -0
  153. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight.egg-info/requires.txt +0 -0
  154. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/src/nnsight.egg-info/top_level.txt +0 -0
  155. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/tests/__init__.py +0 -0
  156. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/tests/test_diffusion.py +0 -0
  157. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/tests/test_tiny.py +0 -0
  158. {nnsight-0.5.0.dev7 → nnsight-0.5.0.dev9}/tests/test_vllm.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nnsight
3
- Version: 0.5.0.dev7
3
+ Version: 0.5.0.dev9
4
4
  Summary: Package for interpreting and manipulating the internals of deep learning models.
5
5
  Author-email: Jaden Fiotto-Kaufman <jadenfk@outlook.com>
6
6
  License: MIT License
@@ -95,6 +95,29 @@ def wrap_autocast(func):
95
95
  DEFAULT_PATCHER.add(Patch(autocast, wrap_autocast(autocast.__init__), "__init__"))
96
96
 
97
97
 
98
+ from torch import Tensor
99
+ from .intervention.tracing.backwards import BackwardsTracer
100
+ from .intervention.tracing.base import WithBlockNotFoundError
101
+
102
+ def wrap_backward(func):
103
+
104
+ @wraps(func)
105
+ def inner(tensor: Tensor, *args, **kwargs):
106
+
107
+ try:
108
+
109
+ tracer = BackwardsTracer(tensor, func, *args, **kwargs)
110
+
111
+ except WithBlockNotFoundError:
112
+
113
+ return func(tensor, *args, **kwargs)
114
+
115
+ return tracer
116
+
117
+ return inner
118
+
119
+ DEFAULT_PATCHER.add(Patch(Tensor, wrap_backward(Tensor.backward), "backward"))
120
+
98
121
  DEFAULT_PATCHER.__enter__()
99
122
 
100
123
 
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  import inspect
4
4
  import os
5
5
  import warnings
6
+ from functools import wraps
6
7
  from types import BuiltinFunctionType, BuiltinMethodType, FunctionType, MethodType
7
8
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union
8
9
 
@@ -26,6 +27,19 @@ else:
26
27
  Interleaver = Any
27
28
 
28
29
 
30
+ def trace_only(fn: Callable):
31
+
32
+ @wraps(fn)
33
+ def wrapper(self: Envoy, *args, **kwargs):
34
+
35
+ if self._interleaver is None:
36
+ raise ValueError(f"Must be within a trace to use `.{fn.__name__}(...)`")
37
+
38
+ return fn(self, *args, **kwargs)
39
+
40
+ return wrapper
41
+
42
+
29
43
  class Envoy(Batchable):
30
44
  """
31
45
  A proxy class that wraps a PyTorch module to enable intervention during execution.
@@ -542,14 +556,17 @@ class Envoy(Batchable):
542
556
  # TODO legacy
543
557
  @property
544
558
  @deprecated(message="Use `tracer.iter` instead.")
559
+ @trace_only
545
560
  def iter(self):
546
561
  return IteratorProxy(self._interleaver)
547
562
 
548
563
  # TODO legacy
549
564
  @deprecated(message="Use `tracer.all()` instead.")
565
+ @trace_only
550
566
  def all(self):
551
567
  return self.iter[:]
552
568
 
569
+ @trace_only
553
570
  def skip(self, replacement: Any):
554
571
  """Skips the execution of this module duting execution / interleaving.
555
572
  Behavior is the module will not be executed and will return a replacement value instead.
@@ -570,12 +587,14 @@ class Envoy(Batchable):
570
587
 
571
588
  self._interleaver.current.skip(requester, replacement)
572
589
 
590
+ @trace_only
573
591
  def wait_for_input(self):
574
592
  """
575
593
  Wait for the input to the module to be available.
576
594
  """
577
595
  self.inputs
578
596
 
597
+ @trace_only
579
598
  def wait_for_output(self):
580
599
  """
581
600
  Wait for the output to the module to be available.
@@ -710,7 +729,7 @@ class Envoy(Batchable):
710
729
 
711
730
  #### Private methods ####
712
731
 
713
- def _add_envoy(self, module: torch.nn.Module, name: str) -> None:
732
+ def _add_envoy(self, module: torch.nn.Module, name: str) -> Envoy:
714
733
  """
715
734
  Adds a new Envoy for a given torch module under this Envoy.
716
735
 
@@ -741,6 +760,8 @@ class Envoy(Batchable):
741
760
  else:
742
761
  super().__setattr__(name, envoy)
743
762
 
763
+ return envoy
764
+
744
765
  def _handle_overloaded_mount(self, envoy: Envoy, mount_point: str) -> None:
745
766
  """If a given module already has an attribute of the same name as something nnsight wants to add, we need to rename it.
746
767
 
@@ -1025,6 +1046,15 @@ class Envoy(Batchable):
1025
1046
  return value(*args, **kwargs)
1026
1047
 
1027
1048
  return trace
1049
+
1050
+ elif isinstance(value, torch.nn.Module):
1051
+ # If the _module has a module in its __dict__ but wasn't picked up when creating the Envoy,
1052
+ # Hopefully it is alrady an Envoy somewhere in the tree.
1053
+ # https://github.com/ndif-team/nnsight/issues/479
1054
+ # This happened because some transformers models set this class attr: _checkpoint_conversion_mapping
1055
+ if hasattr(value, "__path__"):
1056
+ return util.fetch_attr(self, value.__path__[len(self.path) :])
1057
+ return self._add_envoy(value, name)
1028
1058
  else:
1029
1059
  return value
1030
1060
  else:
@@ -1225,21 +1255,22 @@ class OperationEnvoy:
1225
1255
 
1226
1256
  if self._source is None:
1227
1257
  fn = self._interleaver.current.request(f"{self.name}.fn")
1228
-
1229
- #TODO maybe do something else here
1258
+
1259
+ # TODO maybe do something else here
1230
1260
  if isinstance(fn, torch.nn.Module):
1231
-
1261
+
1232
1262
  msg = f"Don't call .source on a module ({getattr(fn, '__path__', '')}) from within another .source. Call it directly with: {getattr(fn, '__path__', '')}.source"
1233
1263
  raise ValueError(msg)
1234
1264
 
1235
1265
  def wrap(fn: Callable, **kwargs):
1236
-
1266
+
1237
1267
  bound_obj = (
1238
1268
  fn.__self__
1239
- if getattr(fn, "__name__", None) != "forward" and inspect.ismethod(fn)
1269
+ if getattr(fn, "__name__", None) != "forward"
1270
+ and inspect.ismethod(fn)
1240
1271
  else None
1241
1272
  )
1242
-
1273
+
1243
1274
  return self._interleaver.wrap_operation(
1244
1275
  fn, **kwargs, bound_obj=bound_obj
1245
1276
  )
@@ -1252,7 +1283,8 @@ class OperationEnvoy:
1252
1283
 
1253
1284
  self._fn = fn
1254
1285
 
1255
- self._interleaver.current.swap(f"{self.name}.fn", self._fn)
1286
+ if f"{self.name}.fn" not in self._interleaver.current.history:
1287
+ self._interleaver.current.swap(f"{self.name}.fn", self._fn)
1256
1288
 
1257
1289
  return self._source
1258
1290