Skip to content
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
12 changes: 12 additions & 0 deletions plugins/flytekit-wandb/flytekitplugins/wandb/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ def execute(self, *args, **kwargs):

run = wandb.init(project=self.project, entity=self.entity, id=wand_id, **self.init_kwargs)

# Store Flyte execution metadata in wandb run config for reverse lookups.
if not is_local_execution:
exec_id = ctx.user_space_params.execution_id
run.config.update(
{
"flyte_execution_id": exec_id.name,
"flyte_execution_project": exec_id.project,
"flyte_execution_domain": exec_id.domain,
},
allow_val_change=True,
)

# If FLYTE_EXECUTION_URL is defined, inject it into wandb to link back to the execution.
execution_url = os.getenv("FLYTE_EXECUTION_URL")
if execution_url is not None:
Expand Down
12 changes: 12 additions & 0 deletions plugins/flytekit-wandb/tests/test_wandb_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def test_non_local_execution(wandb_mock, manager_mock, monkeypatch):

ctx_mock.user_space_params.secrets.get.return_value = "this_is_the_secret"
ctx_mock.user_space_params.execution_id.name = "my_execution_id"
ctx_mock.user_space_params.execution_id.project = "my_project"
ctx_mock.user_space_params.execution_id.domain = "staging"

manager_mock.current_context.return_value = ctx_mock
execution_url = "http://execution_url.com/afsdfsafafasdfs"
Expand All @@ -83,6 +85,16 @@ def test_non_local_execution(wandb_mock, manager_mock, monkeypatch):
wandb_mock.login.assert_called_with(key="this_is_the_secret", host="https://api.wandb.ai")
assert run_mock.notes == f"[Execution URL]({execution_url})"

# Verify Flyte execution metadata is stored in wandb config
run_mock.config.update.assert_called_once_with(
{
"flyte_execution_id": "my_execution_id",
"flyte_execution_project": "my_project",
"flyte_execution_domain": "staging",
},
allow_val_change=True,
)


def test_errors():
with pytest.raises(ValueError, match="project must be set"):
Expand Down