ML for Developers

This commit is contained in:
GokuMohandas
2023-07-26 04:53:11 -07:00
commit 776a75b010
54 changed files with 55464 additions and 0 deletions

21
.github/workflows/documentation.yaml vendored Normal file
View File

@@ -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
.github/workflows/json_to_md.py vendored Normal file
View File

@@ -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
.github/workflows/serve.yaml vendored Normal file
View File

@@ -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
.github/workflows/workloads.yaml vendored Normal file
View File

@@ -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