Skip to content

Commit

Permalink
Release v1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
PedramBakh committed Dec 6, 2022
1 parent d00e5b9 commit 449752b
Show file tree
Hide file tree
Showing 25 changed files with 753 additions and 310 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.7, 3.8, 3.9, '3.10']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI

on:
release:
types: [published]

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@master
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution 📦 to Test PyPI
if: startsWith(github.ref, 'refs/tags/test')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags') && !startsWith(github.ref, 'refs/tags/test')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
180 changes: 164 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,167 @@
*__pycache__
__pycache__
.DS_Store
data/
dist/
logs/
bin
develop-eggs
downloads
eggs
parts
*.egg-info
lib
lib64
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

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

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.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/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# VS Code
.vscode/
.vscode

# macOS
.DS_Store
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# **carbontracker**
[![pypi](https://img.shields.io/pypi/v/carbontracker?label=pypi)](https://pypi.org/project/carbontracker/)
[![Python 3.6](https://img.shields.io/pypi/pyversions/django?color=blue&logo=python)](https://www.python.org/downloads/)
[![Python](https://img.shields.io/badge/python-%3E%3D3.7-blue)](https://www.python.org/downloads/)
[![build](https://github.com/lfwa/carbontracker/workflows/build/badge.svg)](https://github.com/lfwa/carbontracker/actions)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/lfwa/carbontracker/blob/master/LICENSE)
[![License](https://img.shields.io/github/license/lfwa/carbontracker)](https://github.com/lfwa/carbontracker/blob/master/LICENSE)

## About
**carbontracker** is a tool for tracking and predicting the energy consumption and carbon footprint of training deep learning models as described in [Anthony et al. (2020)](https://arxiv.org/abs/2007.03051).
Expand Down Expand Up @@ -49,6 +49,8 @@ pip install carbontracker
If True, only devices (under the chosen components) running processes associated with the main process are measured. If False, all available devices are measured (see Section 'Notes' for jobs running on SLURM or in containers). Note that this requires your devices to have active processes before instantiating the `CarbonTracker` class.
- `log_dir` (default=None):
Path to the desired directory to write log files. If None, then no logging will be done.
- `log_file_prefix` (default=""):
Prefix to add to the log file name.
- `verbose` (default=1):
Sets the level of verbosity.
- `decimal_precision` (default=6):
Expand Down
6 changes: 0 additions & 6 deletions carbontracker/__version__.py

This file was deleted.

54 changes: 29 additions & 25 deletions carbontracker/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
from carbontracker.components.gpu import nvidia
from carbontracker.components.cpu import intel

components = [{
"name": "gpu",
"error": exceptions.GPUError("No GPU(s) available."),
"handlers": [nvidia.NvidiaGPU]
}, {
"name": "cpu",
"error": exceptions.CPUError("No CPU(s) available."),
"handlers": [intel.IntelCPU]
}]
components = [
{"name": "gpu", "error": exceptions.GPUError("No GPU(s) available."), "handlers": [nvidia.NvidiaGPU]},
{"name": "cpu", "error": exceptions.CPUError("No CPU(s) available."), "handlers": [intel.IntelCPU]},
]


def component_names():
Expand All @@ -35,10 +30,8 @@ class Component:
def __init__(self, name, pids, devices_by_pid):
self.name = name
if name not in component_names():
raise exceptions.ComponentNameError(
f"No component found with name '{self.name}'.")
self._handler = self._determine_handler(pids=pids,
devices_by_pid=devices_by_pid)
raise exceptions.ComponentNameError(f"No component found with name '{self.name}'.")
self._handler = self._determine_handler(pids=pids, devices_by_pid=devices_by_pid)
self.power_usages = []
self.cur_epoch = -1 # Sentry

Expand Down Expand Up @@ -75,20 +68,35 @@ def collect_power_usage(self, epoch):
if diff != 0:
for _ in range(diff):
# Copy previous measurement lists.
latest_measurements = self.power_usages[
-1] if self.power_usages else []
latest_measurements = self.power_usages[-1] if self.power_usages else []
self.power_usages.append(latest_measurements)
self.power_usages.append([])

self.power_usages[-1].append(self.handler.power_usage())
try:
self.power_usages[-1].append(self.handler.power_usage())
except exceptions.IntelRaplPermissionError:
# Only raise error if no measurements have been collected.
if not self.power_usages[-1]:
print(
"No sudo access to read Intel's RAPL measurements from the energy_uj file."
"\nSee issue: https://github.com/lfwa/carbontracker/issues/40"
)
# Append zero measurement to avoid further errors.
self.power_usages.append([0])
except exceptions.GPUPowerUsageRetrievalError:
if not self.power_usages[-1]:
print(
"GPU model does not support retrieval of power usages in NVML."
"\nSee issue: https://github.com/lfwa/carbontracker/issues/36"
)
# Append zero measurement to avoid further errors.
self.power_usages.append([0])

def energy_usage(self, epoch_times):
"""Returns energy (kWh) used by component per epoch."""
energy_usages = []
# We have to compute each epoch in a for loop since numpy cannot
# handle lists of uneven length.
for idx, (power, time) in enumerate(zip(self.power_usages,
epoch_times)):
for idx, (power, time) in enumerate(zip(self.power_usages, epoch_times)):
# If no power measurement exists, try to use measurements from
# later epochs.
while not power and idx != len(self.power_usages) - 1:
Expand Down Expand Up @@ -124,12 +132,8 @@ def shutdown(self):
def create_components(components, pids, devices_by_pid):
components = components.strip().replace(" ", "").lower()
if components == "all":
return [
Component(name=comp_name, pids=pids, devices_by_pid=devices_by_pid)
for comp_name in component_names()
]
return [Component(name=comp_name, pids=pids, devices_by_pid=devices_by_pid) for comp_name in component_names()]
else:
return [
Component(name=comp_name, pids=pids, devices_by_pid=devices_by_pid)
for comp_name in components.split(",")
Component(name=comp_name, pids=pids, devices_by_pid=devices_by_pid) for comp_name in components.split(",")
]
Loading

0 comments on commit 449752b

Please sign in to comment.