def setup(self, kwargs): """Complete setup for wandb.init(). This includes parsing all arguments, applying them with settings and enabling logging. """ self.kwargs = kwargs self._wl = wandb_setup._setup() # Make sure we have a logger setup (might be an early logger) _set_logger(self._wl._get_logger()) # Start with settings from wandb library singleton settings = self._wl._clone_settings() settings_param = kwargs.pop("settings", None) if settings_param: settings._apply_settings(settings_param) self._reporter = reporting.setup_reporter( settings=settings.duplicate().freeze() ) sm_config = sagemaker.parse_sm_config() if sm_config: sm_api_key = sm_config.get("wandb_api_key", None) sm_run, sm_env = sagemaker.parse_sm_resources() if sm_env: if sm_api_key: sm_env["WANDB_API_KEY"] = sm_api_key settings._apply_environ(sm_env) wandb.setup(settings=settings) for k, v in six.iteritems(sm_run): kwargs.setdefault(k, v) # Remove parameters that are not part of settings init_config = kwargs.pop("config", None) or dict() config_include_keys = kwargs.pop("config_include_keys", None) config_exclude_keys = kwargs.pop("config_exclude_keys", None) # Add deprecation message once we can better track it and document alternatives # if config_include_keys or config_exclude_keys: # wandb.termwarn( # "config_include_keys and config_exclude_keys are deprecated:" # " use config=wandb.helper.parse_config(config_object, include=('key',))" # " or config=wandb.helper.parse_config(config_object, exclude=('key',))" # ) init_config = parse_config( init_config, include=config_include_keys, exclude=config_exclude_keys ) # merge config with sweep or sm (or config file) self.config = sm_config or self._wl._config or dict() for k, v in init_config.items(): self.config.setdefault(k, v) monitor_gym = kwargs.pop("monitor_gym", None) if monitor_gym and len(wandb.patched["gym"]) == 0: wandb.gym.monitor() tensorboard = kwargs.pop("tensorboard", None) sync_tensorboard = kwargs.pop("sync_tensorboard", None) if tensorboard or sync_tensorboard and len(wandb.patched["tensorboard"]) == 0: wandb.tensorboard.patch() magic = kwargs.get("magic") if magic not in (None, False): magic_install(kwargs) # handle login related parameters as these are applied to global state anonymous = kwargs.pop("anonymous", None) force = kwargs.pop("force", None) login_key = wandb.login(anonymous=anonymous, force=force) if not login_key: settings.mode = "offline" # apply updated global state after login was handled settings._apply_settings(wandb.setup()._settings) settings._apply_init(kwargs) # TODO(jhr): should this be moved? probably. d = dict(_start_time=time.time(), _start_datetime=datetime.datetime.now(),) settings.update(d) if settings._jupyter: self._jupyter_setup(settings) self._log_setup(settings) self.settings = settings.freeze()
def setup(self, kwargs): """Complete setup for wandb.init(). This includes parsing all arguments, applying them with settings and enabling logging. """ self.kwargs = kwargs self._wl = wandb_setup._setup() # Make sure we have a logger setup (might be an early logger) _set_logger(self._wl._get_logger()) # Start with settings from wandb library singleton settings = self._wl.settings().duplicate() settings_param = kwargs.pop("settings", None) if settings_param: settings._apply_settings(settings_param) self._reporter = reporting.setup_reporter( settings=settings.duplicate().freeze()) sm_config = sagemaker.parse_sm_config() if sm_config: sm_api_key = sm_config.get("wandb_api_key", None) sm_run, sm_env = sagemaker.parse_sm_resources() if sm_env: if sm_api_key: sm_env["WANDB_API_KEY"] = sm_api_key settings._apply_environ(sm_env) for k, v in six.iteritems(sm_run): kwargs.setdefault(k, v) # Remove parameters that are not part of settings init_config = kwargs.pop("config", None) or dict() config_include_keys = kwargs.pop("config_include_keys", None) config_exclude_keys = kwargs.pop("config_exclude_keys", None) # Add deprecation message once we can better track it and document alternatives # if config_include_keys or config_exclude_keys: # wandb.termwarn( # "config_include_keys and config_exclude_keys are deprecated:" # " use config=wandb.helper.parse_config(config_object, include=('key',))" # " or config=wandb.helper.parse_config(config_object, exclude=('key',))" # ) init_config = parse_config(init_config, include=config_include_keys, exclude=config_exclude_keys) # merge config with sweep or sm (or config file) self.config = sm_config or self._wl._config or dict() for k, v in init_config.items(): self.config.setdefault(k, v) # Temporarily unsupported parameters unsupported = ( "allow_val_change", "force", ) for key in unsupported: val = kwargs.pop(key, None) if val: self._reporter.warning( "currently unsupported wandb.init() arg: %s", key) monitor_gym = kwargs.pop("monitor_gym", None) if monitor_gym and len(wandb.patched["gym"]) == 0: wandb.gym.monitor() tensorboard = kwargs.pop("tensorboard", None) sync_tensorboard = kwargs.pop("sync_tensorboard", None) if tensorboard or sync_tensorboard and len( wandb.patched["tensorboard"]) == 0: wandb.tensorboard.patch() magic = kwargs.get("magic") if magic not in (None, False): magic_install(kwargs) # prevent setting project, entity if in sweep # TODO(jhr): these should be locked elements in the future or at least # moved to apply_init() if settings.sweep_id: for key in ("project", "entity"): val = kwargs.pop(key, None) if val: print("Ignored wandb.init() arg %s when running a sweep" % key) settings.apply_init(kwargs) login_key = wandb_login._login(_disable_warning=True, _settings=settings) if not login_key: settings.mode = "offline" # TODO(jhr): should this be moved? probably. d = dict( _start_time=time.time(), _start_datetime=datetime.datetime.now(), ) settings.update(d) if settings._jupyter: self._jupyter_setup(settings) self._log_setup(settings) self.settings = settings.freeze()
def setup(self, kwargs): """Complete setup for wandb.init(). This includes parsing all arguments, applying them with settings and enabling logging. """ self.kwargs = kwargs wl = wandb.setup() # Make sure we have a logger setup (might be an early logger) _set_logger(wl._get_logger()) settings = wl.settings(dict(kwargs.pop("settings", None) or tuple())) self._reporter = reporting.setup_reporter( settings=settings.duplicate().freeze()) # Remove parameters that are not part of settings init_config = kwargs.pop("config", None) or dict() # merge config with sweep (or config file) self.config = wl._config or dict() for k, v in init_config.items(): self.config.setdefault(k, v) # Temporarily unsupported parameters unsupported = ( "magic", "config_exclude_keys", "config_include_keys", "reinit", "anonymous", "dir", "allow_val_change", "resume", "force", "tensorboard", "sync_tensorboard", "monitor_gym", ) for key in unsupported: val = kwargs.pop(key, None) if val: self._reporter.warning( "currently unsupported wandb.init() arg: %s", key) # prevent setting project, entity if in sweep # TODO(jhr): these should be locked elements in the future or at least # moved to apply_init() if settings.sweep_id: for key in ("project", "entity"): val = kwargs.pop(key, None) if val: print("Ignored wandb.init() arg %s when running a sweep" % key) settings.apply_init(kwargs) # TODO(jhr): should this be moved? probably. d = dict( _start_time=time.time(), _start_datetime=datetime.datetime.now(), ) settings.update(d) self._log_setup(settings) wl._early_logger_flush(logger) self.wl = wl self.settings = settings.freeze()
def setup(self, kwargs): """Complete setup for wandb.init(). This includes parsing all arguments, applying them with settings and enabling logging. """ self.kwargs = kwargs # Some settings should be persisted across multiple runs the first # time setup is called. # TODO: Is this the best way to do this? session_settings_keys = ["anonymous"] session_settings = {k: kwargs[k] for k in session_settings_keys} self._wl = wandb.setup(settings=session_settings, _warn=False) # Make sure we have a logger setup (might be an early logger) _set_logger(self._wl._get_logger()) settings = self._wl.settings( dict(kwargs.pop("settings", None) or tuple())) self._reporter = reporting.setup_reporter( settings=settings.duplicate().freeze()) # Remove parameters that are not part of settings init_config = kwargs.pop("config", None) or dict() if not isinstance(init_config, dict): init_config = parse_config(init_config) # merge config with sweep (or config file) self.config = self._wl._config or dict() for k, v in init_config.items(): self.config.setdefault(k, v) # Temporarily unsupported parameters unsupported = ( "magic", "config_exclude_keys", "config_include_keys", "allow_val_change", "force", ) for key in unsupported: val = kwargs.pop(key, None) if val: self._reporter.warning( "currently unsupported wandb.init() arg: %s", key) monitor_gym = kwargs.pop("monitor_gym", None) if monitor_gym and len(wandb.patched["gym"]) == 0: wandb.gym.monitor() tensorboard = kwargs.pop("tensorboard", None) sync_tensorboard = kwargs.pop("sync_tensorboard", None) if tensorboard or sync_tensorboard and len( wandb.patched["tensorboard"]) == 0: wandb.tensorboard.patch() # prevent setting project, entity if in sweep # TODO(jhr): these should be locked elements in the future or at least # moved to apply_init() if settings.sweep_id: for key in ("project", "entity"): val = kwargs.pop(key, None) if val: print("Ignored wandb.init() arg %s when running a sweep" % key) settings.apply_init(kwargs) # TODO(jhr): should this be moved? probably. d = dict( _start_time=time.time(), _start_datetime=datetime.datetime.now(), ) settings.update(d) if settings.jupyter: self._jupyter_setup() self._log_setup(settings) self.settings = settings.freeze()