-
Notifications
You must be signed in to change notification settings - Fork 296
SNOW-2367850: task integration example update #250
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-ajiang
wants to merge
24
commits into
main
Choose a base branch
from
ajiang_task_example_update
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 11 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0291c04
update the task SDK
sfc-gh-ajiang 375d3ab
revert changes
sfc-gh-ajiang 703488f
resolve the comments
sfc-gh-ajiang f96fd9b
revert unnecessary changes
sfc-gh-ajiang ad5d13b
revert unnecessary changes
sfc-gh-ajiang fd6a7dc
resolve the comments
sfc-gh-ajiang 5524f9a
resolve the comments
sfc-gh-ajiang 3015500
resolve the comments
sfc-gh-ajiang 94e941a
resolve the comments
sfc-gh-ajiang 74a1edb
resolve the comments
sfc-gh-ajiang 7f992c4
reformat the script
sfc-gh-ajiang 01c160f
update the sample
sfc-gh-ajiang 9fb7478
update the sample
sfc-gh-ajiang 071eb1c
update the sample
sfc-gh-ajiang f6ab75c
update the sample
sfc-gh-ajiang 16b0b42
update the samples
sfc-gh-ajiang 9fe2b7a
update the samples
sfc-gh-ajiang 6b7c373
add more information for ML Job Definition
sfc-gh-ajiang cf1e70f
remove session creation at module level
sfc-gh-ajiang 1b5f9b1
resolve the comments
sfc-gh-ajiang d6a9bd0
update the image
sfc-gh-ajiang 591d89a
resolve the comments
sfc-gh-ajiang 2412da7
add the latest screenshots
sfc-gh-ajiang cd46e72
resolve the comments
sfc-gh-ajiang 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
Some comments aren't visible on the classic Files Changed page.
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
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,69 @@ | ||
| from snowflake.ml.data import DatasetInfo | ||
| from snowflake.core.task.context import TaskContext | ||
| from snowflake.snowpark import Session | ||
| import os | ||
| import json | ||
| import cloudpickle as cp | ||
| import io | ||
| import argparse | ||
|
|
||
| from pipeline_dag import RunConfig | ||
| from modeling import evaluate_model, train_model | ||
|
|
||
| session = Session.builder.getOrCreate() | ||
sfc-gh-ajiang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| index = int(os.environ.get("SNOWFLAKE_JOB_INDEX", 0)) | ||
|
|
||
| # Only head node saves and returns results | ||
| if index != 0: | ||
| print(f"Worker node (index {index}) - exiting") | ||
| exit(0) | ||
sfc-gh-ajiang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| artifact_dir = None | ||
| try: | ||
| ctx = TaskContext(session) | ||
| config = RunConfig.from_task_context(ctx) | ||
| artifact_dir = config.artifact_dir | ||
|
|
||
| # Load the datasets | ||
| serialized = json.loads(ctx.get_predecessor_return_value("PREPARE_DATA")) | ||
sfc-gh-ajiang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| except Exception as e: | ||
sfc-gh-ajiang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| print(f"Error loading dataset info: {e}") | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--dataset-info", type=str, required=True) | ||
| args = parser.parse_args() | ||
| serialized = json.loads(args.dataset_info) | ||
sfc-gh-ajiang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| dataset_info = { | ||
| key: DatasetInfo(**obj_dict) for key, obj_dict in serialized.items() | ||
| } | ||
| model_obj = train_model(session, dataset_info["train"]) | ||
|
|
||
| if not hasattr(model_obj, 'feature_weights'): | ||
| model_obj.feature_weights = None | ||
sfc-gh-ajiang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| train_metrics = evaluate_model( | ||
| session, model_obj, dataset_info["train"], prefix="train" | ||
| ) | ||
| test_metrics = evaluate_model( | ||
| session, model_obj, dataset_info["test"], prefix="test" | ||
| ) | ||
| metrics = {**train_metrics, **test_metrics} | ||
| if artifact_dir: | ||
| model_pkl = cp.dumps(model_obj) | ||
| model_path = os.path.join(config.artifact_dir, "model.pkl") | ||
sfc-gh-ajiang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| put_result = session.file.put_stream( | ||
| io.BytesIO(model_pkl), model_path, overwrite=True | ||
| ) | ||
| result_dict = { | ||
| "model_path": os.path.join(config.artifact_dir, put_result.target), | ||
| "metrics": metrics, | ||
| } | ||
| ctx.set_return_value(json.dumps(result_dict)) | ||
| else: | ||
| result_dict = { | ||
| "model_obj": model_obj, | ||
| "metrics": metrics, | ||
| } | ||
| __return__= result_dict | ||
sfc-gh-ajiang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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.
One of the main points of this sample is to demonstrate how easy it is to convert a local pipeline to pushing certain steps down into ML Jobs. Needing to write a separate script file which we
submit_file()just for this conversion severely weakens this story. Why can't we just keep using a@remote()decorated function?@remote(...)should convert the function into anMLJobDefinitionwhich we can directly use inpipeline_dagwithout needing an explicitMLJobDefinition.register()callThere 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.
That is currently
@remotedoes not create job definition and it creates a job directly. Currently, we only merged the PR for phase one and phase 2 is in review.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.
Let's hold off on merging this until
@remoteis ready thenThere 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.
Since the
@remotechange is now available, can we now call this as an ML Job directly frompipeline_dag?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 am little confused here. Do you mean we create a job inside the task directly?