Since diffxpy relies on batchglm, which uses TensorFlow for linear algebra operations, you can control TensorFlow's multi-threading behavior. This is useful for limiting core usage on certain operating systems.
Important: You must set these environment variables before importing diffxpy.api or batchglm.api in your Python session. If you need to change these settings, you must restart your Python session.
Use the following environment variables:
TF_NUM_THREADS: Controls the number of threads used for linear algebra operations (training).TF_LOOP_PARALLEL_ITERATIONS: Controls the number of threads used during TensorFlow while_loops (used during Hessian computation).
To restrict TensorFlow to a single thread, execute this at the very beginning of your script:
import os
os.environ.setdefault("TF_NUM_THREADS", "1")
os.environ.setdefault("TF_LOOP_PARALLEL_ITERATIONS", "1")
import diffxpy.api as de