Skip to content

Commit

Permalink
Merge pull request #263 from ndif-team/calling
Browse files Browse the repository at this point in the history
Add ability to call envoys /  models outside of tracing context
  • Loading branch information
JadenFiotto-Kaufman authored Oct 8, 2024
2 parents e7480d6 + b11e142 commit 3a31696
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/nnsight/envoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,28 @@ def _set_tracer(self, tracer: Tracer, propagate=True):
if propagate:
for envoy in self._sub_envoys:
envoy._set_tracer(tracer, propagate=True)


def _tracing(self) -> bool:
"""Whether or not tracing.
Returns:
bool: Is tracing.
"""

try:

return self._tracer.graph.alive

except:

return False

def _scanning(self) -> bool:
"""Whether or not in scanning mode. Checks the current Tracer's Invoker.
Returns:
bool: _description_
bool: Is scanning.
"""

try:
Expand Down Expand Up @@ -420,6 +436,9 @@ def __call__(
Returns:
InterventionProxy: Module call proxy.
"""

if not self._tracing():
return self._module(*args, **kwargs)

if isinstance(self._tracer.backend, EditBackend):
hook = True
Expand Down
4 changes: 4 additions & 0 deletions src/nnsight/models/NNsightModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ def __init__(
self.dispatch_model()

logger.info(f"Initialized `{self._model_key}`")

def __call__(self, *args, **kwargs):

return self._envoy(*args, **kwargs)

def trace(
self,
Expand Down

0 comments on commit 3a31696

Please sign in to comment.