Skip to main content

No project description provided

Project description

nshrunner

nshrunner is a Python library that provides a unified way to run functions in various environments, such as local dev machines, cloud VMs, and SLURM clusters. It was created to simplify the process of running ML training jobs across multiple machines and environments.

Motivation

When running ML training jobs on different machines and environments, it can be challenging to manage the specifics of each environment. nshrunner was developed to address this issue by providing a single function that can be used to run jobs on any supported environment without having to worry about the details of each environment.

Features

  • Supports running functions locally, on SLURM clusters, and in GNU Screen sessions
  • Provides a unified interface for running functions across different environments
  • Allows for easy configuration of job options, such as resource requirements and environment variables
  • Supports snapshotting the environment to ensure reproducibility, using the nshsnap library
  • Provides utilities for logging, seeding, and signal handling

Installation

nshrunner can be installed using pip:

pip install nshrunner

Usage

Here's a simple example showing the different ways to run a function:

import nshrunner as R

def train_model(batch_size: int, learning_rate: float):
    # Training logic here
    return {"accuracy": 0.95}

# Define runs with different hyperparameters
runs = [
    (32, 0.001),  # (batch_size, learning_rate)
    (64, 0.0005),
]

# Run locally
results = R.run_local(train_model, runs)

# Run in a GNU Screen session
R.submit_screen(
    train_model,
    runs,
    screen={
        "name": "training",
        "logging": {
            "output_file": "logs/output.log",
            "error_file": "logs/error.log"
        },
        "attach": False  # Run detached
    }
)

# Run on SLURM
R.submit_slurm(
    train_model,
    runs,
    slurm={
        "name": "training",
        "partition": "gpu",
        "resources": {
            "nodes": 1,
            "cpus": 4,
            "gpus": 1,
            "memory_gb": 32,
            "time": "12:00:00"
        },
        "output_dir": "logs"
    }
)

The library provides a consistent interface across different execution environments while handling the complexities of:

  • Job submission and management
  • Resource allocation
  • Environment setup
  • Output logging
  • Error handling

For more advanced usage, you can configure additional options like:

# Configure environment snapshot for reproducibility
R.submit_slurm(
    train_model,
    runs,
    runner={
        "working_dir": "experiments",
        "snapshot": True,  # Snapshot code and dependencies
        "seed": {"seed": 42}  # Set random seeds
    },
    slurm={...}
)

Contributing

Contributions are welcome! For feature requests, bug reports, or questions, please open an issue on GitHub. If you'd like to contribute code, please submit a pull request with your changes.

License

nshrunner is released under the MIT License. See LICENSE for more information.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

nshrunner-1.0.0.dev1.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

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

nshrunner-1.0.0.dev1-py3-none-any.whl (44.6 kB view details)

Uploaded Python 3

File details

Details for the file nshrunner-1.0.0.dev1.tar.gz.

File metadata

  • Download URL: nshrunner-1.0.0.dev1.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.12.3 Linux/6.8.0-49-generic

File hashes

Hashes for nshrunner-1.0.0.dev1.tar.gz
Algorithm Hash digest
SHA256 e7ed97dadc288eaebfd1dc25e775a26f6b0a57c58d3e10b36153e64e44e917c3
MD5 683cc2d079ff92c36e7cf19a25206f08
BLAKE2b-256 783f28752d74a5ecf107efdc2a9b5c31f9077a130096512e52654fd63495ca65

See more details on using hashes here.

File details

Details for the file nshrunner-1.0.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: nshrunner-1.0.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 44.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.12.3 Linux/6.8.0-49-generic

File hashes

Hashes for nshrunner-1.0.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 739cad9dc709fb9e92753017b4d05c365ddcdeaadc6cc7799c33b092e9c84869
MD5 bbaf7ed19782cfa2a8a97adba2c72cd2
BLAKE2b-256 55b973518f40e3a3d74a3eb30be7b32598428220538b34ea48da6c09e46fb5bc

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