Home > Enterprise >  Python running slower than before some system change
Python running slower than before some system change

Time:11-18

I have two computers at home for my python projects. One is a PC with an Intel i5-7400 CPU and the other is a laptop with an Intel i7-10750H CPU. Presumably the laptop is faster running the same python code than the PC. This was the case before I made some changes to the laptop in an attempt to leverage its Nvida GPU for training DNN model.

I followed the instruction from Tensorflow GPU support webpage to upgrade Nvida GPU driver, install Cuda toolkit and cuDNN with the recommanded version. After the installation, I created a new conda environment and installed latest tensorflow. With all this I could detect my GPU with tf.config.list_physical_devices() and run some test code on the GPU. However, the performance was not lifted and even worse, the laptop became noticeably slower running the same code on its CPU. I tested the following simple code on both machines:

from datetime import datetime
import numpy as np

t0 = datetime.now()

for i in range(1000):
    a = np.random.rand(1000, 1000)
    b = np.random.rand(1000, 1000)
    c = np.matmul(a, b)

t1 = datetime.now()

print(t1 - t0)

The PC ran it in 32s but the laptop needed 45s. I tried a few things to resolve this, including uninstalling Cuda toolkit/cuDNN and reinstalling anaconda (tried different anaconda versions). But the issue still remains. Anyone has any insights about why this happens and what to try in order to address it? Many thanks.

CodePudding user response:

This is probably not your main problem however, your laptop run with battery? The laptop can decrease performance for saving battery life

CodePudding user response:

There are many reasons to consider. Firstly, The code you are ruining doesn't use GPU at all. It's all about CPU's holding the throttle. Basically, as a part of "Thermal management" Laptops CPU power limit throttle is constantly controlled. Fact is in CPU's runs code faster than GPU's. So, maybe your laptop reaching thermal limitations and throttles down to slower for most of the time it takes to run the program. Maybe your PC CPU is able to withhold that throttle so it's finishing bit faster.

Once check Benchmarking your code. A wonderful instructions return here https://stackoverflow.com/a/1593034/15358800

  • Related