Package: nvfan
nvfanA module to control Nvidia Graphic Cards' fan within python. Features:set constant fan speedset more aggressive fan schedule compared to stock to avoid overhaeting when doing Deep Learning or other computationally intense tasksWhy?My deep learning rig contains 2 GTX 1080ti graphic cards with no liquid cooling. It takes only a few minutes for the GPUs to hit the thermal threshold of 86°C after I start a training process. Yet, it only uses fans at 50% rate.This module uses a more aggressive fan speed and therefore avoids overheating, and thus throttling of GPU frequency at around 90° Celsius.What is special about it?You only have to add two to three lines to your main Deep Learning python script and then the fan speed is adjusted to keep GPU temperature at max 80° Celsius. When you Deep Learning pipeline exists, the control of the fann speed is automatically given back to the nvidia driver. Hence, fan speed is significantly reduced when finished to reduce noise.How to use it?Controlling nvidia gpu fan requires anXserver to be running. To runXwithout having a monitor attached to the system requires special config.PreparationSetup x config in a shell like below. You may need to usesudo.$nvidia-xconfig--enable-all-gpus--cool-bits=7--connected-monitor=Monitor0--allow-empty-initial-configuration--force-generateWarning: we used--force-generateflag. A backup of your previous config is saved and is reported as the result of running this function.Aa manual configuration could look likke this::$cat/etc/X11/xorg.conf.d/nv.conf# startSection"Device"Identifier"Device0"Driver"nvidia"VendorName"NVIDIA Corporation"BoardName"GeForce GTX 1080 Ti"Option"Coolbits""4"EndSection# trailSee alsohttps://wiki.archlinux.org/index.php/NVIDIA/Tips_and_tricksRun XI think the best way is to use xinit:$xinit&Leavve this sttep out if  you are  using a desktoop envirronment like Gnoome, KDE, or similar.DependenciesPlease make surenvdia-smiandnvidia-settingsare installed. The latter usually needs to be installed manually whereas the former is usually included in the nvidia driver package.Install nvfan$pipinstallnvfanUsageYou can use command line script:$nvfanconstant-g0-s60# sets a constant speed at 60%Or in your python script:importnvfanfirst_gpu=0nvfan.constant(first_gpu,60)The above script, puts GPU 0 inconstantmode with 60% speed. You can useaggressiveordrivermodes too: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)Instead of using the module you can use theGPUclass to have more control (i.e. setting custom X11 display, if not setDISPLAYenvironment variable is used, or if not set,:0is used as fallback)importnvfangpu=gpufan.GPU(0,display=":1")# or use default `None` for automatic lookup of displaygpu.aggressive()You can also omit the first parameter (device) like so:importnvfangpu=gpufan.GPU()# or use default `None` for automatic lookup of displaygpu.aggressive()Then all available GPUs are set to aggressive speed.DecoratorsAs another syntactic sugar you can annotate functions, which will set the constant/aggressive speed before calling the decorated method and as soon as it returns will give the control back to the nvidia driver:importtimefromnvfan.decoratorsimportconstant,aggressive@constant(percentage=95)defmain():time.sleep(60)@aggressive()defmain_agg():time.sleep(60)if__name__=='__main__':main()main_agg()CautionUse this module at your own risk. The author takes no responsibility and the scripts come with no warranty.