nnsight 0.5.0.dev16__tar.gz → 0.5.2__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 (74) hide show
  1. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/PKG-INFO +2 -2
  2. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/pyproject.toml +1 -1
  3. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/__init__.py +35 -2
  4. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/serialization.py +7 -8
  5. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/tracing/base.py +11 -3
  6. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/schema/request.py +0 -1
  7. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight.egg-info/PKG-INFO +2 -2
  8. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight.egg-info/requires.txt +1 -1
  9. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/.github/workflows/publish.yml +0 -0
  10. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/.github/workflows/python-app.yml +0 -0
  11. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/.gitignore +0 -0
  12. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/CHANGELOG.md +0 -0
  13. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/CODE_OF_CONDUCT.md +0 -0
  14. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/LICENSE +0 -0
  15. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/NNsight_Walkthrough.ipynb +0 -0
  16. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/NNsight_v0_3_guide.ipynb +0 -0
  17. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/NNsight_v0_4_guide.ipynb +0 -0
  18. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/README.md +0 -0
  19. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/conftest.py +0 -0
  20. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/function_vectors_solutions.ipynb +0 -0
  21. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/pytest.ini +0 -0
  22. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/setup.cfg +0 -0
  23. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/setup.py +0 -0
  24. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/_c/__init__.py +0 -0
  25. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/_c/py_mount.c +0 -0
  26. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/config.yaml +0 -0
  27. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/__init__.py +0 -0
  28. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/backends/__init__.py +0 -0
  29. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/backends/base.py +0 -0
  30. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/backends/editing.py +0 -0
  31. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/backends/execution.py +0 -0
  32. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/backends/remote.py +0 -0
  33. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/batching.py +0 -0
  34. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/envoy.py +0 -0
  35. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/inject.py +0 -0
  36. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/interleaver.py +0 -0
  37. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/tracing/__init__.py +0 -0
  38. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/tracing/backwards.py +0 -0
  39. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/tracing/editing.py +0 -0
  40. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/tracing/globals.py +0 -0
  41. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/tracing/invoker.py +0 -0
  42. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/tracing/iterator.py +0 -0
  43. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/tracing/tracer.py +0 -0
  44. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/intervention/tracing/util.py +0 -0
  45. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/log.py +0 -0
  46. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/__init__.py +0 -0
  47. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/base.py +0 -0
  48. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/diffusion.py +0 -0
  49. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/language.py +0 -0
  50. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/mixins/__init__.py +0 -0
  51. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/mixins/loadable.py +0 -0
  52. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/mixins/meta.py +0 -0
  53. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/mixins/remoteable.py +0 -0
  54. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/vllm/__init__.py +0 -0
  55. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/vllm/model_runners/GPUModelRunner.py +0 -0
  56. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/vllm/model_runners/__init__.py +0 -0
  57. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/vllm/sampling copy.py +0 -0
  58. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/vllm/sampling.py +0 -0
  59. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/vllm/vllm.py +0 -0
  60. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/vllm/workers/GPUWorker.py +0 -0
  61. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/vllm/workers/__init__.py +0 -0
  62. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/modeling/vllm/workers/gpu_input_batch.py +0 -0
  63. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/schema/__init__.py +0 -0
  64. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/schema/config.py +0 -0
  65. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/schema/response.py +0 -0
  66. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight/util.py +0 -0
  67. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight.egg-info/SOURCES.txt +0 -0
  68. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight.egg-info/dependency_links.txt +0 -0
  69. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/src/nnsight.egg-info/top_level.txt +0 -0
  70. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/tests/__init__.py +0 -0
  71. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/tests/test_diffusion.py +0 -0
  72. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/tests/test_lm.py +0 -0
  73. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/tests/test_tiny.py +0 -0
  74. {nnsight-0.5.0.dev16 → nnsight-0.5.2}/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.dev16
3
+ Version: 0.5.2
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
@@ -17,7 +17,7 @@ Description-Content-Type: text/markdown
17
17
  License-File: LICENSE
18
18
  Requires-Dist: transformers
19
19
  Requires-Dist: astor
20
- Requires-Dist: dill
20
+ Requires-Dist: cloudpickle
21
21
  Requires-Dist: python-socketio[client]
22
22
  Requires-Dist: pydantic>=2.9.0
23
23
  Requires-Dist: torch>=2.4.0
