nnsight 0.5.0.dev3__tar.gz → 0.5.0.dev5__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.dev3 → nnsight-0.5.0.dev5}/PKG-INFO +1 -1
  2. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/_c/py_mount.c +14 -29
  3. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/envoy.py +59 -2
  4. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/tracing/base.py +5 -0
  5. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight.egg-info/PKG-INFO +1 -1
  6. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/.github/workflows/publish.yml +0 -0
  7. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/.github/workflows/python-app.yml +0 -0
  8. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/.gitignore +0 -0
  9. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/CHANGELOG.md +0 -0
  10. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/CODE_OF_CONDUCT.md +0 -0
  11. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/LICENSE +0 -0
  12. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/NNsight_Walkthrough.ipynb +0 -0
  13. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/NNsight_v0_3_guide.ipynb +0 -0
  14. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/NNsight_v0_4_guide.ipynb +0 -0
  15. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/README.md +0 -0
  16. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/conftest.py +0 -0
  17. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/.DS_Store +0 -0
  18. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/Makefile +0 -0
  19. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/contributing.md +0 -0
  20. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/make.bat +0 -0
  21. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/requirements.txt +0 -0
  22. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/.DS_Store +0 -0
  23. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/.DS_Store +0 -0
  24. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/css/custom.css +0 -0
  25. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/css/home.css +0 -0
  26. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/css/pygments.css +0 -0
  27. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/css/status.css +0 -0
  28. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/.DS_Store +0 -0
  29. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/execution.png +0 -0
  30. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/icon.ico +0 -0
  31. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/interleaved.png +0 -0
  32. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/ioi.png +0 -0
  33. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/nnsight_logo.svg +0 -0
  34. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/tutorials/.DS_Store +0 -0
  35. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/tutorials/activation_patching.webp +0 -0
  36. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/tutorials/attribution_patching.webp +0 -0
  37. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/tutorials/dictionary_learning.webp +0 -0
  38. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/tutorials/function_vectors.webp +0 -0
  39. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/tutorials/future_lens.webp +0 -0
  40. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/tutorials/logit_lens.webp +0 -0
  41. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/images/tutorials/walkthrough.webp +0 -0
  42. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/js/.DS_Store +0 -0
  43. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/js/code.js +0 -0
  44. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_static/js/custom.js +0 -0
  45. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_templates/layout.html +0 -0
  46. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/_templates/ndif_status.html +0 -0
  47. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/about.rst +0 -0
  48. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/conf.py +0 -0
  49. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/documentation/intervention.rst +0 -0
  50. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/documentation/modeling.rst +0 -0
  51. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/documentation/schema.rst +0 -0
  52. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/documentation/tracing.rst +0 -0
  53. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/documentation/util.rst +0 -0
  54. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/documentation.rst +0 -0
  55. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/features.rst +0 -0
  56. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/index.rst +0 -0
  57. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/conditionals.ipynb +0 -0
  58. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/cross_prompt.ipynb +0 -0
  59. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/custom_functions.ipynb +0 -0
  60. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/early_stopping.ipynb +0 -0
  61. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/editing_tutorial.ipynb +0 -0
  62. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/getting.ipynb +0 -0
  63. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/gradients.ipynb +0 -0
  64. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/iterator.ipynb +0 -0
  65. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/lora_training.ipynb +0 -0
  66. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/model_editing.ipynb +0 -0
  67. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/modules.ipynb +0 -0
  68. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/multiple_token.ipynb +0 -0
  69. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/operations.ipynb +0 -0
  70. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/remote_execution.ipynb +0 -0
  71. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/scan_validate.ipynb +0 -0
  72. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/sessions.ipynb +0 -0
  73. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/setting.ipynb +0 -0
  74. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/streaming.ipynb +0 -0
  75. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/features/vllm_support.ipynb +0 -0
  76. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/LoRA_tutorial.ipynb +0 -0
  77. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/activation_patching.ipynb +0 -0
  78. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/attribution_patching.ipynb +0 -0
  79. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/boundless_DAS.ipynb +0 -0
  80. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/dict_learning.ipynb +0 -0
  81. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/diffusion_lens.ipynb +0 -0
  82. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/images/Activation_patching-figure1.png +0 -0
  83. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/images/LoRA_tutorial_figure_1.png +0 -0
  84. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/images/LoRA_tutorial_figure_2.png +0 -0
  85. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/logit_lens.ipynb +0 -0
  86. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/start_remote_access.ipynb +0 -0
  87. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/tutorial_price_tagging_utils.py +0 -0
  88. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/notebooks/tutorials/walkthrough.ipynb +0 -0
  89. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/pages/home.html +0 -0
  90. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/start.rst +0 -0
  91. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/status.rst +0 -0
  92. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/source/tutorials.rst +0 -0
  93. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/sourcelatex/conf.py +0 -0
  94. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/sourcelatex/documentation/contexts.rst +0 -0
  95. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/sourcelatex/documentation/intervention.rst +0 -0
  96. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/sourcelatex/documentation/models.rst +0 -0
  97. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/sourcelatex/documentation/module.rst +0 -0
  98. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/sourcelatex/documentation/patching.rst +0 -0
  99. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/sourcelatex/documentation/tracing.rst +0 -0
  100. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/sourcelatex/documentation/util.rst +0 -0
  101. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/docs/sourcelatex/index.rst +0 -0
  102. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/pyproject.toml +0 -0
  103. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/pytest.ini +0 -0
  104. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/setup.cfg +0 -0
  105. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/setup.py +0 -0
  106. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/__init__.py +0 -0
  107. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/_c/__init__.py +0 -0
  108. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/config.yaml +0 -0
  109. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/__init__.py +0 -0
  110. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/backends/__init__.py +0 -0
  111. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/backends/base.py +0 -0
  112. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/backends/editing.py +0 -0
  113. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/backends/execution.py +0 -0
  114. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/backends/remote.py +0 -0
  115. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/batching.py +0 -0
  116. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/inject.py +0 -0
  117. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/interleaver.py +0 -0
  118. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/serialization.py +0 -0
  119. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/tracing/__init__.py +0 -0
  120. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/tracing/backwards.py +0 -0
  121. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/tracing/editing.py +0 -0
  122. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/tracing/globals.py +0 -0
  123. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/tracing/invoker.py +0 -0
  124. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/tracing/iterator.py +0 -0
  125. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/tracing/tracer.py +0 -0
  126. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/intervention/tracing/util.py +0 -0
  127. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/log.py +0 -0
  128. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/__init__.py +0 -0
  129. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/base.py +0 -0
  130. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/diffusion.py +0 -0
  131. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/language.py +0 -0
  132. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/mixins/__init__.py +0 -0
  133. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/mixins/loadable.py +0 -0
  134. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/mixins/meta.py +0 -0
  135. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/mixins/remoteable.py +0 -0
  136. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/vllm/__init__.py +0 -0
  137. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/vllm/model_runners/GPUModelRunner.py +0 -0
  138. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/vllm/model_runners/__init__.py +0 -0
  139. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/vllm/sampling.py +0 -0
  140. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/vllm/vllm.py +0 -0
  141. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/vllm/workers/GPUWorker.py +0 -0
  142. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/modeling/vllm/workers/__init__.py +0 -0
  143. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/schema/__init__.py +0 -0
  144. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/schema/config.py +0 -0
  145. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/schema/request.py +0 -0
  146. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/schema/response.py +0 -0
  147. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight/util.py +0 -0
  148. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight.egg-info/SOURCES.txt +0 -0
  149. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight.egg-info/dependency_links.txt +0 -0
  150. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight.egg-info/requires.txt +0 -0
  151. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/src/nnsight.egg-info/top_level.txt +0 -0
  152. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/tests/__init__.py +0 -0
  153. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/tests/test_diffusion.py +0 -0
  154. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/tests/test_lm.py +0 -0
  155. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/tests/test_tiny.py +0 -0
  156. {nnsight-0.5.0.dev3 → nnsight-0.5.0.dev5}/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.dev3
