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.3

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.3
File Size Uploaded
milalib-0.0.3.tar.gz 16.6 kB Details

Built distribution (wheel)

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

Total release size: 37.9 kB

Release files / milalib-0.0.3.tar.gz

Download URL milalib-0.0.3.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3715b73087f364d1563087b0700e408d3fbafbc5ce19b33f6d3354657e58b26a
BLAKE2b-256 checksum
How to use checksums
7fdc72d6ffa2f8b365217562543aa18eef881622f586fd9dd4ecea5560115ed9
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.3-py3-none-any.whl

Download URL milalib-0.0.3-py3-none-any.whl
Size 21.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db13ee298abc32de9ef6682a046deaa3b5c3fcc6c613df4d18b4964775e73309
BLAKE2b-256 checksum
How to use checksums
0512d9c4675165beef4c2b8702a32282a7d96ae525c89541b2d8c0c4ddfd79ce
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

This release

0.0.3 This release

2 release files

0.0.2

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