Skip to content

Commit

Permalink
feat (api): Add persistent setting for debug mode + improve error log
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamBelfki3 committed Oct 11, 2024
1 parent d36b065 commit f5abeaf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/nnsight/models/NNsightModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from ..logger import logger
from ..tracing import protocols
from ..tracing.Graph import Graph
from .. import CONFIG


class MetaDispatcher(TorchDispatchMode):
Expand Down Expand Up @@ -241,11 +242,16 @@ def trace(

backend = RemoteBackend(host=backend, blocking=blocking)

if "debug" not in kwargs.keys():
kwargs["debug"] = CONFIG.APP.DEBUG

# Create Tracer object.
if self._default_graph is not None:

graph = self._default_graph.copy()

graph.debug = kwargs["debug"]

tracer = Tracer(backend, self, bridge=bridge, graph=graph, scan=scan, **kwargs)
else:
tracer = Tracer(backend, self, bridge=bridge, scan=scan, **kwargs)
Expand Down Expand Up @@ -401,6 +407,9 @@ def session(

backend = RemoteBackend(host=backend, blocking=blocking)

if "debug" not in kwargs.keys():
kwargs["debug"] = CONFIG.APP.DEBUG

session = Session(backend, self, **kwargs)

self._session = session
Expand Down
7 changes: 7 additions & 0 deletions src/nnsight/schema/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ApiConfigModel(BaseModel):
class AppConfigModel(BaseModel):
LOGGING: bool = False
REMOTE_LOGGING: bool = True
DEBUG: bool = False


class ConfigModel(BaseModel):
Expand All @@ -26,6 +27,12 @@ def set_default_api_key(self, apikey: str):

self.save()

def set_default_app_debug(self, debug: bool):

self.APP.DEBUG = debug

self.save()

def save(self):

from .. import PATH
Expand Down
4 changes: 1 addition & 3 deletions src/nnsight/tracing/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def execute(self) -> None:
if type(e) != protocols.EarlyStopProtocol.EarlyStopException:
if self.attached():
print(f"\n{self.meta_data['traceback']}\n" + \
"NNsightError: The exception below was the direct cause of this exception.\n")
f"NNsightError: {str(e)}.\n")

# Kill all the graphs in the Session to signal that an error occured
# This way only the traceback of the Node responsible for the error gets printed out
Expand All @@ -403,8 +403,6 @@ def kill_graph(graph: "Graph") -> None:
graph.alive = False

[kill_graph(g) for g in bridge.graph_stack]
# Propagate original error
raise e
else:
raise type(e)(
f"Above exception occured when executing Node: '{self.name}' in Graph: '{self.graph.id}'"
Expand Down

0 comments on commit f5abeaf

Please sign in to comment.