gpt4 book ai didi

Tensorflow 2.0 100% 使用所有 CPU 内核

转载 作者:行者123 更新时间:2023-12-04 17:26:05 25 4
gpt4 key购买 nike

我的 Tensorflow 模型大量使用了应该在 CPU 上完成的数据预处理,以使 GPU 保持开放以进行训练。

top - 09:57:54 up 16:23,  1 user,  load average: 3,67, 1,57, 0,67
Tasks: 400 total, 1 running, 399 sleeping, 0 stopped, 0 zombie
%Cpu(s): 19,1 us, 2,8 sy, 0,0 ni, 78,1 id, 0,0 wa, 0,0 hi, 0,0 si, 0,0 st
MiB Mem : 32049,7 total, 314,6 free, 5162,9 used, 26572,2 buff/cache
MiB Swap: 6779,0 total, 6556,0 free, 223,0 used. 25716,1 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
17604 joro 20 0 22,1g 2,3g 704896 S 331,2 7,2 4:39.33 python
这就是 top 向我展示的内容。我想让这个 python 进程在所有内核中使用至少 90% 的可用 CPU。如何做到这一点?
GPU 利用率更好,约为 90%。即使我不知道为什么它不是 100%
Mon Aug 10 10:00:13 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.100 Driver Version: 440.100 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce RTX 208... Off | 00000000:01:00.0 On | N/A |
| 35% 41C P2 90W / 260W | 10515MiB / 11016MiB | 11% Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1128 G /usr/lib/xorg/Xorg 102MiB |
| 0 1648 G /usr/lib/xorg/Xorg 380MiB |
| 0 1848 G /usr/bin/gnome-shell 279MiB |
| 0 10633 G ...uest-channel-token=1206236727 266MiB |
| 0 13794 G /usr/lib/firefox/firefox 6MiB |
| 0 17604 C python 9457MiB |
+-----------------------------------------------------------------------------+

我发现的只是 tensorflow 1.0 的解决方案:
sess = tf.Session(config=tf.ConfigProto(
intra_op_parallelism_threads=NUM_THREADS))
我有一个 Intel 9900k 和一个 RTX 2080 Ti 并使用 Ubuntu 20.04
E:当我在上面添加以下代码时,它使用 1 个核心 100%
tf.config.threading.set_intra_op_parallelism_threads(1)
tf.config.threading.set_inter_op_parallelism_threads(1)
但是再次将这个数字增加到 16 只使用所有核心 ~30%

最佳答案

这可能有很多问题,我通过以下方式为我解决了这个问题:
tf.config.threading.set_intra_op_parallelism_threads(<Your_Physical_Core_Count>) tf.config.threading.set_inter_op_parallelism_threads(<Your_Physical_Core_Count>)两者都与您的物理核心数有关。您不希望将超线程用于高度矢量化的操作,因为在没有任何间隙时您无法从并行化操作中受益。

"With a high level of vectorization, the number of execution gaps isvery small and there is possibly insufficient opportunity to make upany penalty due to increased contention in HT."


来自:Saini 等人,NASAA 高级 super 计算部门出版,2011:超线程对处理器的影响
生产应用中的资源利用
编辑:我不再确定,如果两者之一必须是 1。但是 100% 需要设置为物理。

关于Tensorflow 2.0 100% 使用所有 CPU 内核,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63336300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com