Skip to main content

Jupyter Notebook + Slurm integration.

Project description

ipy-slurm-exec

Real Slurm magic - execute individual Jupyter Notebook cells on your Slurm cluster e.g. GPU offload.

Simple example

For internals, see Architecture.

Install

pip install ipy-slurm-exec

slurm_exec arguments:

Specify arguments with %%slurm_exec to manage inputs, outputs, and the Slurm job.

Managing variables

If you do not specify a list of input variables to export, then all are exported into the Slurm job. Similarly for importing after the job finishes. For large notebooks this may cause problems - overwriting a variable in another part of your notebook, or exporting many big variables that are never used (wasting memory). Use these arguments to manage:

-i, --inputs: list of input variables to export into the Slurm job

e.g. %%slurm_exec -i data,scale ...
-o, --outputs: list of output variables to import into Notebook from Slurm job

e.g. %%slurm_exec -o reduced ...

Output fail

Python variables created in the Slurm job may be dependent on additional modules it loaded that were not loaded by your Notebook, for example CUDA. These cannot be imported into Notebook so will be skipped - the execution report will list when this happens e.g.:

Skipped variables in Notebook:
  device_vec: 'cudaErrorInsufficientDriver: CUDA driver version is insufficient for CUDA runtime version'

Input/export functions & classes

You can also export a function or class that you defined in Notebook, into the Slurm job.

%%slurm_exec -i custom_function ...

To also export all variables:

%%slurm_exec -i custom_function,* ...

It is not possible to export all functions, because this would export all functions from all modules you imported (and all modules they imported).

Slurm job parameters

Refer to any Slurm cluster documentation for setting these parameters, as the values are simply passed to Slurm. When not set then Slurm defaults are used, same as when directly submitting a job to Slurm.

--partition
--time
--ntasks
--cpus-per-task
--mem
--gpus

e.g. %%slurm_exec --partition=gpu --gpus=1 --time=00:10:00

GNU environment modules

--modules: list of modules to load in Slurm job. Add prefix '+' to have job inherit modules loaded in Notebook.

e.g. %%slurm_exec ... --modules=+cuda

GPU example

Bringing everything together, here is a more realistic example - running a Notebook cell on a GPU.

Import ipy_slurm_exec

import ipy_slurm_exec
%load_ext ipy_slurm_exec

Setup data in Notebook:

import torch
import numpy as np
seed = 123
vector = np.linspace(-2, 2, 256, dtype=np.float32)
torch.manual_seed(seed)

Code to run on a GPU:

%%slurm_exec -i seed,vector -o torch_result --partition=gpu --gpus=1 --mem=1G
torch.manual_seed(seed)
device = torch.device("cuda")
x = torch.from_numpy(vector).to(device)
y = torch.tanh(x @ x.T)
torch_result = y.sum().item()

Execution report:

Submitted Slurm job 1326 (folder: slurm_exec/20251223T1152-dc0f96dc)
Job completed                                                                   
Imported: torch_result

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

ipy_slurm_exec-1.1.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

ipy_slurm_exec-1.1.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file ipy_slurm_exec-1.1.0.tar.gz.

File metadata

  • Download URL: ipy_slurm_exec-1.1.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for ipy_slurm_exec-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b53a8e437dc99629738d51ccda36fd3d3ba1389b4e87ee0edd2052954a758906
MD5 a9fecf7e3387981f754f9c61ae4f3406
BLAKE2b-256 7c8bcf5c292a9cb2df505e383e1e77a7d9a7777bbd3a5699d7963c3aad8f06b5

See more details on using hashes here.

File details

Details for the file ipy_slurm_exec-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: ipy_slurm_exec-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for ipy_slurm_exec-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e77d23e5277a9e79e03b3308721f692a60dbed102d4b67bbef1a8abe991658c0
MD5 5dc502c3b9d68c71722f049985696fca
BLAKE2b-256 3ece7181e4ded6ad998a6f797c0cc5afb3146865edbd5e7acb933565d7f31c0f

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