簡體   English   中英

Tensorflow 2.2 不考慮線程設置(inter_op、intra_op 和 OMP_NUM_THREADS)

[英]Tensorflow 2.2 not respecting thread settings (inter_op, intra_op, and OMP_NUM_THREADS)

我正在運行一個設置 inter_op、intra_op 和 OMP_NUM_THREADS 的 tensorflow 應用程序,但是,它完全忽略了這些設置,並且似乎以默認值運行。 這是我設置它們的方式:

import tensorflow as tf
    print('Using Thread Parallelism: {} NUM_INTRA_THREADS, {} NUM_INTER_THREADS, {} OMP_NUM_THREADS'.format(os.environ['NUM_INTRA_THREADS'], os.environ['NUM_INTER_THREADS'], os.environ['OMP_NUM_THREADS']))
    session_conf = tf.compat.v1.ConfigProto(inter_op_parallelism_threads=int(os.environ['NUM_INTER_THREADS']),
        intra_op_parallelism_threads=int(os.environ['NUM_INTRA_THREADS']))
    sess = tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph(), config=session_conf)
    tf.compat.v1.keras.backend.set_session(sess)

我已經驗證它正在讀取正確的值(打印按預期打印值)。 我也嘗試過使用其他 Tensorflow 2 版本,但沒有成功。

我不知道我做錯了什么。

版本信息:tensorflow 2.2.0 py37_2 intel tensorflow-base 2.2.0 0 intel tensorflow-estimator 2.2.0 pyh208ff02_0

keras 2.4.3 0 keras-base 2.4.3 py_0 keras-preprocessing 1.1.0 py_1

You might want to checkout the new way of using TensorFlow v2, as they eventually gave up tf.session and started to do "Functions, not sessions" (you may realise you should probably use the v2 functions by looking at the function name tf.compat.v1.xxxx )。

有四個線程相關的配置設置功能供您使用(此處的文檔):

  • get_inter_op_parallelism_threads() :獲取用於獨立操作之間並行性的線程數。
  • get_intra_op_parallelism_threads() :獲取單個操作中用於並行性的線程數。
  • set_inter_op_parallelism_threads() :設置用於獨立操作之間並行性的線程數。
  • set_intra_op_parallelism_threads() :設置單個操作中用於並行性的線程數。

所以解決方案是在代碼的開頭簡單地使用以下代碼:

tf.config.threading.set_inter_op_parallelism_threads(4)
tf.config.threading.set_intra_op_parallelism_threads(16)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM