nnsight 0.5.0.dev5__tar.gz → 0.5.0.dev7__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 (156) hide show
  1. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/PKG-INFO +1 -1
  2. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/__init__.py +29 -6
  3. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/_c/py_mount.c +1 -15
  4. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/envoy.py +9 -3
  5. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/interleaver.py +3 -0
  6. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/tracing/base.py +47 -30
  7. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight.egg-info/PKG-INFO +1 -1
  8. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/.github/workflows/publish.yml +0 -0
  9. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/.github/workflows/python-app.yml +0 -0
  10. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/.gitignore +0 -0
  11. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/CHANGELOG.md +0 -0
  12. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/CODE_OF_CONDUCT.md +0 -0
  13. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/LICENSE +0 -0
  14. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/NNsight_Walkthrough.ipynb +0 -0
  15. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/NNsight_v0_3_guide.ipynb +0 -0
  16. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/NNsight_v0_4_guide.ipynb +0 -0
  17. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/README.md +0 -0
  18. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/conftest.py +0 -0
  19. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/.DS_Store +0 -0
  20. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/Makefile +0 -0
  21. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/contributing.md +0 -0
  22. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/make.bat +0 -0
  23. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/requirements.txt +0 -0
  24. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/.DS_Store +0 -0
  25. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/.DS_Store +0 -0
  26. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/css/custom.css +0 -0
  27. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/css/home.css +0 -0
  28. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/css/pygments.css +0 -0
  29. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/css/status.css +0 -0
  30. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/.DS_Store +0 -0
  31. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/execution.png +0 -0
  32. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/icon.ico +0 -0
  33. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/interleaved.png +0 -0
  34. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/ioi.png +0 -0
  35. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/nnsight_logo.svg +0 -0
  36. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/tutorials/.DS_Store +0 -0
  37. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/tutorials/activation_patching.webp +0 -0
  38. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/tutorials/attribution_patching.webp +0 -0
  39. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/tutorials/dictionary_learning.webp +0 -0
  40. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/tutorials/function_vectors.webp +0 -0
  41. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/tutorials/future_lens.webp +0 -0
  42. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/tutorials/logit_lens.webp +0 -0
  43. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/images/tutorials/walkthrough.webp +0 -0
  44. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/js/.DS_Store +0 -0
  45. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/js/code.js +0 -0
  46. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_static/js/custom.js +0 -0
  47. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_templates/layout.html +0 -0
  48. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/_templates/ndif_status.html +0 -0
  49. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/about.rst +0 -0
  50. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/conf.py +0 -0
  51. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/documentation/intervention.rst +0 -0
  52. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/documentation/modeling.rst +0 -0
  53. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/documentation/schema.rst +0 -0
  54. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/documentation/tracing.rst +0 -0
  55. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/documentation/util.rst +0 -0
  56. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/documentation.rst +0 -0
  57. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/features.rst +0 -0
  58. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/index.rst +0 -0
  59. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/conditionals.ipynb +0 -0
  60. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/cross_prompt.ipynb +0 -0
  61. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/custom_functions.ipynb +0 -0
  62. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/early_stopping.ipynb +0 -0
  63. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/editing_tutorial.ipynb +0 -0
  64. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/getting.ipynb +0 -0
  65. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/gradients.ipynb +0 -0
  66. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/iterator.ipynb +0 -0
  67. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/lora_training.ipynb +0 -0
  68. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/model_editing.ipynb +0 -0
  69. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/modules.ipynb +0 -0
  70. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/multiple_token.ipynb +0 -0
  71. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/operations.ipynb +0 -0
  72. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/remote_execution.ipynb +0 -0
  73. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/scan_validate.ipynb +0 -0
  74. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/sessions.ipynb +0 -0
  75. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/setting.ipynb +0 -0
  76. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/streaming.ipynb +0 -0
  77. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/features/vllm_support.ipynb +0 -0
  78. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/LoRA_tutorial.ipynb +0 -0
  79. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/activation_patching.ipynb +0 -0
  80. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/attribution_patching.ipynb +0 -0
  81. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/boundless_DAS.ipynb +0 -0
  82. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/dict_learning.ipynb +0 -0
  83. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/diffusion_lens.ipynb +0 -0
  84. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/images/Activation_patching-figure1.png +0 -0
  85. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/images/LoRA_tutorial_figure_1.png +0 -0
  86. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/images/LoRA_tutorial_figure_2.png +0 -0
  87. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/logit_lens.ipynb +0 -0
  88. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/start_remote_access.ipynb +0 -0
  89. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/tutorial_price_tagging_utils.py +0 -0
  90. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/notebooks/tutorials/walkthrough.ipynb +0 -0
  91. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/pages/home.html +0 -0
  92. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/start.rst +0 -0
  93. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/status.rst +0 -0
  94. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/source/tutorials.rst +0 -0
  95. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/sourcelatex/conf.py +0 -0
  96. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/sourcelatex/documentation/contexts.rst +0 -0
  97. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/sourcelatex/documentation/intervention.rst +0 -0
  98. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/sourcelatex/documentation/models.rst +0 -0
  99. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/sourcelatex/documentation/module.rst +0 -0
  100. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/sourcelatex/documentation/patching.rst +0 -0
  101. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/sourcelatex/documentation/tracing.rst +0 -0
  102. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/sourcelatex/documentation/util.rst +0 -0
  103. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/docs/sourcelatex/index.rst +0 -0
  104. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/pyproject.toml +0 -0
  105. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/pytest.ini +0 -0
  106. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/setup.cfg +0 -0
  107. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/setup.py +0 -0
  108. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/_c/__init__.py +0 -0
  109. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/config.yaml +0 -0
  110. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/__init__.py +0 -0
  111. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/backends/__init__.py +0 -0
  112. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/backends/base.py +0 -0
  113. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/backends/editing.py +0 -0
  114. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/backends/execution.py +0 -0
  115. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/backends/remote.py +0 -0
  116. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/batching.py +0 -0
  117. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/inject.py +0 -0
  118. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/serialization.py +0 -0
  119. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/tracing/__init__.py +0 -0
  120. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/tracing/backwards.py +0 -0
  121. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/tracing/editing.py +0 -0
  122. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/tracing/globals.py +0 -0
  123. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/tracing/invoker.py +0 -0
  124. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/tracing/iterator.py +0 -0
  125. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/tracing/tracer.py +0 -0
  126. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/intervention/tracing/util.py +0 -0
  127. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/log.py +0 -0
  128. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/__init__.py +0 -0
  129. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/base.py +0 -0
  130. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/diffusion.py +0 -0
  131. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/language.py +0 -0
  132. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/mixins/__init__.py +0 -0
  133. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/mixins/loadable.py +0 -0
  134. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/mixins/meta.py +0 -0
  135. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/mixins/remoteable.py +0 -0
  136. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/vllm/__init__.py +0 -0
  137. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/vllm/model_runners/GPUModelRunner.py +0 -0
  138. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/vllm/model_runners/__init__.py +0 -0
  139. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/vllm/sampling.py +0 -0
  140. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/vllm/vllm.py +0 -0
  141. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/vllm/workers/GPUWorker.py +0 -0
  142. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/modeling/vllm/workers/__init__.py +0 -0
  143. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/schema/__init__.py +0 -0
  144. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/schema/config.py +0 -0
  145. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/schema/request.py +0 -0
  146. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/schema/response.py +0 -0
  147. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight/util.py +0 -0
  148. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight.egg-info/SOURCES.txt +0 -0
  149. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight.egg-info/dependency_links.txt +0 -0
  150. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight.egg-info/requires.txt +0 -0
  151. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/src/nnsight.egg-info/top_level.txt +0 -0
  152. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/tests/__init__.py +0 -0
  153. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/tests/test_diffusion.py +0 -0
  154. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/tests/test_lm.py +0 -0
  155. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/tests/test_tiny.py +0 -0
  156. {nnsight-0.5.0.dev5 → nnsight-0.5.0.dev7}/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.dev5