@@ -28,7 +28,7 @@ classifiers = [
28
28
  dependencies = [
29
29
  "transformers",
30
30
  "astor",
31
- "dill",
31
+ "cloudpickle",
32
32
  "python-socketio[client]",
33
33
  "pydantic>=2.9.0",
34
34
  "torch>=2.4.0",
@@ -1,6 +1,39 @@
1
- from functools import wraps
1
+ # This section ensures that the source code for both the main script and the file where `nnsight` is imported
2
+ # is cached in Python's `linecache` module. This is important for robust stack trace and debugging support,
3
+ # especially in interactive or dynamic environments where files may change after import.
4
+ #
5
+ # 1. We first attempt to cache the main script (the file passed to the Python interpreter) by calling
6
+ # `linecache.getlines` on `sys.argv[0]`. This ensures that if the script is modified or deleted after
7
+ # execution starts, traceback and inspection tools can still access its source.
8
+ # 2. Next, we walk up the call stack to find the first frame outside of importlib (i.e., the user code that
9
+ # imported `nnsight`), and cache its source file as well. This helps ensure that the file where `nnsight`
10
+ # is imported is also available in `linecache`, even if it changes later.
11
+
12
+ import linecache
13
+ import sys
14
+ import os
15
+
16
+ try:
17
+ # Cache the main script file
18
+ linecache.getlines(os.path.abspath(sys.argv[0]))
19
+ except Exception:
20
+ pass
21
+
2
22
  import inspect
3
- import os, yaml, sys
23
+
24
+ try:
25
+ # Walk up the stack to cache the file where nnsight is imported
26
+ frame = inspect.currentframe()
27
+ while frame.f_back:
28
+ frame = frame.f_back
29
+ if 'importlib' not in frame.f_code.co_filename:
30
+ linecache.getlines(frame.f_code.co_filename, frame.f_globals)
31
+ except Exception:
32
+ pass
33
+
34
+ from functools import wraps
35
+
36
+ import os, yaml
4
37
  import warnings
5
38
  from typing import Optional
6
39
  from .schema.config import ConfigModel
@@ -4,12 +4,12 @@ from builtins import open
4
4
  from types import FrameType
5
5
  from typing import TYPE_CHECKING, Any, Optional, Union
6
6
 
7
- import dill
7
+ import cloudpickle
8
8
 
9
9
  from .envoy import Envoy
10
10
 
11
11
 
12
- class CustomDillPickler(dill.Pickler):
12
+ class CustomCloudPickler(cloudpickle.Pickler):
13
13
  def persistent_id(self, obj):
14
14
 
15
15
  if isinstance(obj, Envoy):
@@ -21,7 +21,7 @@ class CustomDillPickler(dill.Pickler):
21
21
  return None
22
22
 
23
23
 
24
- class CustomDillUnpickler(dill.Unpickler):
24
+ class CustomCloudUnpickler(pickle.Unpickler):
25
25
  def __init__(self, file, root: Envoy, frame: FrameType):
26
26
  super().__init__(file)
27
27
  self.root = root
@@ -41,22 +41,21 @@ class CustomDillUnpickler(dill.Unpickler):
41
41
 
42
42
  def save(obj: Any, path: Optional[str] = None):
43
43
 
44
- dill.settings["recurse"] = True
45
44
 
46
45
  if path is None:
47
46
  file = io.BytesIO()
48
- CustomDillPickler(file).dump(obj)
47
+ CustomCloudPickler(file, protocol=4).dump(obj)
49
48
  file.seek(0)
50
49
  return file.read()
51
50
 
52
51
  with open(path, "wb") as file:
53
- CustomDillPickler(file).dump(obj)
52
+ CustomCloudPickler(file).dump(obj)
54
53
 
55
54
 
56
55
  def load(data: Union[str, bytes], model: Envoy, frame: Optional[FrameType] = None):
57
56
 
58
57
  if isinstance(data, bytes):
59
- return CustomDillUnpickler(io.BytesIO(data), model, frame).load()
58
+ return CustomCloudUnpickler(io.BytesIO(data), model, frame).load()
60
59
 
61
60
  with open(data, "rb") as file:
62
- return CustomDillUnpickler(file, model, frame).load()
61
+ return CustomCloudUnpickler(file, model, frame).load()
@@ -1,5 +1,5 @@
1
1
  import ast
2
- import ctypes
2
+ import linecache
3
3
  import inspect
4
4
  import re
5
5
  import sys
@@ -11,6 +11,7 @@ from ..backends.execution import ExecutionBackend
11
11
  from .globals import Globals
12
12
  from .util import (TracingDeffermentException, get_non_nnsight_frame,
13
13
  push_variables, suppress_all_output)
14
+ from ...util import Patch, Patcher
14
15
 
15
16
 
16
17
  class ExitTracingException(Exception):
@@ -162,8 +163,15 @@ class Tracer:
162
163
 
163
164
  # CASE 3: We're in a regular Python file.
164
165
  elif not frame.f_code.co_filename.startswith("<nnsight"):
165
- # For regular files, get source lines using inspect
166
- source_lines, offset = inspect.getsourcelines(frame)
166
+
167
+ def noop(*args, **kwargs):
168
+ pass
169
+
170
+ # We dont want linecache to clear the cache for the file we're tracing as the user might have edited it.
171
+ with Patcher([Patch(linecache, noop,"checkcache")]):
172
+
173
+ # For regular files, get source lines using inspect
174
+ source_lines, offset = inspect.getsourcelines(frame)
167
175
 
168
176
  start_line = start_line if offset == 0 else start_line - offset + 1
169
177
 
@@ -4,7 +4,6 @@ import io
4
4
  import zlib
5
5
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Union
6
6
 
7
- import dill
8
7
  from pydantic import BaseModel, ConfigDict
9
8
  from ..intervention.serialization import save, load
10
9
  if TYPE_CHECKING:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nnsight
3
- Version: 0.5.0.dev16
3
+ Version: 0.5.2
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
@@ -17,7 +17,7 @@ Description-Content-Type: text/markdown
17
17
  License-File: LICENSE
18
18
  Requires-Dist: transformers
19
19
  Requires-Dist: astor
20
- Requires-Dist: dill
20
+ Requires-Dist: cloudpickle
21
21
  Requires-Dist: python-socketio[client]
22
22
  Requires-Dist: pydantic>=2.9.0
23
23
  Requires-Dist: torch>=2.4.0
@@ -1,6 +1,6 @@
1
1
  transformers
2
2
  astor
3
- dill
3
+ cloudpickle
4
4
  python-socketio[client]
5
5
  pydantic>=2.9.0
6
6
  torch>=2.4.0
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