scGPT的重新安装

scGPT的安装教程(以下顺序为实际安装顺序)

0. 创建 conda 环境后,首先安装 r-base python==3.8( python 版本需要大于3.7版本)

1. 使用 conda 安装 torch:安装支持 CUDA 的 PyTorch: 

    # pytorch 2.0.1 版本
    conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.7 -c pytorch -c nvidia
    
    # pytorch 1.13.0 版本
    conda install pytorch==1.13.0 torchvision==0.14.0 torchaudio==0.13.0 pytorch-cuda=11.7 -c pytorch -c nvidia
    
    # 当conda环境中需要装的CUDA版本与本地CUDA版本不一致时,
    # 需要另外安装 cudatoolkit(确定) 和 cuda-nvcc(不确定,仅供参考);
    # 举例:conda环境下安装 CUDA 11.6 版本的 pytorch 1.13.0 的版本
    conda install cudatoolkit==11.6 -c nvidia
    conda install pytorch==1.13.0 torchvision==0.14.0 torchaudio==0.13.0 pytorch-cuda=11.6 -c pytorch -c nvidia
    conda install cuda-nvcc -c nvidia

注意

  1. (好像和是否是pip源安装也无关)使用 pip 安装 torch 后,测试flash_attn时会报错:ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version GLIBCXX_3.4.29 not found问题

  2. 解决方法:丝滑解决ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29‘ not found问题-CSDN博客

    image.png

  3. 安装 cuda-nvccconda install cuda-nvcc -c nvidia

2. 使用 pip 安装 packaging 和 ninja

3. 安装 flash_attn

注意

  1. 安装 2.0.* 以上版本的flash_attn时,无需额外操作,但是要记得提前安装packaging 和 ninja;

  2. 安装 1.0.5 以下版本的flash_attn时,需要使用本地安装的方式安装

    # 第一步:clone到本地,并且克隆一些配置文件
    git clone https://github.com/Dao-AILab/flash-attention
    cd flash-attention 
    # 切换至指定版本的flash_attn
    git checkout v1.0.4
    # 克隆一些配置文件
    git submodule update --init --recursive
    
    # 第二步:执行下面命令
    cd flash-attention && pip install .
    # 可选操作
    pip install csrc/layer_norm
    pip install csrc/rotary
    # 成功安装
    
    ##############################################################
    # (下面这个方法无法成功安装flash_attn,已验证)
    # 安装 1.0.5 以下版本的另一种方法(错误方法),
    # pip安装完1.0.*版本的flash_attn以后,
    # 然后再pip本地安装rotary和layer_norm:
    pip install flash_attn==1.0.4 --no-build-isolation
    
    cd flash-attention 
    pip install csrc/layer_norm
    pip install csrc/rotary
    
    安装 flash_attn 1.0.4 报错及解决方法:
    1. 报错一:本地编译安装 flash_attn 1.0.4 时报错 image.png 解决方法:github.com/Dao-AILab/f…

      image.png

    2. 报错二:flash_attn 1.0.4 安装成功后报错

      image.png 解决方法:import flash_attn fail 环境中已经下载好flashattention了,但总是导入失败 · Issue #535 · QwenLM/Qwen (github.com)

      image.png

  3. 测试 flash_attn 是否安装成功:

    1. 测试一:

     # 首先安装 pytest
    
     pip install pytest
     # 测试 flash_attn
     # test_rotary.py 运行时间30s左右 
     pytest tests/test_rotary.py 
    

    运行成功结果:

    image.png

    2. 测试二:

     # pytest tests/test_flash_attn.py 运行时间90分钟左右
     pytest tests/test_flash_attn.py 
    

    运行成功结果: image.png 报错及原因: image.png

    3. 测试三:

    # python benchmarks/benchmark_flash_attention.py 运行时间2分钟左右
    

    运行成功结果: image.png 4. 测试四:

    # python benchmarks/benchmark_causal.py 运行时间 分钟左右
    

    运行成功结果: image.png

4. 安装 triton:

注意

  1. 最新版本的 triton 仅支持 CUDA 12.0 及以上版本,安装最新版本的triton会报错 RuntimeError: Triton Error [CUDA]: device kernel image is invalid。 解决方法 github.com/openai/trit… image.png

  2. 因此,对于 CUDA 版本为11.*的,通过安装 pip install triton==2.1.0 可解决报错 RuntimeError: `Triton Error [CUDA]: device kernel image is invalid 。github.com/openai/trit… image.png

5. 安装 scgpt

注意

  1. 有人提供的成功安装scgpt的环境文件。github.com/bowang-lab/…

  2. pip install --no-deps scgpt 命令的作用是仅安装 Python 包 scgpt 本身,而不安装它所声明的任何依赖包。

  3. 注意 pip install scgpt 后,需要卸载通过 pip 安装的 torch。

  4. scgpt 0.2.1版本,其做微调时可以使用 torch2.0版本和 flash_attn2.0版本了(未经验证,仅作为参考)。 github.com/bowang-lab/…

    image.png

6. 安装 其他依赖包

pip install numpy==1.21.6 numba==0.55.2 jax==0.3.13 jaxlib==0.3.10  matplotlib ml-dtypes pandas scikit-misc scipy seaborn torchmetrics

参考:

posted @ 2024-04-23 11:54  wuhaoliu  阅读(9)  评论(0)    收藏  举报  来源