3
+ Version: 0.5.0.dev7
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
@@ -1,5 +1,6 @@
1
1
  from functools import wraps
2
- import os, yaml
2
+ import inspect
3
+ import os, yaml, sys
3
4
  import warnings
4
5
  from typing import Optional
5
6
  from .schema.config import ConfigModel
@@ -22,6 +23,8 @@ try:
22
23
  except NameError:
23
24
  __IPYTHON__ = False
24
25
 
26
+ __INTERACTIVE__ = (sys.flags.interactive or not sys.argv[0]) and not __IPYTHON__
27
+
25
28
  base_deprecation_message = "is deprecated as of v0.5.0 and will be removed in a future version."
26
29
 
27
30
  def deprecated(message:Optional[str]=None, error:bool=False):
@@ -142,9 +145,29 @@ str = deprecated(message="Use the standard `str()` instead.")(str)
142
145
  tuple = deprecated(message="Use the standard `tuple()` instead.")(tuple)
143
146
  bytearray = deprecated(message="Use the standard `bytearray()` instead.")(bytearray)
144
147
 
148
+ if __INTERACTIVE__:
149
+ from code import InteractiveConsole
150
+ import readline
151
+
152
+ # We need to use our own console so when we trace, we can get the source code from the buffer of our custom console.
153
+ class NNsightConsole(InteractiveConsole):
154
+ pass
155
+
156
+ # We want the new console to have the locals of the interactive frame the user is already in.
157
+ frame = inspect.currentframe()
158
+
159
+ while frame.f_back:
160
+ frame = frame.f_back
161
+
162
+ # This was kicked off by importing nnsight, but upon entering the new console, we wont actually have the import in the new locals.
163
+ # So we need to get the last command from the history and execute it in the new locals.
164
+ length = readline.get_current_history_length()
165
+ l1 = readline.get_history_item(length)
166
+ ilocals = {**frame.f_locals}
167
+ exec(l1, frame.f_globals, ilocals)
168
+
169
+ __INTERACTIVE_CONSOLE__ = NNsightConsole(filename="<nnsight-console>", locals=ilocals)
170
+ __INTERACTIVE_CONSOLE__.interact(banner="")
145
171
 
