Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF2 environment settings #5230

Merged
merged 33 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9d63670
implemented first level of tensorflow configuration
dakshvar22 Feb 7, 2020
58dd5fc
Merge branch 'tf2' into tf2-tfconfig
dakshvar22 Feb 12, 2020
0f8b8a5
added test and refactored env variables
dakshvar22 Feb 12, 2020
3deda46
remove extra lines
dakshvar22 Feb 12, 2020
75663a0
added changelog
dakshvar22 Feb 12, 2020
1ba52e0
removed unref variable
dakshvar22 Feb 12, 2020
9008960
add types
dakshvar22 Feb 12, 2020
6f96fa5
Merge branch 'tf2' into tf2-tfconfig
dakshvar22 Feb 12, 2020
5ec8d3e
remove old tests
dakshvar22 Feb 12, 2020
142327a
added docs
dakshvar22 Feb 12, 2020
ddae7ae
refactored tests
dakshvar22 Feb 13, 2020
c875933
WIP
dakshvar22 Feb 13, 2020
0295023
check
dakshvar22 Feb 13, 2020
2843fe0
fix test for cpu testing
dakshvar22 Feb 13, 2020
4d12daf
Merge branch 'tf2' into tf2-tfconfig
dakshvar22 Feb 13, 2020
ef527c0
address comments
dakshvar22 Feb 13, 2020
879bd0d
fix type annotations
dakshvar22 Feb 13, 2020
0fec427
fix imports
dakshvar22 Feb 13, 2020
5a88cd5
test just one pytest file on travis
dakshvar22 Feb 14, 2020
6f28218
added all tests to pytest now
dakshvar22 Feb 14, 2020
af6f037
trying to fix the test. Multiprocessing :(
dakshvar22 Feb 14, 2020
0881af0
Merge branch 'tf2' into tf2-tfconfig
dakshvar22 Feb 17, 2020
98c43b2
remove cpu env set test
dakshvar22 Feb 17, 2020
d970ae9
remove unused imports
dakshvar22 Feb 17, 2020
a96159b
refactor function
dakshvar22 Feb 17, 2020
6146bf9
Apply suggestions from code review
dakshvar22 Feb 17, 2020
99a3fe2
Apply suggestions from code review
dakshvar22 Feb 17, 2020
14b6ea5
changes from code comments
dakshvar22 Feb 17, 2020
98d54a9
add docstring
dakshvar22 Feb 17, 2020
69bd8f2
Update rasa/utils/tensorflow/environment.py
dakshvar22 Feb 17, 2020
eb4fce6
Apply suggestions from code review
dakshvar22 Feb 17, 2020
8950359
shorten docstring
dakshvar22 Feb 17, 2020
f168ce9
fix import
dakshvar22 Feb 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions docs/api/tensorflow_usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
:desc: Find out how to configure your environment for efficient usage of tensorflow inside Rasa
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding a table with all environment variables at the bottom / top?


.. _tensorflow_usage:

Setting up Tensorflow Runtime
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
=============================

Tensorflow allows setting the runtime environment via
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
`TF Config submodule <https://www.tensorflow.org/api_docs/python/tf/config>`_. Rasa supports a smaller subset of these
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`TF Config submodule <https://www.tensorflow.org/api_docs/python/tf/config>`_. Rasa supports a smaller subset of these
`TF Config submodule <https://www.tensorflow.org/api_docs/python/tf/config>`_. Rasa Open Source supports a smaller subset of these

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to Rasa OSS everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted to Rasa Open Source 😄

configuration options and makes appropriate calls to the `tf.config` submodule.
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
This smaller subset comprises of configurations that developers frequently use with Rasa.
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
All configuration options are specified using environment variables as shown in subsequent sections.

dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved

Optimize CPU Performance
------------------------

Parallelize one operation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Parallelize one operation
Parallelize One Operation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can you parallelize a single operation? :-D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A matrix multiplication can be parallelized on multiple threads. It can be a single operation but a non-atomic one. :)

^^^^^^^^^^^^^^^^^^^^^^^^^

Set ``TF_INTRA_OP_PARALLELISM_THREADS`` as an environment variable to specify maximum number of threads that can be used
to parallelize the execution of one operation. If left unspecified, this value defaults to 0 which means tensorflow should
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
pick an appropriate value depending on the system configuration.


dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
Parallelize multiple operations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Set ``TF_INTER_OP_PARALLELISM_THREADS`` as an environment variable to specify maximum number of threads that can be used
to parallelize the execution of multiple **non-blocking** operations. If left unspecified, this value defaults to 0
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
which means tensorflow should pick an appropriate value depending on the system configuration.

dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved

Optimize GPU Performance
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
------------------------

Limiting GPU memory growth
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
^^^^^^^^^^^^^^^^^^^^^^^^^^

Tensorflow by default blocks all the available GPU memory for the running process. This can be limiting if you are running
multiple tensorflow processes and want to distribute memory across them. To prevent this,
set an environment variable ``TF_FORCE_GPU_ALLOW_GROWTH`` to ``True``.
wochinge marked this conversation as resolved.
Show resolved Hide resolved


dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
Restricting absolute GPU memory available
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Often, a developer wants to limit the absolute amount of GPU memory that can be used by a process.

For example, you may have two visible GPUs(GPU:0 and GPU:1) and you want to allocate 1024 MB from first GPU and 2048 MB from second GPU.
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
You can do so by setting an environment variable as ``TF_GPU_MEMORY_ALLOC="0:1024, 1:2048"``.

Another scenario can be where you have access to 2 GPUs(GPU:0 and GPU:1) but you would like to use only second GPU for
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
Rasa process.
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
``TF_GPU_MEMORY_ALLOC="1:2048"`` would make 2048 MB of memory from GPU 1 available for the Rasa process
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved



dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
dakshvar22 marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Understand messages, hold conversations, and connect to messaging channels and A
api/lock-stores
api/training-data-importers
api/core-featurization
api/tensorflow_usage
migration-guide
changelog

Expand Down