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
Initial pass at wandb Ludwig integration #514
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
64c00db
Initial pass at ludwig integration
vanpelt 52ec945
Dont assume wandb.init has been called
vanpelt 717245a
Formatting fixes
vanpelt 6161ff2
PR feedback
vanpelt 44b682d
Fix the deep scanner
vanpelt 0b24405
Final fixes
vanpelt d437278
Last major deepsource issue
vanpelt b3df25b
Merge branch 'master' of https://github.com/uber/ludwig into feature/…
vanpelt 0428aed
Merge branch 'master' of https://github.com/uber/ludwig into feature/…
borisdayma e11365e
refactor(wandb): convert static methods to regular methods
borisdayma 078d2c9
Merge branch 'master' of https://github.com/uber/ludwig into feature/…
borisdayma 70e1c60
docs: fix of formatting of long line
borisdayma b086647
docs(wandb): fix formatting
borisdayma 6691c19
feat(wandb): predict_end not used anymore
borisdayma 9bfdf2f
docs(wandb): document use of wandb contrib
borisdayma 4a71e88
test(wandb): add integration test
borisdayma 0285945
style(wandb): fix formatting
borisdayma 7568c78
fix(wandb): add dependency to test requirements
borisdayma 09b559c
test(wandb): remove instance from contrib_registry
borisdayma c796f5b
feat(wandb): log name of run from model_name
borisdayma File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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,63 @@ | ||
# coding=utf-8 | ||
# Copyright (c) 2019 Uber Technologies, Inc. | ||
# | ||
# 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. | ||
# ============================================================================== | ||
|
||
import logging | ||
import os | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Wandb(): | ||
"""Class that defines the methods necessary to hook into process.""" | ||
|
||
@staticmethod | ||
def import_call(argv, *args, **kwargs): | ||
""" | ||
Enable Third-party support from wandb.ai | ||
Allows experiment tracking, visualization, and | ||
management. | ||
""" | ||
try: | ||
import wandb | ||
# Needed to call an attribute of wandb to make DeepSource not complain | ||
return Wandb() if wandb.__version__ else None | ||
except ImportError: | ||
logger.error( | ||
"Ignored --wandb: Please install wandb; see https://docs.wandb.com") | ||
return None | ||
|
||
def train_model(self, model, *args, **kwargs): | ||
import wandb | ||
logger.info("wandb.train_model() called...") | ||
config = model.hyperparameters.copy() | ||
del config["input_features"] | ||
del config["output_features"] | ||
wandb.config.update(config) | ||
|
||
def train_init(self, experiment_directory, experiment_name, model_name, | ||
resume, output_directory): | ||
import wandb | ||
logger.info("wandb.train_init() called...") | ||
wandb.init(project=os.getenv("WANDB_PROJECT", experiment_name), | ||
name=model_name, sync_tensorboard=True, dir=output_directory) | ||
wandb.save(os.path.join(experiment_directory, "*")) | ||
|
||
def visualize_figure(self, fig): | ||
import wandb | ||
logger.info("wandb.visualize_figure() called...") | ||
if wandb.run: | ||
wandb.log({"figure": fig}) |
This file contains 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 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 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 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
pytest | ||
pytest | ||
wandb |
This file contains 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,58 @@ | ||
import logging | ||
import os | ||
import shutil | ||
import sys | ||
|
||
import ludwig.contrib | ||
from tests.integration_tests.test_experiment import run_experiment | ||
from tests.integration_tests.utils import image_feature | ||
from tests.integration_tests.utils import category_feature | ||
from tests.integration_tests.utils import generate_data | ||
|
||
import wandb | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.INFO) | ||
logging.getLogger("ludwig").setLevel(logging.INFO) | ||
|
||
|
||
def test_wandb_experiment(csv_filename): | ||
# Test W&B integration | ||
|
||
# add wandb arg and detect flag | ||
sys.argv.append('--wandb') | ||
ludwig.contrib.contrib_import() | ||
|
||
# disable sync to cloud | ||
os.environ['WANDB_MODE'] = 'dryrun' | ||
|
||
# Image Inputs | ||
image_dest_folder = os.path.join(os.getcwd(), 'generated_images') | ||
|
||
# Inputs & Outputs | ||
input_features = [image_feature(folder=image_dest_folder)] | ||
output_features = [category_feature()] | ||
rel_path = generate_data(input_features, output_features, csv_filename) | ||
|
||
# Run experiment | ||
run_experiment(input_features, output_features, data_csv=rel_path) | ||
|
||
# Check a W&B run was created | ||
assert wandb.run is not None | ||
|
||
# End session | ||
wandb.join() | ||
|
||
# Remove instance from contrib_registry | ||
ludwig.contrib.contrib_registry['instances'].pop() | ||
|
||
# Delete the temporary data created | ||
shutil.rmtree(image_dest_folder) | ||
|
||
|
||
if __name__ == '__main__': | ||
""" | ||
To run tests individually, run: | ||
```python -m pytest tests/integration_tests/test_contrib_wandb.py::test_name``` | ||
""" | ||
pass |
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.
I would add
name=model_name
to the init parameters.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.
Good idea, I was not aware of what
model_name
was used for initially but now it makes sense to use it as the W&B run name