Skip to content

Commit

Permalink
reformatted by black
Browse files Browse the repository at this point in the history
  • Loading branch information
konabuta committed Nov 2, 2022
1 parent 318500d commit 377d3d4
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 182 deletions.
33 changes: 5 additions & 28 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,10 @@

FROM mcr.microsoft.com/vscode/devcontainers/miniconda:0-3

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# Copy environment.yml (if found) to a temp location so we update the environment. Also
# copy "noop.txt" so the COPY instruction does not fail if no environment.yml exists.
COPY environment.yml* .devcontainer/noop.txt /tmp/conda-tmp/
RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then umask 0002 && /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi \
&& rm -rf /tmp/conda-tmp

# [Optional] Uncomment to install a different version of Python than the default
# RUN conda install -y python=3.6 \
# && pip install --no-cache-dir pipx \
# && pipx reinstall-all

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

RUN curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
RUN echo "az extension add -n ml -y" | bash
RUN echo "az ml -h" | bash


COPY ./environments/requirements.txt /environments/
RUN conda create -y --name mlops-train python=3.8

SHELL ["conda", "run", "-n", "mlops-train", "/bin/bash", "-c"]
RUN conda create -y --name mlops-train python=3.8 && \
/bin/bash -c "source activate mlops-train" && \
pip install -r /environments/requirements.txt

RUN pip install -r /environments/requirements.txt
COPY .pre-commit-config.yaml .
RUN git init . && pre-commit install-hooks
50 changes: 11 additions & 39 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,25 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.238.1/containers/python-3-miniconda
{
"name": "Miniconda (Python 3)",
"build": {
"build": {
"context": "..",
"dockerfile": "Dockerfile",
"args": {
"NODE_VERSION": "lts/*"
}
},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/opt/conda/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
"settings": {
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
},
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
]
"ms-python.vscode-pylance",
"ms-toolsai.vscode-ai"
],
"onCreateCommand": "az extension add -n ml -y"
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "python --version",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"azure-cli": "latest",
"homebrew": "latest"
}
}
4 changes: 2 additions & 2 deletions .devcontainer/noop.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
This file is copied into the container along with environment.yml* from the
parent folder. This is done to prevent the Dockerfile COPY instruction from
failing if no environment.yml is found.
parent folder. This is done to prevent the Dockerfile COPY instruction from
failing if no environment.yml is found.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ jobs:
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
Expand All @@ -61,7 +61,7 @@ jobs:
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/smoke-testing.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: smoke-testing
on:
push:
push:
branches:
- main
pull_request:
Expand All @@ -10,13 +10,13 @@ on:
- cron: "0 0 * * *"
jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup python
uses: actions/[email protected]
with:
with:
python-version: "3.9"
- name: pip install
run: pip install black[jupyter]==22.8.0
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
rev: 22.6.0
hooks:
- id: black
language_version: python3.8
language_version: python3

# import 並び替え
- repo: https://github.com/pycqa/isort
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"python.linting.flake8Enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.enabled": true
}
}
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Instead, please report them to the Microsoft Security Response Center (MSRC) at

If you prefer to submit without logging in, send email to [[email protected]](mailto:[email protected]). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).

You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).

Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:

Expand Down
8 changes: 4 additions & 4 deletions SUPPORT.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Support

## How to file issues and get help
## How to file issues and get help

This project uses GitHub Issues to track bugs and feature requests. Please search the existing
issues before filing new issues to avoid duplicates. For new issues, file your bug or
This project uses GitHub Issues to track bugs and feature requests. Please search the existing
issues before filing new issues to avoid duplicates. For new issues, file your bug or
feature request as a new Issue.

For help and questions about using this project, please contact our team via GitHub Issues.

## Microsoft Support Policy
## Microsoft Support Policy

Support for this project is limited to the resources listed above.
4 changes: 2 additions & 2 deletions assets/create-compute.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$schema: https://azuremlschemas.azureedge.net/latest/amlCompute.schema.json
$schema: https://azuremlschemas.azureedge.net/latest/amlCompute.schema.json
name: cpu-cluster
type: amlcompute
size: STANDARD_DS3_v2
min_instances: 0
max_instances: 4
idle_time_before_scale_down: 300
idle_time_before_scale_down: 300
2 changes: 1 addition & 1 deletion assets/create-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name: nyc_taxi_dataset
description: nyc_taxi_dataset.
type: uri_file
version: 1
path: ../data/raw/nyc_taxi_dataset.csv
path: ../data/raw/nyc_taxi_dataset.csv
2 changes: 1 addition & 1 deletion assets/create-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name: nyc-taxi-env
image: mcr.microsoft.com/azureml/openmpi3.1.2-ubuntu18.04
version: 1
conda_file: ../environments/conda_train.yml
description: nyc-taxi-env
description: nyc-taxi-env
2 changes: 1 addition & 1 deletion environments/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ matplotlib
black
flake8
pytest
pre-commit
pre-commit
2 changes: 1 addition & 1 deletion jobs/batch_endpoint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$schema: https://azuremlschemas.azureedge.net/latest/batchEndpoint.schema.json
name: batch-endpoint
description: endpoint for batch-deployment
auth_mode: aad_token
auth_mode: aad_token
17 changes: 6 additions & 11 deletions src/deploy/score.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os

import numpy as np
from mlflow.pyfunc import load_model


# Called when the service is loaded
def init():
global model
Expand All @@ -15,21 +17,14 @@ def init():


def run(mini_batch):
print(
f"run method start: {__file__}, run({mini_batch})"
)
print(f"run method start: {__file__}, run({mini_batch})")

for input in mini_batch:
input_np = np.loadtxt(
input, delimiter=",", skiprows=1
)
input_np = np.loadtxt(input, delimiter=",", skiprows=1)
predictions = model.predict(input_np)
log_txt = "Predictions:" + str(
predictions
)
log_txt = "Predictions:" + str(predictions)
print(log_txt)

return [
[row, pred]
for row, pred in enumerate(predictions)
[row, pred] for row, pred in enumerate(predictions)
] # return a dataframe or a list
50 changes: 33 additions & 17 deletions src/model/register_model.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import argparse, os
import argparse
import os
from pathlib import Path

import mlflow
from mlflow.pyfunc import load_model


def parse_args():

parser = argparse.ArgumentParser()
parser.add_argument('--model_name', type=str, help='Name under which model will be registered')
parser.add_argument('--model_path', type=str, help='Model directory')
parser.add_argument('--deploy_flag', type=str, help='A deploy flag whether to deploy or no')

parser.add_argument(
"--model_name",
type=str,
help="Name under which model will be registered",
)
parser.add_argument(
"--model_path",
type=str,
help="Model directory",
)
parser.add_argument(
"--deploy_flag",
type=str,
help="A deploy flag whether to deploy or no",
)

args, _ = parser.parse_known_args()
print(f'Arguments: {args}')
print(f"Arguments: {args}")

return args

Expand All @@ -29,30 +43,32 @@ def main():
model_name = args.model_name
model_path = args.model_path

if len(args.deploy_flag) == 1: # this is the case where deploy_flag is a digit
if len(args.deploy_flag) == 1: # this is the case where deploy_flag is a digit
deploy_flag = int(args.deploy_flag)
else: # this is the case where deploy_flag is a path name
with open((Path(args.deploy_flag) / "deploy_flag"), 'rb') as f:
else: # this is the case where deploy_flag is a path name
with open(
(Path(args.deploy_flag) / "deploy_flag"),
"rb",
) as f:
deploy_flag = int(f.read())

if deploy_flag==1:
if deploy_flag == 1:

print("Registering ", model_name)

model = load_model(os.path.join(model_path, 'models'))
# log model using mlflow
model = load_model(os.path.join(model_path, "models"))
# log model using mlflow
mlflow.sklearn.log_model(model, model_name)
#mlflow.sklearn.log_model(sk_model=model, artifact_path="models", registered_model_name=model_name)

# register model using mlflow model
model_uri = f'runs:/{run_id}/{args.model_name}'
model_uri = f"runs:/{run_id}/{args.model_name}"
mlflow.register_model(model_uri, model_name)

else:
print("Model will not be registered!")

mlflow.end_run()


if __name__ == "__main__":
main()
main()
Loading

0 comments on commit 377d3d4

Please sign in to comment.