install_env.bat 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. @echo off
  2. chcp 65001
  3. set USE_MIRROR=true
  4. set INSTALL_TYPE=preview
  5. echo "USE_MIRROR: %USE_MIRROR%"
  6. echo "INSTALL_TYPE: %INSTALL_TYPE%"
  7. setlocal enabledelayedexpansion
  8. cd /D "%~dp0"
  9. set PATH="%PATH%";%SystemRoot%\system32
  10. echo %PATH%
  11. echo "%CD%"| findstr /R /C:"[!#\$%&()\*+,;<=>?@\[\]\^`{|}~\u4E00-\u9FFF ] " >nul && (
  12. echo.
  13. echo There are special characters in the current path, please make the path of fish-speech free of special characters before running. && (
  14. goto end
  15. )
  16. )
  17. set TMP=%CD%\fishenv
  18. set TEMP=%CD%\fishenv
  19. (call conda deactivate && call conda deactivate && call conda deactivate) 2>nul
  20. set INSTALL_DIR=%cd%\fishenv
  21. set CONDA_ROOT_PREFIX=%cd%\fishenv\conda
  22. set INSTALL_ENV_DIR=%cd%\fishenv\env
  23. set PIP_CMD=%cd%\fishenv\env\python -m pip
  24. set PYTHON_CMD=%cd%\fishenv\env\python
  25. set API_FLAG_PATH=%~dp0API_FLAGS.txt
  26. set MINICONDA_DOWNLOAD_URL=https://repo.anaconda.com/miniconda/Miniconda3-py310_23.3.1-0-Windows-x86_64.exe
  27. if "!USE_MIRROR!" == "true" (
  28. set MINICONDA_DOWNLOAD_URL=https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_23.3.1-0-Windows-x86_64.exe
  29. )
  30. set MINICONDA_CHECKSUM=307194e1f12bbeb52b083634e89cc67db4f7980bd542254b43d3309eaf7cb358
  31. set conda_exists=F
  32. call "%CONDA_ROOT_PREFIX%\_conda.exe" --version >nul 2>&1
  33. if "%ERRORLEVEL%" EQU "0" set conda_exists=T
  34. if "%conda_exists%" == "F" (
  35. echo.
  36. echo Downloading Miniconda...
  37. mkdir "%INSTALL_DIR%" 2>nul
  38. call curl -Lk "%MINICONDA_DOWNLOAD_URL%" > "%INSTALL_DIR%\miniconda_installer.exe"
  39. if errorlevel 1 (
  40. echo.
  41. echo Failed to download miniconda.
  42. goto end
  43. )
  44. for /f %%a in ('
  45. certutil -hashfile "%INSTALL_DIR%\miniconda_installer.exe" sha256
  46. ^| find /i /v " "
  47. ^| find /i "%MINICONDA_CHECKSUM%"
  48. ') do (
  49. set "hash=%%a"
  50. )
  51. if not defined hash (
  52. echo.
  53. echo Miniconda hash mismatched!
  54. del "%INSTALL_DIR%\miniconda_installer.exe"
  55. goto end
  56. ) else (
  57. echo.
  58. echo Miniconda hash matched successfully.
  59. )
  60. echo Downloaded "%CONDA_ROOT_PREFIX%"
  61. start /wait "" "%INSTALL_DIR%\miniconda_installer.exe" /InstallationType=JustMe /NoShortcuts=1 /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%CONDA_ROOT_PREFIX%
  62. call "%CONDA_ROOT_PREFIX%\_conda.exe" --version
  63. if errorlevel 1 (
  64. echo.
  65. echo Cannot install Miniconda.
  66. goto end
  67. ) else (
  68. echo.
  69. echo Miniconda Install success.
  70. )
  71. del "%INSTALL_DIR%\miniconda_installer.exe"
  72. )
  73. if not exist "%INSTALL_ENV_DIR%" (
  74. echo.
  75. echo Creating Conda Environment...
  76. if "!USE_MIRROR!" == "true" (
  77. call "%CONDA_ROOT_PREFIX%\_conda.exe" create --no-shortcuts -y -k --prefix "%INSTALL_ENV_DIR%" -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ python=3.10
  78. ) else (
  79. call "%CONDA_ROOT_PREFIX%\_conda.exe" create --no-shortcuts -y -k --prefix "%INSTALL_ENV_DIR%" python=3.10
  80. )
  81. if errorlevel 1 (
  82. echo.
  83. echo Failed to Create Environment.
  84. goto end
  85. )
  86. )
  87. if not exist "%INSTALL_ENV_DIR%\python.exe" (
  88. echo.
  89. echo Conda Env does not exist.
  90. goto end
  91. )
  92. set PYTHONNOUSERSITE=1
  93. set PYTHONPATH=
  94. set PYTHONHOME=
  95. set "CUDA_PATH=%INSTALL_ENV_DIR%"
  96. set "CUDA_HOME=%CUDA_PATH%"
  97. call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%"
  98. if errorlevel 1 (
  99. echo.
  100. echo Failed to activate Env.
  101. goto end
  102. ) else (
  103. echo.
  104. echo successfully create env.
  105. )
  106. set "packages=torch torchvision torchaudio fish-speech"
  107. if "%INSTALL_TYPE%"=="preview" (
  108. set "packages=!packages! triton_windows"
  109. )
  110. set "HF_ENDPOINT=https://huggingface.co"
  111. set "no_proxy="
  112. if "%USE_MIRROR%"=="true" (
  113. set "HF_ENDPOINT=https://hf-mirror.com"
  114. set "no_proxy=localhost,127.0.0.1,0.0.0.0"
  115. )
  116. echo "HF_ENDPOINT: !HF_ENDPOINT!"
  117. echo "NO_PROXY: !no_proxy!"
  118. set "install_packages="
  119. for %%p in (%packages%) do (
  120. %PIP_CMD% show %%p >nul 2>&1
  121. if errorlevel 1 (
  122. set "install_packages=!install_packages! %%p"
  123. )
  124. )
  125. if not "%install_packages%"=="" (
  126. echo.
  127. echo Installing: %install_packages%
  128. for %%p in (%install_packages%) do (
  129. if "%INSTALL_TYPE%"=="preview" (
  130. call :install_preview %%p
  131. ) else (
  132. call :install_stable %%p
  133. )
  134. )
  135. )
  136. endlocal
  137. echo "Environment Check: Success."
  138. pause
  139. goto :EOF
  140. :install_preview
  141. setlocal
  142. if "%1"=="torch" (
  143. call :download_and_install "torch-2.4.0.dev20240427+cu121-cp310-cp310-win_amd64.whl" ^
  144. "%HF_ENDPOINT%/datasets/SpicyqSama007/windows_compile/resolve/main/torch-2.4.0.dev20240427_cu121-cp310-cp310-win_amd64.whl?download=true" ^
  145. "b091308f4cb74e63d0323afd67c92f2279d9e488d8cbf467bcc7b939bcd74e0b"
  146. ) else if "%1"=="torchvision" (
  147. call :download_and_install "torchvision-0.19.0.dev20240428+cu121-cp310-cp310-win_amd64.whl" ^
  148. "%HF_ENDPOINT%/datasets/SpicyqSama007/windows_compile/resolve/main/torchvision-0.19.0.dev20240428_cu121-cp310-cp310-win_amd64.whl?download=true" ^
  149. "7e46d0a89534013f001563d15e80f9eb431089571720c51f2cc595feeb01d785"
  150. ) else if "%1"=="torchaudio" (
  151. call :download_and_install "torchaudio-2.2.0.dev20240427+cu121-cp310-cp310-win_amd64.whl" ^
  152. "%HF_ENDPOINT%/datasets/SpicyqSama007/windows_compile/resolve/main/torchaudio-2.2.0.dev20240427_cu121-cp310-cp310-win_amd64.whl?download=true" ^
  153. "abafb4bc82cbc6f58f18e1b95191bc1884c28e404781082db2eb540b4fae8a5d"
  154. ) else if "%1"=="fish-speech" (
  155. %PIP_CMD% install -e . --upgrade-strategy only-if-needed
  156. ) else if "%1"=="triton_windows" (
  157. call :download_and_install "triton_windows-0.1.0-py3-none-any.whl" ^
  158. "%HF_ENDPOINT%/datasets/SpicyqSama007/windows_compile/resolve/main/triton_windows-0.1.0-py3-none-any.whl?download=true" ^
  159. "2cc998638180f37cf5025ab65e48c7f629aa5a369176cfa32177d2bd9aa26a0a"
  160. )
  161. endlocal
  162. goto :EOF
  163. :install_stable
  164. if "%USE_MIRROR%"=="true" (
  165. if "%1"=="torch" (
  166. %PIP_CMD% install torch==2.3.1 --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121 --no-warn-script-location
  167. ) else if "%1"=="torchvision" (
  168. %PIP_CMD% install torchvision==0.18.1 --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121 --no-warn-script-location
  169. ) else if "%1"=="torchaudio" (
  170. %PIP_CMD% install torchaudio==2.3.1 --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121 --no-warn-script-location
  171. ) else if "%1"=="fish-speech" (
  172. %PIP_CMD% install -e . -i https://pypi.tuna.tsinghua.edu.cn/simple
  173. )
  174. ) else (
  175. if "%1"=="torch" (
  176. %PIP_CMD% install torch==2.3.1 --index-url https://download.pytorch.org/whl/cu121 --no-warn-script-location
  177. ) else if "%1"=="torchvision" (
  178. %PIP_CMD% install torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu121 --no-warn-script-location
  179. ) else if "%1"=="torchaudio" (
  180. %PIP_CMD% install torchaudio==2.3.1 --index-url https://download.pytorch.org/whl/cu121 --no-warn-script-location
  181. ) else if "%1"=="fish-speech" (
  182. %PIP_CMD% install -e .
  183. )
  184. )
  185. goto :EOF
  186. :download_and_install
  187. setlocal
  188. set "WHEEL_FILE=%1"
  189. set "URL=%2"
  190. set "CHKSUM=%3"
  191. :DOWNLOAD
  192. if not exist "%WHEEL_FILE%" (
  193. call curl -Lk "%URL%" --output "%WHEEL_FILE%"
  194. )
  195. for /f "delims=" %%I in ("certutil -hashfile %WHEEL_FILE% SHA256 ^| find /i %CHKSUM%") do (
  196. set "FILE_VALID=true"
  197. )
  198. if not defined FILE_VALID (
  199. echo File checksum does not match, re-downloading...
  200. del "%WHEEL_FILE%"
  201. goto DOWNLOAD
  202. )
  203. echo "OK for %WHEEL_FILE%"
  204. %PIP_CMD% install "%WHEEL_FILE%" --no-warn-script-location
  205. del "%WHEEL_FILE%"
  206. endlocal
  207. goto :EOF