-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fine-tuned todos a bit + migrated flops_utils into the main repo
Still need to update the flops_utils dependency links
- Loading branch information
Showing
23 changed files
with
540 additions
and
77 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__pycache__ | ||
dist |
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,2 +1 @@ | ||
# TODO | ||
move the contents from the tmp_floips |
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,18 @@ | ||
import os | ||
import sys | ||
|
||
from flops_utils.logging import logger | ||
|
||
DOCKER_HOST_IP_LINUX = "172.17.0.1" | ||
|
||
_ERROR_MESSAGE = ( | ||
"Terminating. Make sure to set the environment variables first. Missing: " | ||
) | ||
|
||
|
||
def get_env_var(name: str, default: str = "") -> str: | ||
env_var = os.environ.get(name) or default | ||
if env_var is None: | ||
logger.fatal(f"{_ERROR_MESSAGE}'{name}'") | ||
sys.exit(1) | ||
return env_var |
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,51 @@ | ||
# Reference: | ||
# https://alexandra-zaharia.github.io/posts/make-your-own-custom-color-formatter-with-python-logging/ | ||
|
||
import logging | ||
|
||
|
||
class CustomFormatter(logging.Formatter): | ||
"""Logging colored formatter, adapted from https://stackoverflow.com/a/56944256/3638629""" | ||
|
||
grey = "\x1b[38;21m" | ||
yellow = "\x1b[38;5;226m" | ||
red = "\x1b[38;5;196m" | ||
bold_red = "\x1b[31;1m" | ||
blue = "\x1b[38;5;33m" | ||
light_blue = "\x1b[38;5;45m" | ||
reset = "\x1b[0m" | ||
|
||
def __init__(self, fmt, with_color: bool = False): | ||
super().__init__() | ||
self.fmt = fmt | ||
base_fmt = self.fmt + self.reset | ||
|
||
if with_color: | ||
self.FORMATS = { | ||
logging.DEBUG: self.grey + base_fmt, | ||
logging.INFO: self.light_blue + base_fmt, | ||
logging.WARNING: self.yellow + base_fmt, | ||
logging.ERROR: self.red + base_fmt, | ||
logging.CRITICAL: self.bold_red + base_fmt, | ||
} | ||
else: | ||
self.FORMATS = {level: base_fmt for level in logging._levelToName.values()} | ||
|
||
def format(self, record): | ||
log_fmt = self.FORMATS.get(record.levelno) # type: ignore | ||
formatter = logging.Formatter(log_fmt) | ||
return formatter.format(record) | ||
|
||
|
||
def configure_logger(name, level, with_color=False): | ||
logger = logging.getLogger(name) | ||
logger.setLevel(level) | ||
stream_handler = logging.StreamHandler() | ||
formatter = CustomFormatter("%(message)s", with_color=with_color) | ||
stream_handler.setFormatter(formatter) | ||
logger.addHandler(stream_handler) | ||
return logger | ||
|
||
|
||
logger = configure_logger("logger", logging.DEBUG) | ||
colorful_logger = configure_logger("colorful_logger", logging.DEBUG, with_color=True) |
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,28 @@ | ||
# Used to abstract away concrete uses of MLflow model flavors. | ||
# Based on the provided flavor from the FLOps SLA the specific MLflow model flavor will be used. | ||
|
||
import os | ||
import sys | ||
|
||
from flops_utils.logging import logger | ||
from flops_utils.types import MLModelFlavor | ||
|
||
|
||
def get_ml_model_flavor(): | ||
match MLModelFlavor(os.environ.get("ML_MODEL_FLAVOR")): | ||
case MLModelFlavor.KERAS: | ||
import mlflow.keras # type: ignore | ||
|
||
return mlflow.keras | ||
case MLModelFlavor.PYTORCH: | ||
import mlflow.pytorch # type: ignore | ||
|
||
return mlflow.pytorch | ||
|
||
case MLModelFlavor.SKLEARN: | ||
import mlflow.sklearn # type: ignore | ||
|
||
return mlflow.sklearn | ||
case _: | ||
logger.exception("Provided MLModelFlavor is not supported yet.") | ||
sys.exit(1) |
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 @@ | ||
from .flops_learner_files_proxy import load_dataset |
28 changes: 28 additions & 0 deletions
28
utils_library/flops_utils/ml_repo_building_blocks/flops_learner_files_proxy.py
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,28 @@ | ||
# Note: This proxy is used to provide ML repo developers/users with stub FLOps Learner components. | ||
# E.g. The ML repo developer does not have access to any data of the worker nodes yet. | ||
# This data will be fetched by the Learner's data_loading from the Data Manager Sidecar. | ||
# This data_loading is part of the Learner image and should be abstracted away from the ML repo. | ||
# To be able to include the data_loading methods in the ML repo code these mocks are provided. | ||
# These mocks will be replaced with the real implementation during the FLOps image build process. | ||
|
||
import sys | ||
|
||
import datasets # type: ignore | ||
|
||
from flops_utils.logging import logger | ||
|
||
|
||
def load_dataset() -> datasets.Dataset: | ||
"""Loads the data from the co-located ml-data-server from the learner node. | ||
Returns a single dataset that encompasses all matching found data from the server. | ||
This dataset is in "Arrow" format. | ||
""" | ||
|
||
try: | ||
from data_loading import load_data_from_ml_data_server # type: ignore | ||
|
||
return load_data_from_ml_data_server() | ||
except ImportError: | ||
logger.exception("The data_loading file was not found.") | ||
sys.exit(1) |
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,18 @@ | ||
# Note: This proxy is used to handle ml repo files | ||
# which get injected during the image build. | ||
# I.e. these files are not yet present. | ||
# Additionally it handles exceptions and helps linters, etc to work normally. | ||
|
||
import sys | ||
|
||
from flops_utils.logging import logger | ||
|
||
|
||
def get_model_manager(): | ||
try: | ||
from model_manager import ModelManager # type: ignore | ||
|
||
return ModelManager() | ||
except ImportError: | ||
logger.exception("A ML repo file was not found.") | ||
sys.exit(1) |
Oops, something went wrong.