Pytorch and CUDA: "Torch not compiled with CUDA enabled"

You need to enable CUDA when importing nixpkgs, since the default is to build PyTorch without CUDA support (since CUDA is non-free). E.g.:

import sources.nixpkgs {
  config = {
    allowUnfree = true;
    cudaSupport = true;
  };
}

cudaSupport enables CUDA for all packages that support this option.

Since unfree packages are not built by Hydra, CUDA-enabled PyTorch is not in the binary cache. If you want to avoid the long-ish build (depending on your hardware), you can also use pytorch-bin (in your case pkgs.python38Packages.pytorch-bin). pytorch-bin uses the upstream PyTorch.org builds, patched to work with libraries in the Nix store.

4 Likes