146
-
147
-
148
-
149
-
150
-
172
+ else:
173
+ __INTERACTIVE_CONSOLE__ = None
@@ -98,17 +98,7 @@ static PyObject* unmount_function(PyObject* self, PyObject* args) {
98
98
  Py_RETURN_NONE;
99
99
  }
100
100
 
101
- // Cleanup function for mounted functions
102
- static void cleanup_mounted_functions(void) {
103
- for (int i = 0; i < num_mounted_functions; i++) {
104
- Py_XDECREF(mounted_functions[i].func);
105
- free(mounted_functions[i].name);
106
- }
107
- PyMem_Free(mounted_functions);
108
- mounted_functions = NULL;
109
- num_mounted_functions = 0;
110
- mounted_functions_capacity = 0;
111
- }
101
+
112
102
 
113
103
  // Method definitions
114
104
  static PyMethodDef module_methods[] = {
@@ -134,10 +124,6 @@ PyMODINIT_FUNC PyInit_py_mount(void) {
134
124
  };
135
125
 
136
126
  PyObject* module = PyModule_Create(&def);
137
- if (module) {
138
- // Register cleanup function
139
- Py_AtExit(cleanup_mounted_functions);
140
- }
141
127
 
142
128
  return module;
143
129
  }
@@ -1225,15 +1225,21 @@ class OperationEnvoy:
1225
1225
 
1226
1226
  if self._source is None:
1227
1227
  fn = self._interleaver.current.request(f"{self.name}.fn")
1228
+
1229
+ #TODO maybe do something else here
1230
+ if isinstance(fn, torch.nn.Module):
1231
+
1232
+ 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
+ raise ValueError(msg)
1228
1234
 
1229
1235
  def wrap(fn: Callable, **kwargs):
1230
-
1236
+
1231
1237
  bound_obj = (
1232
1238
  fn.__self__
1233
- if fn.__name__ != "forward" and inspect.ismethod(fn)
1239
+ if getattr(fn, "__name__", None) != "forward" and inspect.ismethod(fn)
1234
1240
  else None
1235
1241
  )
1236
-
1242
+
1237
1243
  return self._interleaver.wrap_operation(
1238
1244
  fn, **kwargs, bound_obj=bound_obj
1239
1245
  )
@@ -110,6 +110,9 @@ class Interleaver:
110
110
 
111
111
  @wraps(fn)
