Advertisement
Guest User

prune.bat

a guest
Sep 16th, 2022
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. @echo off
  2.  
  3. if not defined PYTHON (set PYTHON=python)
  4. if not defined GIT (set GIT=git)
  5. if not defined COMMANDLINE_ARGS (set COMMANDLINE_ARGS=%*)
  6. if not defined VENV_DIR (set VENV_DIR=venv)
  7. if not defined TORCH_COMMAND (set TORCH_COMMAND=pip install torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113)
  8. if not defined REQS_FILE (set REQS_FILE=requirements_versions.txt)
  9.  
  10. mkdir tmp 2>NUL
  11.  
  12. %PYTHON% -c "" >tmp/stdout.txt 2>tmp/stderr.txt
  13. if %ERRORLEVEL% == 0 goto :setup_venv
  14. echo Couldn't launch python
  15. goto :show_stdout_stderr
  16.  
  17. :setup_venv
  18. if [%VENV_DIR%] == [-] goto :skip_venv
  19.  
  20. dir %VENV_DIR%\Scripts\Python.exe >tmp/stdout.txt 2>tmp/stderr.txt
  21. if %ERRORLEVEL% == 0 goto :activate_venv
  22.  
  23. for /f "delims=" %%i in ('CALL %PYTHON% -c "import sys; print(sys.executable)"') do set PYTHON_FULLNAME="%%i"
  24. echo Creating venv in directory %VENV_DIR% using python %PYTHON_FULLNAME%
  25. %PYTHON_FULLNAME% -m venv %VENV_DIR% >tmp/stdout.txt 2>tmp/stderr.txt
  26. if %ERRORLEVEL% == 0 goto :activate_venv
  27. echo Unable to create venv in directory %VENV_DIR%
  28. goto :show_stdout_stderr
  29.  
  30. :activate_venv
  31. set PYTHON="%~dp0%VENV_DIR%\Scripts\Python.exe"
  32. %PYTHON% --version
  33. echo venv %PYTHON%
  34. goto :install_torch
  35.  
  36. :skip_venv
  37. echo Skip
  38. %PYTHON% --version
  39.  
  40. :install_torch
  41. %PYTHON% -c "import torch" >tmp/stdout.txt 2>tmp/stderr.txt
  42. if %ERRORLEVEL% == 0 goto :check_gpu
  43. echo Installing torch...
  44. %PYTHON% -m %TORCH_COMMAND% >tmp/stdout.txt 2>tmp/stderr.txt
  45.  
  46. if %ERRORLEVEL% == 0 goto :check_gpu
  47. echo Failed to install torch
  48. goto :show_stdout_stderr
  49.  
  50. :check_gpu
  51. %PYTHON% -c "import torch; assert torch.cuda.is_available(), 'CUDA is not available'" >tmp/stdout.txt 2>tmp/stderr.txt
  52. if %ERRORLEVEL% == 0 goto :launch
  53. echo Torch is not able to use GPU
  54. goto :show_stdout_stderr
  55.  
  56. :launch
  57. echo Launching prune.py...
  58. %PYTHON% prune.py
  59. pause
  60. exit /b
  61.  
  62. :show_stdout_stderr
  63.  
  64. echo.
  65. echo exit code: %errorlevel%
  66.  
  67. for /f %%i in ("tmp\stdout.txt") do set size=%%~zi
  68. if %size% equ 0 goto :show_stderr
  69. echo.
  70. echo stdout:
  71. type tmp\stdout.txt
  72.  
  73. :show_stderr
  74. for /f %%i in ("tmp\stderr.txt") do set size=%%~zi
  75. if %size% equ 0 goto :show_stderr
  76. echo.
  77. echo stderr:
  78. type tmp\stderr.txt
  79.  
  80. :endofscript
  81.  
  82. echo.
  83. echo Launch unsuccessful. Exiting.
  84. pause
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement