(dispatcher: TaskEventDispatcher, nightly: boolean = false)
| 294 | * @returns |
| 295 | */ |
| 296 | export async function installPyTorchForGPU(dispatcher: TaskEventDispatcher, nightly: boolean = false): Promise<boolean> { |
| 297 | const { PIP_PATH, PYTHON_PATH } = conda.getCondaPaths(); |
| 298 | let installCommand = ""; |
| 299 | logger.info("start installing Pytorch"); |
| 300 | dispatcher({ |
| 301 | message: "Start installing PyTorch..." |
| 302 | }); |
| 303 | |
| 304 | let success = false; |
| 305 | let lastError = null; |
| 306 | for (let i = 0; i < 3; i++) { |
| 307 | if (isMac) { |
| 308 | try { |
| 309 | installCommand = `${PIP_PATH} install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu`; |
| 310 | await runCommand(installCommand, dispatcher); |
| 311 | success = true; |
| 312 | break; |
| 313 | } catch (error: any) { |
| 314 | lastError = error; |
| 315 | } |
| 316 | } else { |
| 317 | try { |
| 318 | const gpuType = await getGPUType() |
| 319 | |
| 320 | dispatcher({ |
| 321 | message: "GPU Type: " + gpuType + ", pip: " + PIP_PATH |
| 322 | }) |
| 323 | // AMD GPU |
| 324 | if (gpuType === 'amd') { |
| 325 | const rocmVersion = nightly ? 'rocm5.7' : 'rocm5.6'; |
| 326 | const installCommand = nightly |
| 327 | ? `${PIP_PATH} install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/${rocmVersion}` |
| 328 | : ` ${PIP_PATH} install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/${rocmVersion}`; |
| 329 | |
| 330 | await runCommand(installCommand, dispatcher); |
| 331 | success = true; |
| 332 | break; |
| 333 | } |
| 334 | // NVIDIA GPU |
| 335 | else if (gpuType === 'nvidia') { |
| 336 | installCommand = `${PIP_PATH} install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121`; |
| 337 | await runCommand(installCommand, dispatcher); |
| 338 | success = true; |
| 339 | break; |
| 340 | } |
| 341 | |
| 342 | // https://github.com/Comfy-Org/comfy-cli/issues/50 |
| 343 | else if (gpuType === "intel") { |
| 344 | await runCommand(`${PIP_PATH} install mkl mkl-dpcpp`, dispatcher); |
| 345 | installCommand = `${PIP_PATH} install torch==2.1.0.post2 torchvision==0.16.0.post2 torchaudio==2.1.0.post2 intel-extension-for-pytorch==2.1.30 --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/` |
| 346 | await runCommand(installCommand, dispatcher); |
| 347 | success = true; |
| 348 | break; |
| 349 | } |
| 350 | |
| 351 | else { |
| 352 | installCommand = `${PIP_PATH} install torch torchvision torchaudio`; |
| 353 | await runCommand(installCommand, dispatcher); |
no test coverage detected