在python脚本中控制nvidia gpu fan。
nvfan的Python项目详细描述
nvfan
在python中控制nvidia显卡风扇的模块。功能:
- 设置恒定风扇转速
- 与库存相比,设置更积极的风扇计划,以避免在进行深入学习或其他计算密集型任务时出现过度操作
为什么?
我的深度学习设备包含2张没有液体冷却的GTX1080TI图形卡。在我开始一个训练过程后,GPU只需几分钟就达到86°C的温度阈值。然而,它只使用风扇在50%的速度。
该模块使用更积极的风扇转速,因此避免过热,从而将GPU频率节流至约90摄氏度。
它有什么特别之处?
您只需要在您的主要深入学习python脚本中添加两到三行代码,然后调整风扇速度以将gpu温度保持在最高80摄氏度。当您深入学习管道存在时,自动控制速度将自动返回给NVIDIA驱动程序。因此,风扇转速在完成时显著降低,以降低噪音。
如何使用?
控制nvidia gpu风扇需要运行X
服务器。要在不将监视器连接到系统的情况下运行X
,需要特殊的配置。
准备工作
在如下shell中设置x配置。您可能需要使用sudo
。
$ nvidia-xconfig --enable-all-gpus --cool-bits=7 --connected-monitor=Monitor0 --allow-empty-initial-configuration --force-generate
警告:我们使用了--force-generate
标志。将保存以前配置的备份,并作为运行此函数的结果进行报告。
手动配置可能如下所示:
$ cat /etc/X11/xorg.conf.d/nv.conf # start Section "Device" Identifier "Device0" Driver "nvidia" VendorName "NVIDIA Corporation" BoardName "GeForce GTX 1080 Ti" Option "Coolbits""4" EndSection # trail
另请参见https://wiki.archlinux.org/index.php/NVIDIA/Tips_and_tricks
运行x
我认为最好的办法是使用XIIT:$ xinit &
如果您使用的是GNOME、KDE或类似的桌面环境,请离开此步骤。
依赖关系
请确保安装了nvdia-smi
和nvidia-settings
。后者通常需要手动安装,而前者通常包含在NVIDIA驱动程序包中。
安装nvfan
$ pip install nvfan
用法
您可以使用命令行脚本:
$ nvfan constant -g 0 -s 60# sets a constant speed at 60%
或者在python脚本中:
importnvfanfirst_gpu=0nvfan.constant(first_gpu,60)
上面的脚本以60%的速度将gpu 0置于constant
模式。您也可以使用aggressive
或driver
模式:
second_gpu=1# In aggressive mode, a small increase in temperature causes a large increase in fan speed.nvfan.aggressive(second_gpu)# Give control back to the driver manually. Please note that after execution is finished, this line is automatically called so you don't have to.nvfan.driver(first_gpu)nvfan.driver(second_gpu)
不使用模块,您可以使用GPU
类来获得更多的控制(即,如果未设置DISPLAY
,则设置自定义x11显示,如果未设置,则使用:0
环境变量,或者如果未设置,则使用:0
作为回退)
importnvfangpu=gpufan.GPU(0,display=":1")# or use default `None` for automatic lookup of displaygpu.aggressive()
您还可以省略第一个参数(device
),如下所示:
importnvfangpu=gpufan.GPU()# or use default `None` for automatic lookup of displaygpu.aggressive()
然后所有可用的GPU都设置为攻击速度。
装饰工
作为另一个语法糖,您可以注释函数,在调用修饰方法之前,它将设置常数/攻击速度,并且一旦返回,就会将控件返回给NVIDIA驱动程序:
importtimefromnvfan.decoratorsimportconstant,aggressive@constant(percentage=95)defmain():time.sleep(60)@aggressive()defmain_agg():time.sleep(60)if__name__=='__main__':main()main_agg()
小心
请自行承担使用本模块的风险。作者不承担任何责任,剧本也没有保证。