<commit_before>.. _configuration:

Configuring Chainer
===================

..  currentmodule:: chainer

Chainer provides some global settings that affect the behavior of some functionalities.
Such settings can be configured using the *unified configuration system*.
The system provides a transparent way to manage the configuration for each process and for each thread.

The configuration is managed by two global objects: :data:`chainer.global_config` and :data:`chainer.config`.

- The :data:`global_config` object maintains the configuration shared in the Python process.
  This is an instance of the :class:`~chainer.configuration.GlobalConfig` class.
  It can be used just as a plain object, and users can freely set any attributes on it.
- The :data:`config` object, on the other hand, maintains the configuration for the current thread.
  This is an instance of the :class:`~chainer.configuration.LocalConfig` class.
  It behaves like a thread-local object, and any attribute modifications are only visible to the current thread.

If no value is set to :data:`config` for a given key, :data:`global_config` is transparently referred.
Thanks to this transparent lookup, users can always use :data:`config` to read any configuration so that the thread-local configuration is used if available and otherwise the default global setting is used.

The following entries of the configuration are currently provided by Chainer.
Some entries support environment variables to set the default values.
Note that the default values are set in the global config.

Configuration Keys
------------------

* ``cudnn_deterministic`` (default: ``False``)
   Flag to configure deterministic computations in cuDNN APIs.

   If it is ``True``, convolution functions that use cuDNN use the deterministic mode (i.e, the computation is reproducible).
   Otherwise, the results of convolution functions using cuDNN may be non-deterministic in exchange for the performance.

* ``debug`` (default: ``False``)
   Debug mode flag.

   If it is ``True``, Chainer runs in the debug mode.
   See :ref:`debug` for more information of the debug mode.

   You can change the default value to ``True`` by setting ``CHAINER_DEBUG`` environment variable to ``1``.

* ``enable_backprop`` (default: ``True``)
   Flag to enable backpropagation support.

   If it is ``True``, computational graphs are created during forward passes by :class:`FunctionNode`\\ s, allowing backpropagation to start from any :class:`Variable` in the graph.
   Otherwise, computational graphs are not created but memory consumptions are reduced.
   So calling :func:`~chainer.Variable.backward` on the results of a function will not compute any gradients of any input.

* ``keep_graph_on_report`` (default: ``False``)
   Flag to configure whether or not to let :func:`report` keep the computational graph.

   If it is ``False``, :func:`report` does not keep the computational graph when a :class:`Variable` object is reported.
   It means that :func:`report` stores a copy of the :class:`Variable` object which is purged from the computational graph.
   If it is ``True``, :func:`report` just stores the :class:`Variable` object as is with the computational graph left attached.

   You can change the default value to ``True`` by setting ``CHAINER_KEEP_GRAPH_ON_REPORT`` environment variable to ``1``.

* ``train`` (default: ``True``)
   Training mode flag.
<commit_msg>add performance effect of debug option<commit_after>.. _configuration:

Configuring Chainer
===================

..  currentmodule:: chainer

Chainer provides some global settings that affect the behavior of some functionalities.
Such settings can be configured using the *unified configuration system*.
The system provides a transparent way to manage the configuration for each process and for each thread.

The configuration is managed by two global objects: :data:`chainer.global_config` and :data:`chainer.config`.

- The :data:`global_config` object maintains the configuration shared in the Python process.
  This is an instance of the :class:`~chainer.configuration.GlobalConfig` class.
  It can be used just as a plain object, and users can freely set any attributes on it.
- The :data:`config` object, on the other hand, maintains the configuration for the current thread.
  This is an instance of the :class:`~chainer.configuration.LocalConfig` class.
  It behaves like a thread-local object, and any attribute modifications are only visible to the current thread.

If no value is set to :data:`config` for a given key, :data:`global_config` is transparently referred.
Thanks to this transparent lookup, users can always use :data:`config` to read any configuration so that the thread-local configuration is used if available and otherwise the default global setting is used.

The following entries of the configuration are currently provided by Chainer.
Some entries support environment variables to set the default values.
Note that the default values are set in the global config.

Configuration Keys
------------------

* ``cudnn_deterministic`` (default: ``False``)
   Flag to configure deterministic computations in cuDNN APIs.

   If it is ``True``, convolution functions that use cuDNN use the deterministic mode (i.e, the computation is reproducible).
   Otherwise, the results of convolution functions using cuDNN may be non-deterministic in exchange for the performance.

* ``debug`` (default: ``False``)
   Debug mode flag.

   If it is ``True``, Chainer runs in the debug mode.
   Enabling debug mode may introduce some performance overhead.
   See :ref:`debug` for more information of the debug mode.

   You can change the default value to ``True`` by setting ``CHAINER_DEBUG`` environment variable to ``1``.

* ``enable_backprop`` (default: ``True``)
   Flag to enable backpropagation support.

   If it is ``True``, computational graphs are created during forward passes by :class:`FunctionNode`\\ s, allowing backpropagation to start from any :class:`Variable` in the graph.
   Otherwise, computational graphs are not created but memory consumptions are reduced.
   So calling :func:`~chainer.Variable.backward` on the results of a function will not compute any gradients of any input.

* ``keep_graph_on_report`` (default: ``False``)
   Flag to configure whether or not to let :func:`report` keep the computational graph.

   If it is ``False``, :func:`report` does not keep the computational graph when a :class:`Variable` object is reported.
   It means that :func:`report` stores a copy of the :class:`Variable` object which is purged from the computational graph.
   If it is ``True``, :func:`report` just stores the :class:`Variable` object as is with the computational graph left attached.

   You can change the default value to ``True`` by setting ``CHAINER_KEEP_GRAPH_ON_REPORT`` environment variable to ``1``.

* ``train`` (default: ``True``)
   Training mode flag.

{'fraction_non_alphanumeric': 0.08741511342291576, 'fraction_numerical': 0.0005779511631267157, 'mean_word_length': 4.6276422764227645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3939341', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1679, 'n_words': 907}