Skip to main content

knock-on-gpus

A CLI tool for checking if GPUs are available before running your script that uses GPUs.

Installation

pip install knock-on-gpus

Quick start

Basic usage

You can use knock-on-gpus to run a script that uses GPUs.

knock-on-gpus -- python my_script.py

If some GPUs are not available, knock-on-gpus will return an error code and print a message to the console.

[!NOTE] knock-on-gpus prohibits omitting the extra command (python my_script.py in this example) by default. This is to avoid accidentally executing the subsequent command without passing CUDA_VISIBLE_DEVICES.

Please see --allow-noop option for details.

Using with CUDA_VISIBLE_DEVICES

You can also use knock-on-gpus to run a script with specific GPUs.

CUDA_VISIBLE_DEVICES=0,1 knock-on-gpus -- python my_script.py

You can also use --devices or -d to specify the GPUs to use.

knock-on-gpus -d 0,1 -- python my_script.py

Auto selection

You can use --auto-select to automatically allocate the number of GPUs.

knock-on-gpus --auto-select 2 -- python my_script.py

If GPU:0, GPU:1, and GPU:3 are unavailable, knock-on-gpus will use GPU:2 and GPU:4.

Set alias for python

You can set an alias for python to use knock-on-gpus by default.

alias unsafe-python="`which python`"
alias python="knock-on-gpus -- python"

Then you can run your script without knock-on-gpus.

Options

--devices

(Alias: -d, --device)

Specifies the GPUs to use. The value is a comma-separated list of GPU IDs.

--memory-border-mib

Specifies the memory border (MiB) to treat as vacant. If the memory usage exceeds this value, the GPU will be treated as occupied.

--use-gpu-strictly

If true, use GPU strictly. If CUDA is not available, it will fail.

--min-gpus

Specifies the number of min GPUs to use.

--max-gpus

Specifies the number of max GPUs to use.

--cuda-visible-devices-env-key

Specifies the environment variable key to set visible devices.

--verbose

If true, print verbose logs.

--auto-select

(Alias: -a, --auto)

If a number is given, it will automatically allocate the number of GPUs.

--allow-noop

If true, allow running without executing extra commands.

Examples

$ knock-on-gpus -d "0,1,2,3" -- sh -c 'echo "devices=$CUDA_VISIBLE_DEVICES"'
# => devices=0,1,2,3

If GPUs are available, this will succeed. "devices=0,1,2,3" will be printed.

$ knock-on-gpus && sh -c 'echo "devices=$CUDA_VISIBLE_DEVICES"'
# => ERROR: Omitting the command is not allowed.

Even if GPUs are available, this will fail because no command passed to knock-on-gpus.

Note that && has no effect to pass the command to knock-on-gpus.

$ knock-on-gpus --allow-noop && sh -c 'echo "devices=$CUDA_VISIBLE_DEVICES"'
# => devices=

If GPUs are available, this will succeed. BUT "devices=" is printed instead of "devices=0,1,2,3" because sh -c ... is not passed to knock-on-gpus.

Metadata

Release files for knock-on-gpus 0.1.0

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

Source distribution (sdist)

Source distribution for knock-on-gpus 0.1.0
File Size Uploaded
knock_on_gpus-0.1.0.tar.gz 11.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for knock-on-gpus 0.1.0
File
knock_on_gpus-0.1.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
knock_on_gpus-0.1.0-py3-none-win32.whl Python 3 none Windows x86-32 Details
knock_on_gpus-0.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details
knock_on_gpus-0.1.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl Python 3 none Linux glibc 2.17+ IBM System/390x Details
knock_on_gpus-0.1.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl Python 3 none Linux glibc 2.17+ PowerPC 64-le Details
knock_on_gpus-0.1.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl Python 3 none Linux glibc 2.17+ x86-32 Details
knock_on_gpus-0.1.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl Python 3 none Linux glibc 2.17+ ARMv7l Details
knock_on_gpus-0.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details
knock_on_gpus-0.1.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details
knock_on_gpus-0.1.0-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details

Total release size: 9.8 MB

Release files / knock_on_gpus-0.1.0.tar.gz

Download URL knock_on_gpus-0.1.0.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3a92d96c9fc5a4401995c317c8ac540ceb9edd623d81b0f9076ea8b164e0302c
BLAKE2b-256 checksum
How to use checksums
e2e0f414196666685e68632e16440bd93c0a260b9d7a2e9d05e54ee4a6b481d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Release files / knock_on_gpus-0.1.0-py3-none-win_amd64.whl

