Skip to main content

Milalib

Milalib is a library of helpers for Mila researchers to properly use the computing resources at their disposal.

All the listed functionality should work in slurm jobs on the Mila cluster. They may or may not work on DRAC clusters (I can report it doesn't work on Fir) -- you are welcome to try and report.

Monitoring GPU/resource usage

Monitoring resources is a little tricky for a few reasons:

  • nvidia-smi's GPU utilization reporting is very loose-grained, leading to overestimation
  • More precise profiling metrics such as sm_occupancy are exposed via DCGM
  • CPU/RAM measurements require knowing what was allocated to your job, which is hidden deep in /sys/fs/cgroup.

Milalib does all the above for you.

You can run the monitor standalone with uvx. It outputs one measurement per line in JSON format.

# Monitor continuously, sampling every 3 seconds (default is 5 seconds)
uvx milalib monitor -i 3

# Get a single sample and quit
uvx milalib monitor -s

# List all available metrics
uvx milalib monitor -l

# Monitor some metrics specifically:
uvx milalib monitor -m sm_occupancy -m gpu_util

# Pipe to jq to only get the numeric value
uvx milalib monitor -m sm_occupancy | jq .value

# Only output metrics for the first GPU
uvx milalib monitor -d gpu0

# Only output GPU metrics
uvx milalib monitor -d 'gpu.*'

You may also install milalib with pip install milalib or uv add milalib.

Wandb integration

If you use wandb for experiment logging, you can also log the monitoring metrics:

from milalib.wandb import monitor

watcher = monitor(
    interval=5,
    metrics=["gpu_util", "power"],
    devices=["gpu0"],
    log=wandb.log,  # optional, defaults to wandb.log
)
...  # train
watcher.stop()

[!TIP] Run milalib monitor -l to view the list of available metrics.

Or, scoped to a block:

with monitor(interval=5):
    ...  # train

Interface

milalib exposes an async generator for the metrics, streaming objects of type MetricValue. Use it like this:

import asyncio

from milalib.monitor.poll import MetricRequest
from milalib.monitor.stream import stream_metrics


async def main():
    request = MetricRequest(metrics=["sm_occupancy"])
    async for value in stream_metrics(request, interval=0.1):
        print(value.timestamp, value.device, value.name, value.statistic, value.value)


asyncio.run(main())

Metadata

Release files for milalib 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for milalib 0.0.2
File Size Uploaded
milalib-0.0.2.tar.gz 16.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for milalib 0.0.2
File Interpreter ABI Platform
milalib-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 37.9 kB

Release files / milalib-0.0.2.tar.gz

Download URL milalib-0.0.2.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a00ca53875459221d611605a3e726562ac3821cd1025e75ab7b1959da93d14fe
BLAKE2b-256 checksum
How to use checksums
20d2acf34cbfd3f380ccdce03b19f0752d68838ef07cb46ac77ae6c017d51c9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release files / milalib-0.0.2-py3-none-any.whl

Download URL milalib-0.0.2-py3-none-any.whl
Size 21.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3402931093e8ed8690178d89708cfde91abc98087441729d8da681816ec709ee
BLAKE2b-256 checksum
How to use checksums
f08bdc4a70e041e6eef2290ce34771c67b35e624300c4b5685530d629cacf54f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.

Transparency log

Release history Release notifications | RSS feed

0.0.3

2 release files

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page