Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct modules access when not tracing #167

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/nnsight/envoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def modules(

if included:
if names:
envoys.append((self._module_path, self))
envoys.append((self._module_path.lstrip("."), self))
else:
envoys.append(self)

Expand Down
6 changes: 6 additions & 0 deletions src/nnsight/models/NNsightModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ def __setattr__(self, key: Any, value: Any) -> None:

if key not in ('_model', '_model_key') and isinstance(value, torch.nn.Module):

if self._envoy._tracer is None:
setattr(self._model, key, value)

setattr(self._envoy, key, value)

else:
Expand All @@ -312,6 +315,9 @@ def __getattr__(self, key: Any) -> Union[Envoy, InterventionProxy, Any]:
Returns:
Any: Attribute.
"""
if self._envoy._tracer is None:
return getattr(self._model, key)

return getattr(self._envoy, key)

### NNsight VIRTUAL METHODS BELOW #####################################
Expand Down
Loading