112
112
  def inner(module: torch.nn.Module, *args, **kwargs):
113
+
114
+ if torch.compiler.is_compiling():
115
+ return fn(module, *args, **kwargs)
113
116
 
114
117
  if not hasattr(module, "__path__"):
115
118
  return fn(module, *args, **kwargs)
@@ -58,7 +58,12 @@ class Tracer:
58
58
  """
59
59
 
60
60
  def __init__(
61
- self, source: List[str], frame: FrameType, start_line: int, node:ast.With, filename: str = None
61
+ self,
62
+ source: List[str],
63
+ frame: FrameType,
64
+ start_line: int,
65
+ node: ast.With,
66
+ filename: str = None,
62
67
  ):
63
68
  """
64
69
  Initialize Info with source code and frame information.
@@ -73,11 +78,15 @@ class Tracer:
73
78
  self.frame = frame
74
79
  self.start_line = start_line
75
80
  self.node = node
76
- self.filename = filename if filename is not None else f"<nnsight {id(self)}>"
77
-
81
+ self.filename = (
82
+ filename if filename is not None else f"<nnsight {id(self)}>"
83
+ )
84
+
78
85
  def copy(self):
79
- return Tracer.Info(self.source, self.frame, self.start_line, self.node, self.filename)
80
-
86
+ return Tracer.Info(
87
+ self.source, self.frame, self.start_line, self.node, self.filename
88
+ )
89
+
81
90
  def __getstate__(self):
82
91
  """Get the state of the info for serialization."""
83
92
  return {
@@ -86,17 +95,17 @@ class Tracer:
86
95
  "filename": self.filename,
87
96
  "frame": self.frame,
88
97
  }
89
-
98
+
90
99
  def __setstate__(self, state):
91
100
  """Set the state of the info for deserialization."""
92
101
  self.source = state["source"]
93
102
  self.start_line = state["start_line"]
94
103
  self.filename = state["filename"]
95
104
  self.frame = state["frame"]
96
-
105
+
97
106
  self.node = None
98
107
 
99
- def __init__(self, *args, backend: Backend = None, _info:Info = None, **kwargs):
108
+ def __init__(self, *args, backend: Backend = None, _info: Info = None, **kwargs):
100
109
  """
101
110
  Initialize a Tracer instance.
102
111
 
@@ -113,7 +122,7 @@ class Tracer:
113
122
 
114
123
  self.info = _info if _info is not None else None
115
124
 
116
- if self.info is None:
125
+ if self.info is None:
117
126
  self.capture()
118
127
 
119
128
  def capture(self):
@@ -127,7 +136,7 @@ class Tracer:
127
136
  """
128
137
  # Find the frame outside of nnsight by walking up the call stack
129
138
  frame = inspect.currentframe()
130
-
139
+
131
140
  while frame:
132
141
  frame = frame.f_back
133
142
  if frame and (
@@ -139,10 +148,12 @@ class Tracer:
139
148
  # Get source code lines from the appropriate location
140
149
  start_line = frame.f_lineno
141
150
 
151
+ # CASE 1: Were already inside of another nnsight trace.
142
152
  if "__nnsight_tracing_info__" in frame.f_locals:
143
153
  # For dynamically generated code, get source from tracing info
144
154
  source_lines = frame.f_locals["__nnsight_tracing_info__"].source
145
155
 
156
+ # CASE 2: We're in an IPython console.
146
157
  elif "_ih" in frame.f_locals:
147
158
  import IPython
148
159
 
@@ -152,12 +163,24 @@ class Tracer:
152
163
  if not source_lines[-1].endswith("\n"):
153
164
  source_lines[-1] += "\n"
154
165
 
166
+ # CASE 3: We're in a regular Python file.
155
167
  elif not frame.f_code.co_filename.startswith("<nnsight"):
156
168
  # For regular files, get source lines using inspect
157
169
  source_lines, offset = inspect.getsourcelines(frame)
158
170
 
159
171
  start_line = start_line if offset == 0 else start_line - offset + 1
160
172
 
173
+ # CASE 4: We're in a regular Python interactive console.
174
+ elif frame.f_code.co_filename == "<nnsight-console>":
175
+ from ... import __INTERACTIVE_CONSOLE__
176
+
177
+ source_lines = __INTERACTIVE_CONSOLE__.buffer
178
+ # Add newline to each source line if it doesn't end with one
179
+ source_lines = [
180
+ line if line.endswith("\n") else line + "\n" for line in source_lines
181
+ ]
182
+
183
+
161
184
  else:
162
185
  raise ValueError("No source code found")
163
186
 
@@ -166,10 +189,10 @@ class Tracer:
166
189
  "\t "
167
190
  ) # indent for removing leading tabs/spaces
