Skip to content

Commit fe0235f

Browse files
[WB-3836] Disabled mode fixes (wandb#1480)
1 parent a73f31b commit fe0235f

8 files changed

Lines changed: 50 additions & 20 deletions

File tree

wandb/dummy.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from types import ModuleType
2-
3-
4-
class Dummy(object):
1+
class Dummy(str):
52
def __init__(self, *args, **kwargs):
63
object.__setattr__(self, "___dict", {})
74

@@ -130,8 +127,13 @@ def __getattr__(self, attr):
130127

131128
def __getitem__(self, key):
132129
d = object.__getattribute__(self, "___dict")
133-
if key in d:
134-
return d[key]
130+
try:
131+
if key in d:
132+
return d[key]
133+
except TypeError:
134+
key = str(key)
135+
if key in d:
136+
return d[key]
135137
dummy = Dummy()
136138
d[key] = dummy
137139
return dummy
@@ -167,10 +169,6 @@ def __bool__(self):
167169
return True
168170

169171

170-
class DummyModule(Dummy, ModuleType):
171-
pass
172-
173-
174172
class DummyDict(dict):
175173
__setattr__ = dict.__setitem__
176174
__delattr__ = dict.__delitem__

wandb/integration/keras/keras.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,8 @@ def _log_dataframe(self):
744744
return None
745745

746746
def _save_model(self, epoch):
747+
if wandb.run.disabled:
748+
return
747749
if self.verbose > 0:
748750
print(
749751
"Epoch %05d: %s improved from %0.5f to %0.5f,"

wandb/sdk/wandb_init.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import time
1515
import traceback
1616

17+
import shortuuid # type: ignore
1718
import six
1819
import wandb
1920
from wandb import trigger
@@ -313,6 +314,12 @@ def init(self): # noqa: C901
313314
run.summary = DummyDict()
314315
run.log = lambda data, *_, **__: run.summary.update(data)
315316
run.finish = lambda *_, **__: module.unset_globals()
317+
run.step = 0
318+
run.resumed = False
319+
run.disabled = True
320+
run.id = shortuuid.uuid()
321+
run.name = "dummy-" + run.id
322+
run.dir = "/"
316323
module.set_global(
317324
run=run,
318325
config=run.config,

wandb/sdk/wandb_run.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ def mode(self):
461461
def offline(self):
462462
return self._settings._offline
463463

464+
@property
465+
def disabled(self):
466+
return self._settings._noop
467+
464468
@property
465469
def group(self):
466470
"""str: name of W&B group associated with run.
@@ -1730,23 +1734,27 @@ def restore(
17301734
ValueError if the file is not found or can't find run_path
17311735
"""
17321736

1737+
is_disabled = wandb.run is not None and wandb.run.disabled
1738+
run = None if is_disabled else wandb.run
17331739
if run_path is None:
1734-
if wandb.run is not None:
1735-
run_path = wandb.run.path
1740+
if run is not None:
1741+
run_path = run.path
17361742
else:
17371743
raise ValueError(
17381744
"run_path required when calling wandb.restore before wandb.init"
17391745
)
17401746
if root is None:
1741-
if wandb.run is not None:
1742-
root = wandb.run.dir
1747+
if run is not None:
1748+
root = run.dir
17431749
api = public.Api()
17441750
api_run = api.run(run_path)
17451751
if root is None:
17461752
root = os.getcwd()
17471753
path = os.path.join(root, name)
17481754
if os.path.exists(path) and replace is False:
17491755
return open(path, "r")
1756+
if is_disabled:
1757+
return None
17501758
files = api_run.files([name])
17511759
if len(files) == 0:
17521760
return None

wandb/sdk/wandb_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ def _apply_init(self, args):
915915
resume_run_id = json.load(f)["run_id"]
916916
if self.run_id is None:
917917
self.run_id = resume_run_id
918-
else:
918+
elif self.run_id != resume_run_id:
919919
wandb.termwarn(
920920
"Tried to auto resume run with id %s but id %s is set."
921921
% (resume_run_id, self.run_id)

wandb/sdk_py27/wandb_init.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import time
1515
import traceback
1616

17+
import shortuuid # type: ignore
1718
import six
1819
import wandb
1920
from wandb import trigger
@@ -313,6 +314,12 @@ def init(self): # noqa: C901
313314
run.summary = DummyDict()
314315
run.log = lambda data, *_, **__: run.summary.update(data)
315316
run.finish = lambda *_, **__: module.unset_globals()
317+
run.step = 0
318+
run.resumed = False
319+
run.disabled = True
320+
run.id = shortuuid.uuid()
321+
run.name = "dummy-" + run.id
322+
run.dir = "/"
316323
module.set_global(
317324
run=run,
318325
config=run.config,

wandb/sdk_py27/wandb_run.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ def mode(self):
461461
def offline(self):
462462
return self._settings._offline
463463

464+
@property
465+
def disabled(self):
466+
return self._settings._noop
467+
464468
@property
465469
def group(self):
466470
"""str: name of W&B group associated with run.
@@ -1730,23 +1734,27 @@ def restore(
17301734
ValueError if the file is not found or can't find run_path
17311735
"""
17321736

1737+
is_disabled = wandb.run is not None and wandb.run.disabled
1738+
run = None if is_disabled else wandb.run
17331739
if run_path is None:
1734-
if wandb.run is not None:
1735-
run_path = wandb.run.path
1740+
if run is not None:
1741+
run_path = run.path
17361742
else:
17371743
raise ValueError(
17381744
"run_path required when calling wandb.restore before wandb.init"
17391745
)
17401746
if root is None:
1741-
if wandb.run is not None:
1742-
root = wandb.run.dir
1747+
if run is not None:
1748+
root = run.dir
17431749
api = public.Api()
17441750
api_run = api.run(run_path)
17451751
if root is None:
17461752
root = os.getcwd()
17471753
path = os.path.join(root, name)
17481754
if os.path.exists(path) and replace is False:
17491755
return open(path, "r")
1756+
if is_disabled:
1757+
return None
17501758
files = api_run.files([name])
17511759
if len(files) == 0:
17521760
return None

wandb/sdk_py27/wandb_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ def _apply_init(self, args):
915915
resume_run_id = json.load(f)["run_id"]
916916
if self.run_id is None:
917917
self.run_id = resume_run_id
918-
else:
918+
elif self.run_id != resume_run_id:
919919
wandb.termwarn(
920920
"Tried to auto resume run with id %s but id %s is set."
921921
% (resume_run_id, self.run_id)

0 commit comments

Comments
 (0)