-
Notifications
You must be signed in to change notification settings - Fork 40
Feature: Support more experiment tracking libraries #365
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
Open
sfc-gh-mwyatt
wants to merge
2
commits into
main
Choose a base branch
from
mwyatt/sf-exp-tracking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Copyright 2025 Snowflake Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from arctic_training.config.base import BaseConfig | ||
|
|
||
|
|
||
| class ExperimentTrackingConfig(BaseConfig): | ||
| type: str = "wandb" | ||
| """ Experiment tracking backend type. """ | ||
|
|
||
| enable: bool = False | ||
| """ Whether to enable experiment tracking. """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Copyright 2025 Snowflake Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
119 changes: 119 additions & 0 deletions
119
arctic_training/experiment_tracking/snowflake_tracker.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # Copyright 2025 Snowflake Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from typing import TYPE_CHECKING | ||
| from typing import Any | ||
| from typing import Dict | ||
| from typing import Optional | ||
|
|
||
| from arctic_training.config.experiment_tracking import ExperimentTrackingConfig | ||
| from arctic_training.experiment_tracking.tracker import ExperimentTracker | ||
| from arctic_training.logging import logger | ||
|
|
||
| if TYPE_CHECKING: | ||
| from arctic_training.trainer.trainer import Trainer | ||
|
|
||
|
|
||
| class SnowflakeExperimentTrackingConfig(ExperimentTrackingConfig): | ||
| type: str = "snowflake" | ||
|
|
||
| account: str = "" | ||
| """ Snowflake account identifier. """ | ||
|
|
||
| user: str = "" | ||
| """ Snowflake user name. """ | ||
|
|
||
| password: str = "" | ||
| """ Snowflake PAT or password. """ | ||
|
|
||
| role: str = "" | ||
| """ Snowflake role. """ | ||
|
|
||
| warehouse: str = "" | ||
| """ Snowflake warehouse. """ | ||
|
|
||
| database: str = "" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, are db and schema mandatory here?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not 100% sure. There might be a default - I will verify. |
||
| """ Snowflake database. """ | ||
|
|
||
| schema_name: str = "" | ||
| """ Snowflake schema. """ | ||
|
|
||
| experiment_name: str = "" | ||
| """ Name of the experiment in Snowflake experiment tracking. """ | ||
|
|
||
| run_name: Optional[str] = None | ||
| """ Name of the run. If not set, one will be generated. """ | ||
|
|
||
| @property | ||
| def connection_params(self): | ||
| return dict( | ||
| account=self.account, | ||
| user=self.user, | ||
| authentication="PAT", | ||
| password=self.password, | ||
| role=self.role, | ||
| warehouse=self.warehouse, | ||
| database=self.database, | ||
| schema=self.schema_name, | ||
| ) | ||
|
|
||
|
|
||
| class SnowflakeExpTracker(ExperimentTracker): | ||
| name: str = "snowflake" | ||
| config: SnowflakeExperimentTrackingConfig | ||
|
|
||
| def __init__(self, trainer: "Trainer", config: SnowflakeExperimentTrackingConfig) -> None: | ||
| super().__init__(trainer, config) | ||
| self._experiment: Any = None | ||
| self._run_name: Optional[str] = config.run_name | ||
|
|
||
| def start(self, run_config: Dict[str, Any]) -> None: | ||
| try: | ||
| from snowflake.ml.experiment.experiment_tracking import ExperimentTracking | ||
| from snowflake.snowpark import Session | ||
| except ImportError: | ||
| raise ImportError( | ||
| "Snowflake experiment tracking requires the snowflake-ml-python and " | ||
| "snowflake-snowpark-python packages. Install them with:\n" | ||
| " pip install snowflake-ml-python snowflake-snowpark-python" | ||
| ) | ||
|
|
||
| session = Session.builder.configs(self.config.connection_params).create() | ||
| self._experiment = ExperimentTracking(session=session) | ||
| self._experiment.set_experiment(self.config.experiment_name) | ||
|
|
||
| self._experiment.start_run(self._run_name) | ||
| self._experiment.log_params(run_config) | ||
| logger.info(f"Snowflake experiment tracking started: {self.config.experiment_name}/{self._run_name}") | ||
|
|
||
| def log_metrics(self, metrics: Dict[str, Any], step: int) -> None: | ||
| if self._experiment is not None: | ||
| self._experiment.log_metrics(metrics, step=step) | ||
|
|
||
| def log_params(self, params: Dict[str, Any]) -> None: | ||
| if self._experiment is not None: | ||
| self._experiment.log_params(params) | ||
|
|
||
| def finish(self) -> None: | ||
| if self._experiment is not None: | ||
| self._experiment.end_run() | ||
|
|
||
| def get_resume_state(self) -> Optional[Dict[str, Any]]: | ||
| if self._run_name is None: | ||
| return None | ||
| return {"run_name": self._run_name} | ||
|
|
||
| def set_resume_state(self, state: Dict[str, Any]) -> None: | ||
| self._run_name = state.get("run_name") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # Copyright 2025 Snowflake Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from abc import ABC | ||
| from abc import abstractmethod | ||
| from typing import TYPE_CHECKING | ||
| from typing import Any | ||
| from typing import Dict | ||
| from typing import Optional | ||
|
|
||
| from arctic_training.config.experiment_tracking import ExperimentTrackingConfig | ||
| from arctic_training.registry import RegistryMeta | ||
| from arctic_training.registry import _validate_class_attribute_set | ||
| from arctic_training.registry import _validate_class_attribute_type | ||
| from arctic_training.registry import _validate_class_method | ||
|
|
||
| if TYPE_CHECKING: | ||
| from arctic_training.trainer.trainer import Trainer | ||
|
|
||
|
|
||
| class ExperimentTracker(ABC, metaclass=RegistryMeta): | ||
| """Base class for experiment tracking backends.""" | ||
|
|
||
| name: str | ||
| """ | ||
| Name of the experiment tracker used for registration. This name | ||
| should be unique and is used in configs to select the tracker. | ||
| """ | ||
|
|
||
| config: ExperimentTrackingConfig | ||
| """ | ||
| The type of the config class that the tracker uses. This should be a | ||
| subclass of ExperimentTrackingConfig. | ||
| """ | ||
|
|
||
| @classmethod | ||
| def _validate_subclass(cls) -> None: | ||
| _validate_class_attribute_set(cls, "name") | ||
| _validate_class_attribute_type(cls, "config", ExperimentTrackingConfig) | ||
| _validate_class_method(cls, "start", ["self", "run_config"]) | ||
| _validate_class_method(cls, "log_metrics", ["self", "metrics", "step"]) | ||
| _validate_class_method(cls, "log_params", ["self", "params"]) | ||
| _validate_class_method(cls, "finish", ["self"]) | ||
| _validate_class_method(cls, "get_resume_state", ["self"]) | ||
| _validate_class_method(cls, "set_resume_state", ["self", "state"]) | ||
|
|
||
| def __init__(self, trainer: "Trainer", config: ExperimentTrackingConfig) -> None: | ||
| self._trainer = trainer | ||
| self.config = config | ||
|
|
||
| @property | ||
| def trainer(self) -> "Trainer": | ||
| return self._trainer | ||
|
|
||
| @abstractmethod | ||
| def start(self, run_config: Dict[str, Any]) -> None: | ||
| """Initialize and start the tracking run.""" | ||
| raise NotImplementedError | ||
|
|
||
| @abstractmethod | ||
| def log_metrics(self, metrics: Dict[str, Any], step: int) -> None: | ||
| """Log metrics for the current step.""" | ||
| raise NotImplementedError | ||
|
|
||
| @abstractmethod | ||
| def log_params(self, params: Dict[str, Any]) -> None: | ||
| """Log parameters/config for the run.""" | ||
| raise NotImplementedError | ||
|
|
||
| @abstractmethod | ||
| def finish(self) -> None: | ||
| """Finalize and close the tracking run.""" | ||
| raise NotImplementedError | ||
|
|
||
| @abstractmethod | ||
| def get_resume_state(self) -> Optional[Dict[str, Any]]: | ||
| """Return state needed to resume this tracker across checkpoint restarts.""" | ||
| raise NotImplementedError | ||
|
|
||
| @abstractmethod | ||
| def set_resume_state(self, state: Dict[str, Any]) -> None: | ||
| """Restore tracker state from a previous checkpoint.""" | ||
| raise NotImplementedError |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From managed API path, SPCS will be responsible for setting the config. SPCS job only has OAuth token available to be used. Could we support the authentication type
token = <oauth_token>, authenticator = 'oauth'?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let me update for different auth types and I will let you test!