Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inference flavor experiments #6

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9b527ff
add job script generation scripts for inference flavor comparison
mcw92 Sep 6, 2024
86fc9d8
disable input validation in sklearn
mcw92 Sep 10, 2024
1b98781
convert synthetic data to float32 to be able to disable sklearn's inp…
mcw92 Sep 10, 2024
760171a
convert imbalanced datasets also to np.float32
mcw92 Sep 10, 2024
54a4649
update coverage badge
github-actions[bot] Sep 10, 2024
46771f4
separate model checkpointing from saving of other results
mcw92 Sep 10, 2024
a1b3a75
Merge branch 'feature/inference_flavor' of https://github.com/Helmhol…
mcw92 Sep 10, 2024
21e297b
update coverage badge
github-actions[bot] Sep 10, 2024
17537cb
fix bug when scaling number of trees with nodes in for loop
mcw92 Sep 18, 2024
81d9fb3
introduce Codecov app and comment coverage report on PR
mcw92 Sep 23, 2024
e11b0ae
add Codecov and pre-commit CI badges
mcw92 Sep 23, 2024
d3d5bed
exclude tests from code coverage globally
mcw92 Sep 23, 2024
0bc09f2
appease pre-commit
mcw92 Sep 23, 2024
46f9e20
use matrix testing for OS and Python version
mcw92 Sep 23, 2024
7f4dc1d
remove Python 3.9 from version matrix
mcw92 Sep 23, 2024
ada5638
modify some comments, log strings, and docstrings
mcw92 Sep 24, 2024
3277b43
sort log prints and add additional safety backup of results after tra…
mcw92 Sep 24, 2024
c859881
update versions of pre-commit hooks
mcw92 Sep 24, 2024
e184d8a
introduce separate test dependencies
mcw92 Sep 24, 2024
f2b0f5c
Merge branch 'main' into feature/inference_flavor
mcw92 Sep 26, 2024
81e2dc4
add scripts for plotting and analysis of inference comparison exps
mcw92 Sep 26, 2024
7985a5f
add analysis script for inference flavor comparison
mcw92 Sep 30, 2024
a583f4e
add analysis script for weak scaling exps
mcw92 Sep 30, 2024
d616d3e
use base 2 in log plots
mcw92 Oct 1, 2024
cfb2153
add script to generate strong scaling job scripts
mcw92 Oct 1, 2024
9e73ab4
remove commented-out line
mcw92 Oct 1, 2024
8dab9a8
update script to use smaller-scale baselines
mcw92 Oct 1, 2024
4630b17
Merge branch 'feature/inference_flavor' of https://github.com/Helmhol…
mcw92 Oct 1, 2024
29227bb
update general scaling job script generation script
mcw92 Oct 9, 2024
7d6d003
Merge branch 'feature/inference_flavor' of https://github.com/Helmhol…
mcw92 Oct 9, 2024
736790b
remove manually created coverage badge
mcw92 Oct 9, 2024
466e803
update script to generation strong scaling job scripts
mcw92 Oct 9, 2024
5407c36
add job script generation script for pure parallel training
mcw92 Oct 9, 2024
7ea6241
add job script generation script for strong scaling serial baselines
mcw92 Oct 9, 2024
fbd4d2e
add overall consumed energy to plot
mcw92 Oct 9, 2024
a648bb3
add total energy consumed to plot
mcw92 Oct 9, 2024
e675087
add combined weak scaling plot for inference comparison
mcw92 Oct 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 53 additions & 50 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,59 @@
name: Python test

on: [push]
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest"]
python-version: [ "3.10", "3.11", "3.12" ]
mpi: [ "openmpi" ] # "mpich", "intelmpi"
# exclude:
# - os: "macos-latest"
# mpi: "intelmpi"

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- name: Set up MPI
uses: mpi4py/setup-mpi@v1
with:
mpi: 'openmpi'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ."[dev]"
pip install genbadge"[coverage]"
- name: Lint with ruff
run: |
# Stop the build if there are Python syntax errors or undefined names.
ruff check --output-format=github --select=E9,F63,F7,F82 --target-version=py39 .
# Default set of ruff rules with GitHub Annotations
ruff check --output-format=github --target-version=py39 .
- name: Test with pytest and measure coverage
run: |
coverage run --omit "*/tests/*" --rcfile=./pyproject.toml -m pytest
mpirun -n 4 coverage run --rcfile=./pyproject.toml -m mpi4py -m pytest --with-mpi
coverage combine
coverage report --omit "*/tests/*" -m
coverage xml
genbadge coverage -i coverage.xml -o coverage.svg
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v19
id: verify-changed-files
with:
files: coverage.svg

- name: Commit files
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add coverage.svg
git commit -m "update coverage badge"

- name: Push changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.github_token }}
branch: ${{ github.ref }}
- name: Check out repository
uses: actions/checkout@v4

