A CLI tool for checking if GPUs are available before running your script that uses GPUs.
Project description
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 passingCUDA_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
.
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
Built Distributions
File details
Details for the file knock_on_gpus-0.1.0.tar.gz
.
File metadata
- Download URL: knock_on_gpus-0.1.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
3a92d96c9fc5a4401995c317c8ac540ceb9edd623d81b0f9076ea8b164e0302c
|
|
MD5 |
50dbaa5fd4c03db7081111a5a3ebd8d5
|
|
BLAKE2b-256 |
e2e0f414196666685e68632e16440bd93c0a260b9d7a2e9d05e54ee4a6b481d7
|
File details
Details for the file knock_on_gpus-0.1.0-py3-none-win_amd64.whl
.
File metadata
- Download URL: knock_on_gpus-0.1.0-py3-none-win_amd64.whl
- Upload date:
- Size: 916.0 kB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
98e995e6d7407843bae7303462501f3b2acf9326686ab8c0a32053661e5ba665
|
|
MD5 |
e9864c741a9309d7369d1d63082faa2f
|
|
BLAKE2b-256 |
70171729df403c8c2755f295211f88e5bdbfbb0f3c4fad33386ed98039942cd2
|
File details
Details for the file knock_on_gpus-0.1.0-py3-none-win32.whl
.
File metadata
- Download URL: knock_on_gpus-0.1.0-py3-none-win32.whl
- Upload date:
- Size: 832.9 kB
- Tags: Python 3, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
8637633e78924fb5818e144d2e3a3d57b2e2b15f2c842b29335955251ce2881f
|
|
MD5 |
b9f89be5ff98f0b4d7092ccb1f4ddfa3
|
|
BLAKE2b-256 |
83f0d41d5da5b9edf9e33d04ef9f7a01a577234a333ffb2bb3e3d49329b426e5
|
File details
Details for the file knock_on_gpus-0.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: knock_on_gpus-0.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
9064ad2280b82b8d5736e2b12322dc1256077116f77420a4b32ab23f131f11d8
|
|
MD5 |
e47932e6af4d8c2bb66c6dff42b04127
|
|
BLAKE2b-256 |
12d5debdd5e99aacc66d52664a55d9afbee42cd24b398d02ea7de5610bc1ace3
|
File details
Details for the file knock_on_gpus-0.1.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
.
File metadata
- Download URL: knock_on_gpus-0.1.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
- Upload date:
- Size: 1.1 MB
- Tags: Python 3, manylinux: glibc 2.17+ s390x
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
dec302634df21d5ffb3c2c6bd9692872c8056cfe3ed60048677d22589108830e
|
|
MD5 |
badb3661c1a5841419205f3bd34b7700
|
|
BLAKE2b-256 |
7f25c0713f00530e5ab49528f7ece74479e92c1adc364d9cf19c32b4833903fb
|
File details
Details for the file knock_on_gpus-0.1.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
.
File metadata
- Download URL: knock_on_gpus-0.1.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
- Upload date:
- Size: 1.1 MB
- Tags: Python 3, manylinux: glibc 2.17+ ppc64le
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
4bb5248b869e3e3cdd238fdc86e959138776b36c1967e59bd348dfbddae62791
|
|
MD5 |
833b9e564bc80fb2889790e4280e9368
|
|
BLAKE2b-256 |
74c58170185e28906cb690f3ebd08a22a9284d56c58c04344fe84e14bb5579ad
|
File details
Details for the file knock_on_gpus-0.1.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: knock_on_gpus-0.1.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 1.1 MB
- Tags: Python 3, manylinux: glibc 2.17+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
ba6404b19f7f0daa0f1888150345f357ecb8ba1af6410141a99dade542268654
|
|
MD5 |
545a42eac1ac3721cab3c4dc34b96be0
|
|
BLAKE2b-256 |
b37286123c5bd369de3af92585328077b4b9c6f8641a2299966555baa05b7609
|
File details
Details for the file knock_on_gpus-0.1.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
.
File metadata
- Download URL: knock_on_gpus-0.1.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 886.5 kB
- Tags: Python 3, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
5b1bf8265de640dcbf4b63f52fd874dc1f15f046ff334b0bb9d46df8f078a4c9
|
|
MD5 |
f5811aca0d6ea6eaa88f7012fd05e86c
|
|
BLAKE2b-256 |
0a42822b752c1d2642324b14e4fe45cba15529d36da775afab99f8ec3774a2a1
|
File details
Details for the file knock_on_gpus-0.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: knock_on_gpus-0.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 926.1 kB
- Tags: Python 3, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
4eecf6580275d22797f49ebccedad6e6e1efefff08026ed352b0afed527f0929
|
|
MD5 |
94a4386bfe548de67fe808398c77f8aa
|
|
BLAKE2b-256 |
b31cd8c7dcee53b68abd8d86b6c3950fd398280f139c550522b5d2f5f8cec70f
|
File details
Details for the file knock_on_gpus-0.1.0-py3-none-macosx_11_0_arm64.whl
.
File metadata
- Download URL: knock_on_gpus-0.1.0-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 926.8 kB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
9a45f92cf858adb7a190154d86589f010144f022874596dde9948d087d68ced5
|
|
MD5 |
f6d414eea3bc89d019a7d0c80d2d2145
|
|
BLAKE2b-256 |
8c1545d97c98c10aa0ad66fda2dc2a059a9f380ecb3b68c4136bebdb9cd1fdfb
|
File details
Details for the file knock_on_gpus-0.1.0-py3-none-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: knock_on_gpus-0.1.0-py3-none-macosx_10_12_x86_64.whl
- Upload date:
- Size: 996.0 kB
- Tags: Python 3, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
d18d93cb24d7f483a242a4b311bcd955bac4faa6fe7faa6a5827a19b9ed88ad5
|
|
MD5 |
68d979c5b624a69a8e09aa4dedcd3549
|
|
BLAKE2b-256 |
629b7d39a946bb67728ddb5629ec1e394833ccd8e121ebad23be27cd4695fd6f
|