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

Improve wandb.init(settings=) to handle Settings object similarly to dict parameter #3510

Merged
merged 31 commits into from
Apr 16, 2022

Conversation

dmitryduev
Copy link
Member

@dmitryduev dmitryduev commented Apr 11, 2022

Fixes #3505

Description

Treat a wandb.Settings object passed to wandb.init() similar to how a passed dict is treated. Will now detect settings that differ from defaults and apply them using Source.INIT, as this is probably that the user would expect when doing wandb.init(settings=wandb.Settings(...)).

Also deprecated config_include_keys and config_exclude_keys kwargs in wandb.init(...) bc saw a todo in the code next to what I was touching and couldn't ignore it :)

Testing

Hopefully fixed a couple tests + improved robustness in tests/test_redir.py that would flake out at times.

@dmitryduev dmitryduev requested review from vanpelt, raubitsj and kptkin and removed request for vanpelt April 11, 2022 19:12
@dmitryduev dmitryduev marked this pull request as draft April 12, 2022 02:16
@codecov
Copy link

codecov bot commented Apr 12, 2022

Codecov Report

Merging #3510 (9dbbb55) into master (e3a26cf) will increase coverage by 0.03%.
The diff coverage is 93.54%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3510      +/-   ##
==========================================
+ Coverage   81.41%   81.44%   +0.03%     
==========================================
  Files         236      236              
  Lines       29082    29098      +16     
==========================================
+ Hits        23677    23700      +23     
+ Misses       5405     5398       -7     
Flag Coverage Δ
functest 58.14% <83.87%> (+0.07%) ⬆️
unittest 71.54% <93.54%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
wandb/sdk/lib/retry.py 91.46% <ø> (ø)
wandb/sdk/wandb_run.py 89.84% <ø> (+0.12%) ⬆️
wandb/sdk/wandb_settings.py 94.55% <88.88%> (-0.32%) ⬇️
wandb/sdk/internal/internal_api.py 83.96% <100.00%> (ø)
wandb/sdk/wandb_init.py 85.42% <100.00%> (+0.02%) ⬆️
wandb/sdk/lib/apikey.py 87.69% <0.00%> (-0.77%) ⬇️
wandb/sdk/lib/git.py 76.19% <0.00%> (ø)
wandb/sdk/launch/agent/agent.py 93.18% <0.00%> (+0.75%) ⬆️
... and 2 more

@dmitryduev dmitryduev requested a review from kptkin April 12, 2022 07:25
@dmitryduev dmitryduev marked this pull request as ready for review April 12, 2022 07:25
Comment on lines +320 to +325
@pytest.mark.skip(
reason=(
"mock server enforces entity=mock_server_entity and project=test,"
"this should only work on a live server, or mock_server would need customization."
)
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to work bc previously, a Settings object passed to wandb.init() would "carry over" its setting sources. settings.update(...) by default uses Source.OVERRIDE meaning that no downstream changes would affect the changed settings (unless again overridden).
We could customize mock_server so that it "recognizes" two (or more) entities, but it feels a bit outside the scope for this PR.

@@ -995,3 +995,13 @@ def test_local_api_key_validation():

# ensure that base_url is applied first without causing an error in api_key validation
wandb.Settings()._apply_settings(s)


def test_run_urls():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a "replacement" test for the one in wandb_run_test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean test_run_urls?

@@ -138,10 +141,23 @@ def setup(self, kwargs) -> None: # noqa: C901
settings_param = kwargs.pop("settings", None)
if settings_param is not None:
if isinstance(settings_param, Settings):
# todo: check the logic here. this _only_ comes up in tests?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see, I even left a todo back in the day lol :)

@@ -81,7 +82,7 @@ def _get_wandb_dir(root_dir: str) -> str:
return os.path.expanduser(path)


# fixme: should either return bool or error out. fix once confident.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixme's break our flake checker, according to @raubitsj, so rm'ed 'em all.

Comment on lines +1136 to +1140
def items(self) -> ItemsView[str, Any]:
return self.make_static().items()

def get(self, key: str, default: Any = None) -> Any:
return self.make_static().get(key, default)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought, why not make the Settings object even more similar to a dictionary? It's pretty convenient in certain scenarios.

@dmitryduev dmitryduev added this to the sdk-2022-04.2 milestone Apr 12, 2022
@dmitryduev dmitryduev requested a review from a team April 13, 2022 08:40
@dmitryduev dmitryduev added this to the sdk-2022-05.1 milestone Apr 15, 2022
tests/test_redir.py Outdated Show resolved Hide resolved
wandb/sdk/wandb_init.py Outdated Show resolved Hide resolved
wandb/sdk/wandb_run.py Outdated Show resolved Hide resolved
@@ -917,11 +920,16 @@ def _run_url(self) -> str:
query = self._get_url_query_string()
return f"{project_url}/runs/{quote(self.run_id)}{query}"

def _start_run(self) -> None:
def _start_run(self, source: int = Source.BASE) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: name seems weird given that we only time stamp this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I just kept the way it was called previously. How about _set_time_stamps?

Copy link
Contributor

@kptkin kptkin Apr 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah makes more sense...
though it is weird that it is not part of some _apply_... something? not sure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep this private method, but would be happy to move the call in wandb.init() to _apply_init. @raubitsj there's a todo in that place from you saying "# TODO(jhr): should this be moved? probably.", so I'd defer it to you to make the final decision thanks :)
Also, it's used in standalone_tests/grpc_client.py.

wandb/sdk/wandb_init.py Outdated Show resolved Hide resolved
tests/utils/utils.py Outdated Show resolved Hide resolved
@dmitryduev dmitryduev requested a review from kptkin April 15, 2022 19:52
Copy link
Contributor

@kptkin kptkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@dmitryduev dmitryduev merged commit 497df3d into master Apr 16, 2022
@dmitryduev dmitryduev deleted the disable-stats branch April 16, 2022 00:11
@raubitsj raubitsj changed the title Treat Settings object passed to wandb.init() similar to how dict is treated Improve wandb.init(settings=) to handle Settings object similarly to dict parameter May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CLI]: _disable_stats doesn't work
3 participants