-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat(jobs): improve MLOps example #82
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9cc3e65
feat: separate loader file
redanrd c5dfce0
feat: version model and other training artifacts
redanrd 77c3703
feat: use cron for jobs and container
redanrd e2a9ba5
chore: scaleway provider version for terraform
redanrd 8e956b6
feat: model versioning
redanrd 4a17d10
feat: info get endpoint and trigger post endpoint
redanrd e9888ca
docs: add TF_VAR_data_fetch_cron_schedule
redanrd 2bf3f3f
refactor: formatting
redanrd 08325f2
docs: rewording
redanrd da2f143
feat: increase scheduling frequency
redanrd 6234310
feat: schedule fetching data from source
redanrd 530670d
fix: remove no cache directive
redanrd 5e1cfb0
fix: cron schedules
redanrd edb4c9c
docs: optional tf variables rewording
redanrd 9aed2fe
refactor: inference response message
redanrd 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 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,5 +1,5 @@ | ||
import pandas as pd | ||
import numpy as np | ||
import pandas as pd | ||
from pydantic import BaseModel | ||
|
||
|
||
|
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,60 @@ | ||
import os | ||
import pickle | ||
|
||
import boto3 | ||
|
||
|
||
class ClassifierLoader: | ||
_classifier = None | ||
_classifier_version = "" | ||
|
||
@classmethod | ||
def load(cls, force=False): | ||
if force or cls._classifier is None: | ||
access_key = os.environ["ACCESS_KEY"] | ||
secret_key = os.environ["SECRET_KEY"] | ||
region_name = os.environ["REGION"] | ||
|
||
bucket_name = os.environ["S3_BUCKET_NAME"] | ||
s3_url = os.environ["S3_URL"] | ||
|
||
s3 = boto3.client( | ||
"s3", | ||
region_name=region_name, | ||
endpoint_url=s3_url, | ||
aws_access_key_id=access_key, | ||
aws_secret_access_key=secret_key, | ||
) | ||
|
||
# get model file with the latest version | ||
bucket_objects = s3.list_objects(Bucket=bucket_name) | ||
get_last_modified = lambda object: int( | ||
object["LastModified"].strftime("%s") | ||
) | ||
model_objects = [ | ||
model_object | ||
for model_object in bucket_objects["Contents"] | ||
if "classifier" in model_object["Key"] | ||
] | ||
latest_model_file = [ | ||
object["Key"] for object in sorted(model_objects, key=get_last_modified) | ||
][0] | ||
|
||
s3.download_file(bucket_name, latest_model_file, latest_model_file) | ||
|
||
with open(latest_model_file, "rb") as fh: | ||
cls._classifier = pickle.load(fh) | ||
cls._classifier_version = latest_model_file[11:-4] | ||
|
||
print( | ||
"Successfully loaded model file: {latest_model_file}".format( | ||
latest_model_file=latest_model_file | ||
), | ||
flush=True, | ||
) | ||
|
||
return cls._classifier | ||
|
||
@classmethod | ||
def model_version(cls): | ||
return cls._classifier_version |
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
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
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.
We need to preserve the container state as we load the model in memory. Having many instances would possibly lead to ones with no model loaded in memory so they would fail when requested for inference.