Skip to main content

Lightweight training awareness system for machine learning workflows.

Project description

TrainWatcher

A lightweight training awareness system for machine learning workflows.

TrainWatcher notifies developers when ML training completes or fails and provides a minimal run summary. It is designed to be easy to integrate, framework-agnostic, and reliable.

Developed and managed by Sambit Mahapatra.

Install

pip install trainwatcher

Quickstart

from trainwatcher import monitor

monitor.start()

try:
    # Your training loop here.
    monitor.log(epoch=1, loss=0.42, val_acc=0.81)
    monitor.end()
except Exception as exc:
    monitor.fail(exc)
    raise

Convenience context manager:

from trainwatcher import monitor

with monitor.watch():
    # Your training loop here.
    pass

Configuration

TrainWatcher reads configuration from trainwatcher_config.yaml by default. You can also set TRAINWATCHER_CONFIG to an absolute path or pass a config dict to monitor.end(config=...) and monitor.fail(config=...).

Example config (YAML):

notifications:
  email: true
  telegram: false

email:
  host: smtp.example.com
  port: 587
  username: user@example.com
  password: app_password
  sender: user@example.com
  recipient: user@example.com
  use_tls: true
  subject: TrainWatcher Notification

logging:
  enabled: true
  path: trainwatcher_run.json

An example config is available at examples/trainwatcher_config.yaml.

Cloud Notifications (Resend + Cloudflare)

If you want users to receive email without SMTP setup, use the TrainWatcher Cloud backend.

  1. Deploy the Cloudflare Worker in cloudflare/ and set RESEND_API_KEY and RESEND_FROM.
  2. If you self-host, set the backend URL locally:
export TRAINWATCHER_BASE_URL="https://your-worker.workers.dev"
  1. Register an email once:
from trainwatcher import add_email

add_email("you@example.com")

After that, monitor.end() and monitor.fail() will send notifications automatically if credentials exist. If you use the hosted TrainWatcher backend, no base URL is required. You can inspect the active backend URL with:

from trainwatcher import get_base_url
print(get_base_url())

Cloud backend enforces a default limit of 10 emails per user per day.

To remove the email:

from trainwatcher import delete_email

delete_email()

CLI

You can also register/delete emails via the CLI:

trainwatcher add-email you@example.com
trainwatcher delete-email
trainwatcher help

Mid-Run Notifications

Manual milestone:

from trainwatcher import monitor

monitor.notify("Model loaded on GPU")

Time-based heartbeat:

monitor.heartbeat(interval_seconds=900)  # every 15 minutes
# ...
monitor.stop_heartbeat()

Step-based pings:

for epoch in range(100):
    train()
    monitor.step(notify_every=10)

Configure defaults once:

monitor.configure(
    heartbeat_interval=900,
    step_notify_every=10,
    heartbeat_message="Training still running",
)

Optional per-channel minimum intervals:

limits:
  email_min_interval_seconds: 1800
  telegram_min_interval_seconds: 300
  cloud_min_interval_seconds: 1800

Environment Variables

These environment variables override config values when set.

  • TRAINWATCHER_CONFIG
  • TRAINWATCHER_BASE_URL
  • TRAINWATCHER_API_KEY
  • TRAINWATCHER_CREDENTIALS_PATH
  • TRAINWATCHER_DISABLE_PROXY
  • TRAINWATCHER_NOTIFICATIONS_EMAIL
  • TRAINWATCHER_NOTIFICATIONS_TELEGRAM
  • TRAINWATCHER_EMAIL_HOST
  • TRAINWATCHER_EMAIL_PORT
  • TRAINWATCHER_EMAIL_USERNAME
  • TRAINWATCHER_EMAIL_PASSWORD
  • TRAINWATCHER_EMAIL_SENDER
  • TRAINWATCHER_EMAIL_RECIPIENT
  • TRAINWATCHER_EMAIL_USE_TLS
  • TRAINWATCHER_EMAIL_SUBJECT
  • TRAINWATCHER_TELEGRAM_BOT_TOKEN
  • TRAINWATCHER_TELEGRAM_CHAT_ID
  • TRAINWATCHER_LOGGING_ENABLED
  • TRAINWATCHER_LOGGING_PATH

Logging

Set logging.enabled: true in the config to write a run summary JSON file. The default path is trainwatcher_run.json relative to the config file location.

Testing

Install dev dependencies and run tests:

pip install -e .[dev]
pytest

Vision

TrainWatcher aims to become an intelligent training awareness layer that lets developers manage and monitor long-running training processes without constant supervision. The long-term goal is an intelligent training companion that integrates into broader ML tooling ecosystems and improves developer productivity.

Mission

Provide a lightweight, reliable, easy-to-integrate system that captures training lifecycle events and delivers concise summaries through notification channels such as email or messaging services. The mission prioritizes:

  • Simplicity of integration
  • Reliability of notifications
  • Minimal disruption to existing workflows

Problem Statement

Long-running ML training jobs often require repeated manual checks for completion or failure. This interrupts workflow and delays awareness of errors. Existing enterprise platforms are too heavy for many developers, and there is a gap for a simple, developer-friendly tool focused on basic training awareness.

Value Proposition

TrainWatcher allows developers to step away during training without losing awareness of outcomes. Minimal integration and reliable notifications reduce monitoring fatigue and improve experimentation efficiency.

License

Licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0). See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trainwatcher-0.2.1.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trainwatcher-0.2.1-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

Details for the file trainwatcher-0.2.1.tar.gz.

File metadata

  • Download URL: trainwatcher-0.2.1.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for trainwatcher-0.2.1.tar.gz
Algorithm Hash digest
SHA256 401ea3a66e15971027663704928b322a8a316fbc546898b4bb9cfde22cdb453c
MD5 98f140395cefc7f499f218b18ad3db48
BLAKE2b-256 7b27971caf2c4af00c9d8aa01623d53c41dc52ee7d644ae75be2c480c6a1b4cb

See more details on using hashes here.

File details

Details for the file trainwatcher-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: trainwatcher-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 25.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for trainwatcher-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 598afd19bca215d1cfd1f862da3a17bb520be05577424a281c2028ba2e8a0056
MD5 7409c21b9579dcf07942897bd5bdf62b
BLAKE2b-256 fd908a626867dac7335e41a48f2061bea255020534be5528ee1839ed8e480879

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page