- name: Setup MPI ${{ matrix.mpi }}
uses: mpi4py/setup-mpi@v1
with:
mpi: ${{ matrix.mpi }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ."[test]"

- name: Test with pytest and measure coverage
run: |
coverage run --rcfile=./pyproject.toml -m pytest
mpirun -n 4 coverage run --rcfile=./pyproject.toml -m mpi4py -m pytest --with-mpi
coverage combine
coverage report -m --format markdown > cov_report.txt
coverage xml

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Post coverage report to PR
uses: marocchino/sticky-pull-request-comment@v2
with:
path: cov_report.txt
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0 # Use the sha / tag you want to point at
rev: v1.11.2 # Use the sha / tag you want to point at
hooks:
- id: mypy
additional_dependencies: [types-all]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.10
rev: v0.6.7
hooks:
# Run the linter.
- id: ruff
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[![License: BSD-3](https://img.shields.io/badge/License-BSD--3-blue)](https://opensource.org/licenses/BSD-3-Clause)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![](https://img.shields.io/badge/Python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![codecov](https://codecov.io/gh/Helmholtz-AI-Energy/special-couscous/graph/badge.svg?token=ISGFUW08BK)](https://codecov.io/gh/Helmholtz-AI-Energy/special-couscous)
[![](https://img.shields.io/badge/Contact-marie.weiel%40kit.edu-blue)](mailto:marie.weiel@kit.edu)
![](./coverage.svg)

[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/Helmholtz-AI-Energy/special-couscous/main.svg)](https://results.pre-commit.ci/latest/github/Helmholtz-AI-Energy/special-couscous/main)
``specialcouscous`` is a Python package for large-scale distributed training and inference of random forests on
supercomputers. It uses the message passing interface (MPI) for communication between parallel processes.

Expand Down
1 change: 0 additions & 1 deletion coverage.svg

This file was deleted.

11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ dev = [
"sphinxemoji",
]

test = [
"coverage",
"pytest",
"pytest-cov",
"pytest-mpi"
]

[project.urls]
Homepage = "https://github.com/Helmholtz-AI-Energy/special-couscous"
Issues = "https://github.com/Helmholtz-AI-Energy/special-couscous/issues"
Expand Down Expand Up @@ -150,3 +157,7 @@ testpaths = [

[tool.coverage.run]
parallel = true
omit = ["*/tests/*"]

[tool.coverage.report]
omit = ["*/tests/*"]
42 changes: 40 additions & 2 deletions scripts/analysis/acc_drop.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pathlib
import re
import sys
from collections import defaultdict

Expand Down Expand Up @@ -52,19 +53,46 @@
global_test_accuracy
)

print(results)

for dirpath, dirnames, filenames in os.walk(root_dir):
for filename in filenames:
if filename.endswith(".out"):
parts = dirpath.split(os.sep)
number_of_tasks = int(parts[-2].split("_")[1])
data_seed = int(parts[-1].split("_")[1]) # Extract data seed from path.
model_seed = int(parts[-1].split("_")[2]) # Extract model seed from path.
pattern_energy = r"(?<=\/ )\d+(\.\d+)?(?= Watthours)"
with open(
os.path.join(dirpath, filename), "r"
) as file: # Load input text from the file.
input_text = file.read()
print(dirpath)
energy_match = re.search(pattern_energy, input_text)
energy_consumed = float(energy_match.group(0)) # type:ignore
print(f"Energy Consumed: {energy_consumed:.2f} Watthours")
results[(data_set, number_of_tasks, data_seed, model_seed)].append(
energy_consumed
)

print(results)

# Save the results to a pandas dataframe.
results_df = pd.DataFrame(
[(k[0], k[1], k[2], k[3], v[0]) for k, v in results.items()],
[(k[0], k[1], k[2], k[3], v[0], v[1]) for k, v in results.items()],
columns=[
"Dataset",
"Number of tasks",
"Data seed",
"Model seed",
"Global test accuracy",
"Energy consumed",
],
)
results_df = results_df.sort_values(by=["Number of tasks", "Data seed", "Model seed"])

overall_energy = results_df["Energy consumed"].sum()

avg_data_seeds = (
results_df.groupby(["Number of tasks", "Data seed"])
.agg({"Global test accuracy": "mean"})
Expand All @@ -78,7 +106,7 @@
)
print(avg_n_tasks)

plt.figure(figsize=(10, 6))
f, ax = plt.subplots(figsize=(10, 6))
plt.grid(True)

# Plot individual test accuracy vs number of tasks as small dots
Expand Down Expand Up @@ -128,6 +156,16 @@
fontweight="bold",
)
plt.legend(loc="lower left", fontsize="small")
energy_str = f"Overall {(overall_energy / 1000):.2f} kWh consumed"
ax.text(
0.75,
0.95,
energy_str,
transform=ax.transAxes,
fontsize="small",
verticalalignment="top",
fontweight="bold",
)
# plt.legend(loc='upper left', bbox_to_anchor=(0.5, 0.82), fontsize="small")
plt.savefig(pathlib.Path(root_dir) / f"{data_set}_acc_drop.png")

Expand Down
Loading
Loading