Skip to content

Commit

Permalink
Backend branch (#58)
Browse files Browse the repository at this point in the history
* WIP: Tensorflow MNIST use-case

* UPDATE: Tensorflow MNIST version

* ADD: Backend

* ADD: Use-case init

* FIX: Paths and downloading of the data

* FIX: Paths and downloading of the data

* ADD: Setup, Config update

* ADD: Setup, Config update

* UPDATE: File movement into itwinai

* FIX: Move utils from tensorflow to global folder

* FIX: Add setup into torch Executable

* ADD: MNIST Torch Use-case

* FIX: Formatting
  • Loading branch information
User3574 authored Jul 18, 2023
1 parent c152955 commit a22de0b
Show file tree
Hide file tree
Showing 64 changed files with 2,185 additions and 1,107 deletions.
1 change: 0 additions & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
# These owners will be the default owners for everything in the repo.
# Unless a later match takes precedence, they will be requested for
# review when someone opens a pull request.

10 changes: 2 additions & 8 deletions ai/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@
version="0.1",
packages=find_packages("src"),
package_dir={"": "src"},
entry_points={
"console_scripts": [
"itwinai=itwinai.cli:app"
]
},
entry_points={"console_scripts": ["itwinai=itwinai.cli:app"]},
# Pip dependencies
install_requires=[
'jsonargparse[signatures]>=4.17.0'
]
install_requires=["jsonargparse[signatures]>=4.17.0"],
)
File renamed without changes.
63 changes: 63 additions & 0 deletions ai/src/itwinai/backend/components.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from abc import ABCMeta, abstractmethod


class Executable(metaclass=ABCMeta):
@abstractmethod
def execute(self, args):
pass

@abstractmethod
def setup(self, args):
pass


class Trainer(Executable):
@abstractmethod
def train(self, data):
pass


class DataGetter(Executable):
@abstractmethod
def load(self, args):
pass


class DataPreproc(Executable):
@abstractmethod
def preproc(self, args):
pass


class StatGetter(Executable):
@abstractmethod
def stats(self, args):
pass


class Evaluator(Executable):
@abstractmethod
def evaluate(self, args):
pass


class Saver(Executable):
@abstractmethod
def save(self, args):
pass


class Executor(Executable):
@abstractmethod
def execute(self, pipeline):
pass

@abstractmethod
def setup(self, pipeline):
pass


class Logger(metaclass=ABCMeta):
@abstractmethod
def log(self):
pass
Empty file.
15 changes: 15 additions & 0 deletions ai/src/itwinai/backend/tensorflow/executor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from ..components import Executor


class TensorflowExecutor(Executor):
def __init__(self, args):
self.args = args

def execute(self, pipeline):
args = None
for executable in pipeline:
args = executable.execute(args)

def setup(self, pipeline):
for executable in pipeline:
executable.setup(self.args)
22 changes: 22 additions & 0 deletions ai/src/itwinai/backend/tensorflow/loggers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import wandb
import mlflow
import mlflow.keras

from ..components import Logger


class WanDBLogger(Logger):
def __init__(self):
pass

def log(self):
wandb.init(config={"bs": 12})


class MLFlowLogger(Logger):
def __init__(self):
mlflow.set_tracking_uri("http://127.0.0.1:5000")
mlflow.set_experiment("test-experiment")

def log(self):
mlflow.keras.autolog()
13 changes: 13 additions & 0 deletions ai/src/itwinai/backend/tensorflow/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import keras
import json


def model_to_json(model: keras.Model, filepath: str):
with open(filepath, "w") as f:
json.dump(model.to_json(), f)


def model_from_json(filepath: str) -> keras.Model:
with open(filepath, "r") as f:
config = json.load(f)
return keras.models.model_from_json(config)
Empty file.
16 changes: 16 additions & 0 deletions ai/src/itwinai/backend/torch/executor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from ..components import Executor


class TorchExecutor(Executor):
def __init__(self):
pass

def execute(self, pipeline):
args = None
for executable in pipeline:
args = executable.execute(args)

def setup(self, pipeline):
args = None
for executable in pipeline:
args = executable.setup(args)
22 changes: 22 additions & 0 deletions ai/src/itwinai/backend/torch/loggers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import wandb
import mlflow
import mlflow.keras

from ..components import Logger


class WanDBLogger(Logger):
def __init__(self):
pass

def log(self):
wandb.init(config={"bs": 12})


class MLFlowLogger(Logger):
def __init__(self):
mlflow.set_tracking_uri("http://127.0.0.1:5000")
mlflow.set_experiment("test-experiment")

def log(self):
mlflow.pytorch.autolog()
13 changes: 13 additions & 0 deletions ai/src/itwinai/backend/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import yaml


# Parse (part of) YAML loaded in memory
def parse_pipe_config(yaml_file, parser):
with open(yaml_file, "r", encoding="utf-8") as f:
try:
config = yaml.safe_load(f)
except yaml.YAMLError as exc:
print(exc)
raise exc

return parser.parse_object(config)
Loading

0 comments on commit a22de0b

Please sign in to comment.