Skip to content

Instantly share code, notes, and snippets.

@gdiaz384
Last active February 8, 2024 07:58
Show Gist options
  • Save gdiaz384/d1585dc97c377d3be9df5ff4427116e0 to your computer and use it in GitHub Desktop.
Save gdiaz384/d1585dc97c377d3be9df5ff4427116e0 to your computer and use it in GitHub Desktop.
This script attempts to compile fairseq from source on Windows. See full writeup for details and Linux.
:: This script attempts to compile fairseq from source on Windows, however it makes a lot of assumptions.
:: For a full writeup, see: https://github.com/gdiaz384/py3TranslateLLM/wiki/fairseq-Installation-Guide
:: This script assumes:
:: 1) Python has been downloaded and extracted to "Python38" or a similar folder name. Update the pythonDir below with the actual version.
:: 2) fairseq has already been downloaded, extracted and is available at "fairseq".
:: To clone fairseq:
:: git.exe clone https://github.com/facebookresearch/fairseq
:: 3) The ninja build system is available somewhere in %path%.
:: https://ninja-build.org/
:: 4) This also assumes the Visual Studio C++ 14.0/2015 Build Tools have been installed and are available.
:: The 2015 Build Tools are available in Visual Studio 2017. https://aka.ms/vs/15/release/vs_buildtools.exe
::@echo off
:: Change directory to the current location of the script so that paths specified in the script are relative to the script instead of wherever the command prompt happens to be at the time.
pushd "%~dp0"
:: Update some relative paths to ensure work with the local Python version.
set pythonDir=Python38
set pipLocation="%pythonDir%\python.exe" -s -E -m pip
:: Make sure the script is run from the correct location.
if not exist "%pythonDir%" goto end
if not exist "%pythonDir%\python.exe" goto end
if not exist "fairseq" goto end
:: Upgrade pip
"%pythonDir%\python.exe" -s -E -m pip install --upgrade pip
:: Update build tools.
"%pythonDir%\python.exe" -s -E -m pip install wheel setuptools
:: Use pip to install Torch 2.2.0 CPU from PyTorch.org
:: To install the latest versions instead, omit the "==2.2.0" parts.
%pipLocation% install torch==2.2.0 torchvision==0.17.0 torchaudio==2.2.0 --index-url https://download.pytorch.org/whl/cpu
:: Install some more fairseq dependencies.
%pipLocation% install bitarray hydra-core omegaconf sacrebleu scikit-learn sentencepiece tqdm tensorboardX
cd fairseq
"..\%pythonDir%\python.exe" -s -E -m pip install --editable ./
"..\%pythonDir%\python.exe" -s -E setup.py build_ext --inplace
"..\%pythonDir%\python.exe" -s -E setup.py bdist_wheel
:end
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment