Skip to content

Commit

Permalink
MLOps course -> ML for Developers
Browse files Browse the repository at this point in the history
  • Loading branch information
GokuMohandas committed Jul 26, 2023
0 parents commit de51e65
Show file tree
Hide file tree
Showing 54 changed files with 55,442 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: documentation
on:
push:
branches:
- main

jobs:
build-docs:
runs-on: ubuntu-22.04
steps:
# Set up dependencies
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10.11'
cache: 'pip'
- run: python3 -m pip install mkdocs==1.4.2 mkdocstrings==0.21.2 "mkdocstrings[python]>=0.18"

# Deploy docs
- name: Deploy documentation
run: mkdocs gh-deploy --force
64 changes: 64 additions & 0 deletions .github/workflows/json_to_md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import json
import sys


def to_markdown(data):
markdown = ""
for key, value in data.items():
markdown += f"**{key}:**\n\n"
if isinstance(value, dict):
markdown += "| Key | Value |\n| --- | --- |\n"
for nested_key, nested_value in value.items():
nested_value = (
round(nested_value, 3)
if isinstance(nested_value, float)
else {k: round(v, 3) for k, v in nested_value.items()}
if isinstance(nested_value, dict)
else nested_value
)
markdown += f"| {nested_key} | {nested_value} |\n"
elif isinstance(value, list) and all(isinstance(item, dict) for item in value):
if value:
headers = sorted(set().union(*[item.keys() for item in value]))
markdown += "| " + " | ".join(headers) + " |\n| " + " | ".join(["---"] * len(headers)) + " |\n"
for item in value:
value_list = [
"{:.3e}".format(float(item.get(header, ""))) if not str(item.get(header, "")).isdigit() else str(item.get(header, ""))
for header in headers
]
markdown += "| " + " | ".join(value_list) + " |\n"
else:
markdown += "(empty list)\n"
else:
markdown += f"{value}\n"
markdown += "\n"
return markdown


def json_to_markdown(json_fp, md_fp):
"""Convert a json file to markdown."""
# Read JSON file
with open(json_fp, "r") as file:
data = json.load(file)

# Convert to markdown
markdown = to_markdown(data)

# Save to markdown file
with open(md_fp, "w") as file:
file.write(markdown)
return markdown


if __name__ == "__main__":
# Check if the correct number of arguments is provided
if len(sys.argv) < 3:
print("Usage: python script.py <json_file> <output_file>")
sys.exit(1)

# Get the JSON file path and output Markdown file path from command-line arguments
json_file = sys.argv[1]
md_file = sys.argv[2]

# Call the JSON to Markdown conversion function
json_to_markdown(json_file, md_file)
35 changes: 35 additions & 0 deletions .github/workflows/serve.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: serve
on:
workflow_dispatch: # manual
push:
branches:
- main
permissions: write-all

jobs:
serve:
runs-on: ubuntu-22.04
steps:

# Configure AWS credentials
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::593241322649:role/github-actions-madewithml
role-session-name: s3access
aws-region: us-west-2

# Set up dependencies
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10.11'
cache: 'pip'
- run: python3 -m pip install anyscale==0.5.131 typer==0.9.0

# Serve model
- name: Serve model
run: |
export ANYSCALE_HOST=${{ secrets.ANYSCALE_HOST }}
export ANYSCALE_CLI_TOKEN=${{ secrets.ANYSCALE_CLI_TOKEN }}
anyscale service rollout --service-config-file deploy/services/serve_model.yaml
53 changes: 53 additions & 0 deletions .github/workflows/workloads.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: workloads
on:
workflow_dispatch: # manual
pull_request:
branches:
- main
permissions: write-all

jobs:
workloads:
runs-on: ubuntu-22.04
steps:

# Configure AWS credentials
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::593241322649:role/github-actions-madewithml
role-session-name: s3access
aws-region: us-west-2

# Set up dependencies
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10.11'
cache: 'pip'
- run: python3 -m pip install anyscale==0.5.131 typer==0.9.0

# Run workloads
- name: Workloads
run: |
export ANYSCALE_HOST=${{ secrets.ANYSCALE_HOST }}
export ANYSCALE_CLI_TOKEN=${{ secrets.ANYSCALE_CLI_TOKEN }}
anyscale jobs submit deploy/jobs/workloads.yaml --wait
# Read results from S3
- name: Read results from S3
run: |
mkdir results
aws s3 cp s3://madewithml/${{ github.actor }}/results/ results/ --recursive
python .github/workflows/json_to_md.py results/training_results.json results/training_results.md
python .github/workflows/json_to_md.py results/evaluation_results.json results/evaluation_results.md
# Comment results to PR
- name: Comment training results on PR
uses: thollander/actions-comment-pull-request@v2
with:
filePath: results/training_results.md
- name: Comment evaluation results on PR
uses: thollander/actions-comment-pull-request@v2
with:
filePath: results/evaluation_results.md
110 changes: 110 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Data
logs/
stores/
mlflow/
results/
workspaces/

# VSCode
.vscode/
.idea

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Flask:
instance/
.webassets-cache

# Scrapy:
.scrapy

# Sphinx
docs/_build/

# PyBuilder
target/

# IPython
.ipynb_checkpoints
profile_default/
ipython_config.py

# pyenv
.python-version

# PEP 582
__pypackages__/

# Celery
celerybeat-schedule
celerybeat.pid

# Environment
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# mkdocs
site/

# Airflow
airflow/airflow.db

# MacOS
.DS_Store

# Clean up
.trash/
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-merge-conflict
- id: check-yaml
- id: check-added-large-files
args: ['--maxkb=1000']
exclude: "notebooks"
- id: check-yaml
exclude: "mkdocs.yml"
- repo: local
hooks:
- id: clean
name: clean
entry: make
args: ["clean"]
language: system
pass_filenames: false
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Made With ML

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Makefile
SHELL = /bin/bash

# Styling
.PHONY: style
style:
black .
flake8
python3 -m isort .
pyupgrade

# Cleaning
.PHONY: clean
clean: style
find . -type f -name "*.DS_Store" -ls -delete
find . | grep -E "(__pycache__|\.pyc|\.pyo)" | xargs rm -rf
find . | grep -E ".pytest_cache" | xargs rm -rf
find . | grep -E ".ipynb_checkpoints" | xargs rm -rf
rm -rf .coverage*
Loading

0 comments on commit de51e65

Please sign in to comment.