A light-weight library of utilities for TensorFlow 2/Keras.
Project description
tfu
A small library of many useful utilities for Tensorflow training workflows.
Filtering Visible Devices
In some instances, you may want to filter what devices are visible to Tensorflow. For example, you may have multiple GPUS, but would prefer to use only a single GPU instance when training your model. tf_utils
includes some convenience methods to assist with this.
Selecting a single GPU:
visible_devices = tfu.devices.select_gpu(0)
Selecting a subset of GPUs:
visible_devices = tfu.devices.select_gpu([0, 1])
Training Strategies
When a training strategy is needed, in particular OneDeviceStrategy
or MirroredDeviceStrategy
, tf_utils
provides some convenience functions to create these strategies automatically and filter out unused devices. Some examples are provided below.
Use the CPU only via a OneDeviceStrategy:
strategy = tfu.strategy.cpu(0)
Use a single GPU via the OneDeviceStrategy:
strategy = tfu.strategy.gpu(0)
Use multiple GPUs via the MirroredDeviceStrategy:
strategy = tfu.strategy.gpu([0, 1])
Dynamic Memory Growth
Tensorflow has the ability to use dynamic memory allocation, rather than allocating all of the memory on the GPU at once. Enabling dynamic memory allocation allows you to not only monitor memory usage of your models during training, but it also grants you the ability to run multiple models on a single GPU instance. All device selection and strategy functions within tf_utils
support this feature via the use_dynamic_memory
flag.
Enabling dynamic memory growth via device selection:
visible_devices = tfu.devices.select_gpu(0, use_dynamic_memory=True)
Enabling dynamic memory growth via strategy creation:
strategy = tfu.strategy.gpu(0, use_dynamic_memory=True)
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 Distribution
Hashes for tf_utilities-0.1.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb75ccc20d7f3ee2f40941511e892c81aae0b1976a66e5587bc4a8e7897545b3 |
|
MD5 | 52b06441e1904d9a758dd0ae3024a6db |
|
BLAKE2b-256 | a4e76600ce57636d30b22a3b7baf5032ac373caaaeecacfc6d40a66a88add830 |