3
+ Version: 0.5.0.dev5
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
@@ -13,6 +13,15 @@ static MountedFunction* mounted_functions = NULL;
13
13
  static int num_mounted_functions = 0;
14
14
  static int mounted_functions_capacity = 0;
15
15
 
16
+ static PyObject* get_dict(PyTypeObject* type) {
17
+ #if PY_VERSION_HEX < 0x030C0000
18
+ PyObject* dict = type->tp_dict;
19
+ #else
20
+ PyObject* dict = PyType_GetDict(type);
21
+ #endif
22
+ return dict;
23
+ }
24
+
16
25
  // Function to mount a new function
17
26
  static PyObject* mount_function(PyObject* self, PyObject* args) {
18
27
  PyObject* func;
@@ -45,36 +54,11 @@ static PyObject* mount_function(PyObject* self, PyObject* args) {
45
54
  mounted_functions[num_mounted_functions].func = func;
46
55
  mounted_functions[num_mounted_functions].name = strdup(mount_point);
47
56
  num_mounted_functions++;
48
- // Inject into all currently loaded types
49
- // PyObject* modules = PyImport_GetModuleDict();
50
- // PyObject* key, *value;
51
- // Py_ssize_t pos = 0;
52
-
53
- // while (PyDict_Next(modules, &pos, &key, &value)) {
54
- // if (!PyModule_Check(value)) continue;
55
-
56
- // PyObject* module_dict = PyModule_GetDict(value);
57
- // if (!module_dict) continue;
58
-
59
- // PyObject* item_key, *item_value;
60
- // Py_ssize_t item_pos = 0;
61
- // while (PyDict_Next(module_dict, &item_pos, &item_key, &item_value)) {
62
- // if (PyType_Check(item_value)) {
63
- // PyTypeObject* type = (PyTypeObject*)item_value;
64
-
65
- // // Create an instance method
66
- // PyObject* method = PyInstanceMethod_New(func);
67
- // if (method) {
68
- // PyDict_SetItemString(type->tp_dict, mount_point, method);
69
- // Py_DECREF(method);
70
- // PyType_Modified(type);
71
- // }
72
- // }
73
- // }
74
- // Mount only on the base object type
57
+
75
58
  PyObject* method = PyInstanceMethod_New(func);
76
59
  if (method) {
77
- PyDict_SetItemString(PyBaseObject_Type.tp_dict, mount_point, method);
60
+ PyObject *dict = get_dict(&PyBaseObject_Type);
61
+ PyDict_SetItemString(dict, mount_point, method);
78
62
  Py_DECREF(method);
79
63
  PyType_Modified(&PyBaseObject_Type);
80
64
  }
@@ -91,7 +75,8 @@ static PyObject* unmount_function(PyObject* self, PyObject* args) {
91
75
  }
92
76
 
93
77
  // Remove from base object type
94
- PyDict_DelItemString(PyBaseObject_Type.tp_dict, mount_point);
78
+ PyObject *dict = get_dict(&PyBaseObject_Type);
79
+ PyDict_DelItemString(dict, mount_point);
95
80
  PyType_Modified(&PyBaseObject_Type);
96
81
 
97
82
  // Find and remove from our array
@@ -188,6 +188,7 @@ class Envoy(Batchable):
188
188
  The module's input values as a tuple of positional and keyword arguments. i.e (args, kwargs)
189
189
 
190
190
  """
191
+
191
192
  if self.interleaving:
192
193
  return self._interleaver.current.request(
193
194
  self._interleaver.current.iterate(f"{self.path}.input")
@@ -734,11 +735,60 @@ class Envoy(Batchable):
734
735
 
735
736
  # If the module already has a sub-module named 'input' or 'output',
736
737
  # mount the proxy access to 'nns_input' or 'nns_output instead.
738
+
737
739
  if hasattr(Envoy, name):
738
740
  self._handle_overloaded_mount(envoy, name)
739
741
  else:
740
742
  super().__setattr__(name, envoy)
741
743
 
744
+ def _handle_overloaded_mount(self, envoy: Envoy, mount_point: str) -> None:
745
+ """If a given module already has an attribute of the same name as something nnsight wants to add, we need to rename it.
746
+
747
+ Directly edits the underlying class to accomplish this.
748
+
749
+ Args:
750
+ envoy (Envoy): Envoy to handle.
751
+ mount_point (str): Overloaded attribute name.
752
+ """
753
+
754
+ warnings.warn(
755
+ f"Module `{self.path}` of type `{type(self._module)}` has pre-defined a `{mount_point}` attribute. nnsight access for `{mount_point}` will be mounted at `.nns_{mount_point}` instead of `.{mount_point}` for this module only."
756
+ )
757
+
758
+ # If we already shifted a mount point dont create another new class.
759
+ if "Preserved" in self.__class__.__name__:
760
+
761
+ new_cls = self.__class__
762
+
763
+ else:
764
+
765
+ new_cls = type(
766
+ f"{self.__class__.__name__}.Preserved",
767
+ (self.__class__,),
768
+ {},
769
+ )
770
+
771
+ self.__class__ = new_cls
772
+
773
+ # Get the normal proxy mount point
774
+ mount = getattr(Envoy, mount_point)
775
+
776
+ setattr(new_cls, f"nns_{mount_point}", mount)
777
+
778
+ if isinstance(mount, property):
779
+
780
+ mount = property(
781
+ lambda slf: slf.__dict__[mount_point],
782
+ mount.fset,
783
+ mount.fdel,
784
+ mount.__doc__,
785
+ )
786
+
787
+ setattr(new_cls, mount_point, mount)
788
+
789
+ # Move it to nns_<mount point>
790
+ self.__dict__[mount_point] = envoy
791
+
742
792
  def _update(self, module: torch.nn.Module) -> None:
743
793
  """Updates the ._model attribute using a new model of the same architecture.
744
794
  Used when loading the real weights (dispatching) and need to replace the underlying modules.
@@ -759,12 +809,19 @@ class Envoy(Batchable):
759
809
  self._module.__path__ = self.path
760
810
 
761
811
  if self._source is not None:
812
+
762
813
  def wrap(fn: Callable, **kwargs):
763
814
 
764
- bound_obj = fn.__self__ if inspect.ismethod(fn) and fn.__name__ != "forward" else None
815
+ bound_obj = (
816
+ fn.__self__
817
+ if inspect.ismethod(fn) and fn.__name__ != "forward"
818
+ else None
819
+ )
765
820
 
766
821
  if self.interleaving:
767
- return self._interleaver.wrap_operation(fn, **kwargs, bound_obj=bound_obj)
822
+ return self._interleaver.wrap_operation(
823
+ fn, **kwargs, bound_obj=bound_obj
824
+ )
768
825
  else:
769
826
  return fn
770
827
 
@@ -335,6 +335,9 @@ class Tracer:
335
335
 
336
336
  if self.info is None:
337
337
  self.capture()
338
+
339
+ if isinstance(self.info.node.body[0], ast.Pass):
340
+ return self
338
341
 
339
342
  def skip(new_frame, event, arg):
340
343
  """
@@ -388,6 +391,8 @@ class Tracer:
388
391
 
389
392
  return True
390
393
 
394
+ self.backend(self)
395
+
391
396
  ### Serialization ###
392
397
 
393
398
  def __getstate__(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nnsight
3
- Version: 0.5.0.dev3
3
+ Version: 0.5.0.dev5
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