Download URL knock_on_gpus-0.1.0-py3-none-win_amd64.whl
Size 916.0 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
98e995e6d7407843bae7303462501f3b2acf9326686ab8c0a32053661e5ba665
BLAKE2b-256 checksum
How to use checksums
70171729df403c8c2755f295211f88e5bdbfbb0f3c4fad33386ed98039942cd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Release files / knock_on_gpus-0.1.0-py3-none-win32.whl

Download URL knock_on_gpus-0.1.0-py3-none-win32.whl
Size 832.9 kB
Tags Python 3 Windows x86-32
SHA-256 checksum
How to use checksums
8637633e78924fb5818e144d2e3a3d57b2e2b15f2c842b29335955251ce2881f
BLAKE2b-256 checksum
How to use checksums
83f0d41d5da5b9edf9e33d04ef9f7a01a577234a333ffb2bb3e3d49329b426e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Release files / knock_on_gpus-0.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL knock_on_gpus-0.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.0 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
9064ad2280b82b8d5736e2b12322dc1256077116f77420a4b32ab23f131f11d8
BLAKE2b-256 checksum
How to use checksums
12d5debdd5e99aacc66d52664a55d9afbee42cd24b398d02ea7de5610bc1ace3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Release files / knock_on_gpus-0.1.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL knock_on_gpus-0.1.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 1.1 MB
Tags Linux glibc 2.17+ IBM System/390x Python 3
SHA-256 checksum
How to use checksums
dec302634df21d5ffb3c2c6bd9692872c8056cfe3ed60048677d22589108830e
BLAKE2b-256 checksum
How to use checksums
7f25c0713f00530e5ab49528f7ece74479e92c1adc364d9cf19c32b4833903fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Release files / knock_on_gpus-0.1.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL knock_on_gpus-0.1.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 1.1 MB
Tags Linux glibc 2.17+ PowerPC 64-le Python 3
SHA-256 checksum
How to use checksums
4bb5248b869e3e3cdd238fdc86e959138776b36c1967e59bd348dfbddae62791
BLAKE2b-256 checksum
How to use checksums
74c58170185e28906cb690f3ebd08a22a9284d56c58c04344fe84e14bb5579ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Release files / knock_on_gpus-0.1.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL knock_on_gpus-0.1.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Size 1.1 MB
Tags Linux glibc 2.17+ x86-32 Python 3
SHA-256 checksum
How to use checksums
ba6404b19f7f0daa0f1888150345f357ecb8ba1af6410141a99dade542268654
BLAKE2b-256 checksum
How to use checksums
b37286123c5bd369de3af92585328077b4b9c6f8641a2299966555baa05b7609
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Release files / knock_on_gpus-0.1.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL knock_on_gpus-0.1.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 886.5 kB
Tags Linux glibc 2.17+ ARMv7l Python 3
SHA-256 checksum
How to use checksums
5b1bf8265de640dcbf4b63f52fd874dc1f15f046ff334b0bb9d46df8f078a4c9
BLAKE2b-256 checksum
How to use checksums
0a42822b752c1d2642324b14e4fe45cba15529d36da775afab99f8ec3774a2a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Release files / knock_on_gpus-0.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL knock_on_gpus-0.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 926.1 kB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
4eecf6580275d22797f49ebccedad6e6e1efefff08026ed352b0afed527f0929
BLAKE2b-256 checksum
How to use checksums
b31cd8c7dcee53b68abd8d86b6c3950fd398280f139c550522b5d2f5f8cec70f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Release files / knock_on_gpus-0.1.0-py3-none-macosx_11_0_arm64.whl

Download URL knock_on_gpus-0.1.0-py3-none-macosx_11_0_arm64.whl
Size 926.8 kB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9a45f92cf858adb7a190154d86589f010144f022874596dde9948d087d68ced5
BLAKE2b-256 checksum
How to use checksums
8c1545d97c98c10aa0ad66fda2dc2a059a9f380ecb3b68c4136bebdb9cd1fdfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Release files / knock_on_gpus-0.1.0-py3-none-macosx_10_12_x86_64.whl

Download URL knock_on_gpus-0.1.0-py3-none-macosx_10_12_x86_64.whl
Size 996.0 kB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d18d93cb24d7f483a242a4b311bcd955bac4faa6fe7faa6a5827a19b9ed88ad5
BLAKE2b-256 checksum
How to use checksums
629b7d39a946bb67728ddb5629ec1e394833ccd8e121ebad23be27cd4695fd6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.1

Release history Release notifications | RSS feed

This release

0.1.0 This release

11 release files

0.0.2

11 release files

0.0.1

11 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