Wednesday, 17 April 2024

nixos, poetry: Install pytorch with cuda

https://github.com/tom-010/minimal-nixos-pytorch-example
/etx/nixos/configuration.nix:
environment.systemPackages = with pkgs; [
    cudatoolkit
    cudaPackages_12_2.cudatoolkit
  ];
shell.nix (thanks: https://discourse.nixos.org/t/installing-pytorch-into-a-virtual-python-environment/34720)
{ pkgs ? import  {} }:

# add unstable
pkgs.mkShell {
  buildInputs = with pkgs; [
    gcc
    cudaPackages_12_2.cudatoolkit
  ];

  shellHook = ''
    export LD_LIBRARY_PATH=${pkgs.gcc}/lib64:${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH
    # export SHELL=${pkgs.zsh}/bin/zsh
    export CUDA_PATH=${pkgs.cudaPackages_12_2.cudatoolkit}
    export LD_LIBRARY_PATH=${pkgs.cudaPackages_12_2.cudatoolkit}/lib64:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=/run/opengl-driver/lib:$LD_LIBRARY_PATH
    source $(poetry env info --path)/bin/activate # instead of poetry shell
    poetry run python3 gpu/main.py
  '';
}
poetry:
poetry install torch torchaudio torchvision

No comments:

Post a Comment

Parse Wikipedia dump

""" This module processes Wikipedia dump files by extracting individual articles and parsing them into a structured format, ...