168
191
  indent = len(source_lines[0]) - len(stripped)
169
-
192
+
170
193
  # If theres an indent, we need to remove it. This handles the case of say a trace in an indented function. E.x. a trace inside a method on a class.
171
194
  if indent > 0:
172
-
195
+
173
196
  source_lines = [
174
197
  line[indent:] if line.strip() else line for line in source_lines
175
198
  ]
@@ -178,22 +201,18 @@ class Tracer:
178
201
  start_line, source_lines, node = self.parse(source_lines, start_line)
179
202
 
180
203
  # Calculate indentation level of the Tracer creation line.
181
- stripped = source_lines[0].lstrip(
182
- "\t "
183
- ) # removes leading tabs/spaces
204
+ stripped = source_lines[0].lstrip("\t ") # removes leading tabs/spaces
184
205
  indent = len(source_lines[0]) - len(stripped) - 4
185
-
186
- # If theres an indent (more than just the indentation of the with block), we need to remove it. This handles the case of say a trace in an indented block. E.x. a trace inside a for loop or another with block.
206
+
207
+ # If theres an indent (more than just the indentation of the with block), we need to remove it. This handles the case of say a trace in an indented block. E.x. a trace inside a for loop or another with block.
187
208
  if indent > 0:
188
-
209
+
189
210
  source_lines = [
190
211
  line[indent:] if line.strip() else line for line in source_lines
191
212
  ]
192
213
 
193
214
  # Store the captured information for later use
194
- self.info = Tracer.Info(
195
- source_lines, frame, start_line, node
196
- )
215
+ self.info = Tracer.Info(source_lines, frame, start_line, node)
197
216
 
198
217
  def parse(self, source_lines, start_line):
199
218
  """
@@ -233,7 +252,7 @@ class Tracer:
233
252
  raise WithBlockNotFoundError(f"With block not found at line {start_line}")
234
253
 
235
254
  end_line = visitor.target.end_lineno
236
-
255
+
237
256
  start_line = visitor.target.body[0].lineno - 1
238
257
 
239
258
  return start_line, source_lines[start_line:end_line], visitor.target
@@ -318,9 +337,8 @@ class Tracer:
318
337
  ctypes.pythonapi.PyFrame_LocalsToFast(
319
338
  ctypes.py_object(frame), ctypes.c_int(0)
320
339
  )
321
-
340
+
322
341
  state.clear()
323
-
324
342
 
325
343
  def __enter__(self):
326
344
  """
@@ -335,7 +353,7 @@ class Tracer:
335
353
 
336
354
  if self.info is None:
337
355
  self.capture()
338
-
356
+
339
357
  if isinstance(self.info.node.body[0], ast.Pass):
340
358
  return self
341
359
 
@@ -390,11 +408,11 @@ class Tracer:
390
408
  self.backend(self)
391
409
 
392
410
  return True
393
-
411
+
394
412
  self.backend(self)
395
-
413
+
396
414
  ### Serialization ###
397
-
415
+
398
416
  def __getstate__(self):
399
417
  """Get the state of the tracer for serialization."""
400
418
  return {
@@ -402,7 +420,7 @@ class Tracer:
402
420
  "kwargs": self.kwargs,
403
421
  "info": self.info,
404
422
  }
405
-
423
+
406
424
  def __setstate__(self, state):
407
425
  """Set the state of the tracer for deserialization."""
408
426
  self.args = state["args"]
@@ -410,4 +428,3 @@ class Tracer:
410
428
  self.info = state["info"]
411
429
  self.info.start_line = 0
412
430
  self.backend = ExecutionBackend()
413
-
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nnsight
3
- Version: 0.5.0.dev5
3
+ Version: 0.5.0.dev7
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes