Setting environment variables for Tensorflow (on Linux)

Installing and setting up FaceSwap


Forum rules

Read the FAQs and search the forum before posting a new topic.

Please mark any answers that fixed your problems so others can find the solutions.

Locked
User avatar
rmaurice
Posts: 2
Joined: Thu Mar 25, 2021 11:36 pm
Has thanked: 1 time

Setting environment variables for Tensorflow (on Linux)

Post by rmaurice »

Hi,

I seem to have trouble getting my small Nvidia GT710 card getting to do even menial work on Faceswap on Linux. My setup has been made today on Debian buster using the Linux install script as described on the Download page. The card is successfully detected as the drivers are properly installed. But when I start extraction, Tensorflow automatically switches to CPU because:

Code: Select all

2021-03-26 00:35:00.726016: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561]
Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GT 710 computeCapability: 3.5
coreClock: 0.954GHz coreCount: 1 deviceMemorySize: 1.96GiB deviceMemoryBandwidth: 13.41GiB/s

...

2021-03-26 00:35:02.323817: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1688] Ignoring visible gpu device
 (device: 0, name: GeForce GT 710, pci bus id: 0000:01:00.0, compute capability: 3.5)
 with core count: 1. The minimum required count is 4.
 You can adjust this requirement with the env var TF_MIN_GPU_MULTIPROCESSOR_COUNT.

The card has 192 Cuda cores, so I think there may be a bug in detection here. Anyway, as a workaround, I have been trying to set up TF_MIN_GPU_MULTIPROCESSOR_COUNT in my .bashrc file to 1, but it is not taken into account. I have tried modifying faceswap.py and add os.environ["TF_MIN_GPU_MULTIPROCESSOR_COUNT"] = "1" at startup, but it is not taken into account either. Of course I also did the usual close/restart terminal etc.

I wonder how can I set environment variables so that Tensorflow takes them into account in the context of an execution from Faceswap's GUI. Any help welcome!

by algeron » Sat Mar 27, 2021 7:05 pm

I had a similar problem on Windows. I was able to get it working by editing the hardcoded value in \lib\cli\launcher.py

Go to full post
User avatar
abigflea
Posts: 182
Joined: Sat Feb 22, 2020 10:59 pm
Answers: 2
Has thanked: 20 times
Been thanked: 62 times

Re: Setting environment variables for Tensorflow (on Linux)

Post by abigflea »

I'm pretty sure that GPU is not going to be supported.
Even if it was, a GT 710 is going to be excruciatingly slow.

:o I dunno what I'm doing :shock:
2X RTX 3090 : RTX 3080 : RTX: 2060 : 2x RTX 2080 Super : Ghetto 1060

User avatar
torzdf
Posts: 2649
Joined: Fri Jul 12, 2019 12:53 am
Answers: 159
Has thanked: 128 times
Been thanked: 622 times

Re: Setting environment variables for Tensorflow (on Linux)

Post by torzdf »

In the first instance, run Faceswap in VERBOSE mode and you should get a message from Tensorflow telling you why the GPU is not being used.

You can set an env variable by doing:

VARIABLE=variable ; python faceswap.py ...

My word is final

User avatar
algeron
Posts: 5
Joined: Sat Mar 27, 2021 7:00 pm
Answers: 1
Has thanked: 4 times
Been thanked: 1 time

Re: Setting environment variables for Tensorflow (on Linux)

Post by algeron »

I had a similar problem on Windows. I was able to get it working by editing the hardcoded value in \lib\cli\launcher.py

User avatar
torzdf
Posts: 2649
Joined: Fri Jul 12, 2019 12:53 am
Answers: 159
Has thanked: 128 times
Been thanked: 622 times

Re: Setting environment variables for Tensorflow (on Linux)

Post by torzdf »

I would say that editing the code directly is rarely the best idea, as it can prevent Faceswap from updating.

My word is final

User avatar
rmaurice
Posts: 2
Joined: Thu Mar 25, 2021 11:36 pm
Has thanked: 1 time

Re: Setting environment variables for Tensorflow (on Linux)

Post by rmaurice »

algeron wrote: Sat Mar 27, 2021 7:05 pm

I had a similar problem on Windows. I was able to get it working by editing the hardcoded value in \lib\cli\launcher.py

Thanks [mention]algeron[/mention]!

Those are lines 61-62 of launcher.py:

Code: Select all

    # Ensure tensorflow doesn't pin all threads to one core when using Math Kernel Library
    os.environ["TF_MIN_GPU_MULTIPROCESSOR_COUNT"] = "4"

Setting this to "1" does the trick and the computations are sent to the GPU.

[mention]torzdf[/mention]: is it possible to move this hardcoded setting into a user-configurable one, maybe in an "experimental" section?

User avatar
torzdf
Posts: 2649
Joined: Fri Jul 12, 2019 12:53 am
Answers: 159
Has thanked: 128 times
Been thanked: 622 times

Re: Setting environment variables for Tensorflow (on Linux)

Post by torzdf »

Honestly? I'd need to investigate why that hard coded value was put in in the first place. My preference would just be to remove it altogether, as I am not particularly a fan of setting environment variables inside applications.

My word is final

Locked