Tensorflow on nixos 20.03

Hello,

I’m trying to get tensorflow going with my GPU (GeForce RTX 2080 Ti) and have not been having any success. I am running nixos 20.03 and following grahamc’s example (GitHub - grahamc/nixos-cuda-example: A repository with a NixOS configuration to run CUDA code on NVIDIA GPUs) I’ve been able to get nvidia-smi installed and working and some of the examples run (some also fail to compile).

However, trying to run tensorflow seems to fail. I’ve been trying various shell.nix files (Tensorflow - NixOS Wiki) which seem to patch various python wheel files or alternately download and compile using Bezel, but which then claim there is no GPU present.

Am I missing something? It appears many people have had success, but maybe things (nvidia drivers?) have moved on and are no longer repeatable?

Is anyone able to use tensorflow on nixos 20.03?

Hello!

I wrote that wiki link and regularly use both tensorflow 1 and 2 (wheel and nixpkgs). I can help debug your configuration. That nix-shell should have worked. I’m assuming you pip installed tensorflow within that shell? I’m on IRC or the discord if you want to debug more interactively.

thanks - I’ll go to irc

One thought, if you’re on 20.03 LD_LIBRARY_PATH no longer contains the nvidia libraries by default (under /run/opengl-driver/lib:/run/opengl-driver-32/lib). You can add this line to your config to change that, or use nixGL in your .envrc

  hardware.opengl = {
    enable = true;
    driSupport32Bit = true;
    extraPackages32 = with pkgs.pkgsi686Linux; [ libva ];
    setLdLibraryPath = true; <- This is the line you should add to restore old functionality
  };
2 Likes

thanks - I suspect (am hopeful) that that may be it. I’m in the middle of going back to try 19.09, but I’ll give this a go first.

I almost guarantee that’s it. This nix-shell also automatically handles appending LD_LIBRARY_PATH for you if you want to keep LD_LIBRARY_PATH pure, and uses a shellHook call to nixGL combined with a .envrc to source the shellHook should you be using lorri (which you should if you’re using cuda, or you can accidentally GC the library)

1 Like

Wow!

Combination of adding that chunk to my /etc/nixos/configuration.nix and the extra bits on the LD_LIBRARY_PATH has made it work!

I’ll look at using lorri here - I use it for my haskell work, but hadn’t thought about it here.

Thanks very much.

No problem, I forgot to link above, but the above git repo shows how you can automatically set everything up and uses poetry2nix which I would recommend checking out (it handles tensorflow, but currently has to build from source)

This helped me too, thanks @mjlbach!