需求: 写CI脚本中需要安装pytorch,pytorch官网根据系统、安装工具、编程语言、硬件配置的差异性,给出了不同的安装方法。所以在CI脚本中不得不使用条件判断,搜索官方文档找到的答案如下:
- name: Install pytorch according to the system
if: ${{ matrix.os == 'macos-11' || matrix.os == 'macos-latest' }}
run: |
python -m pip install torch torchvision torchaudio
brew install libomp # lightgbm dependencies
- name: Install pytorch according to the system
if: ${{ matrix.os == 'ubuntu-18.04' || matrix.os == 'ubuntu-20.04' }}
run: |
python -m pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu
- name: Install pytorch according to the system
if: ${{ matrix.os == 'windows-latest' }}
run: |
python -m pip install torch torchvision torchaudio