Skip to content

Instantly share code, notes, and snippets.

@BlueskyFR
Created May 11, 2023 09:56
Show Gist options
  • Save BlueskyFR/1c0a93f8e644344addd250e900fdd66e to your computer and use it in GitHub Desktop.
Save BlueskyFR/1c0a93f8e644344addd250e900fdd66e to your computer and use it in GitHub Desktop.

Conda CUDA environnement that takes precedence over the host's

The following is a code snippet that installs torch along with a full cuda environment that takes precedence over the host's. The only problem is that $TORCH_VERSION must be compatible with/compiled against $CUDA_VERSION, and the latter should be available in conda's nvidia channel (older CUDA versions are not available).

ENV_NAME=segformer CUDA_VERSION=11.1 TORCH_VERSION=1.9 cli=mamba
$cli deactivate
$cli env remove -n $ENV_NAME
$cli create -n $ENV_NAME -c conda-forge -c nvidia python=3.10 gcc=11 gxx cuda-runtime=$CUDA_VERSION cuda-nvcc=$CUDA_VERSION cudatoolkit=$CUDA_VERSION cuda-libraries=$CUDA_VERSION cuda-libraries-dev=$CUDA_VERSION cuda-cudart=$CUDA_VERSION cudnn && \
$cli activate $ENV_NAME && \
pip install light-the-torch && \
ltt install torch==$TORCH_VERSION torchvision

$cli env config vars set CUDA_HOME="/opt/mambaforge/envs/$CONDA_PREFIX"
$cli deactivate
$cli activate $ENV_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment