Skip to content

fix(training): install CUDA PyTorch for training on Windows and show package downloads - #105

Merged
xycld merged 1 commit into
mainfrom
fix/training-cuda-torch-progress
Nov 18, 2026
Merged

xycld merged 1 commit into
mainfrom
fix/training-cuda-torch-progress

Conversation

@xycld

@xycld xycld commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

What and why

Issue #8 has two parts. On Windows with an NVIDIA card the app installed the CPU build of PyTorch, and dependency downloads only said "downloading", with no progress.

PyTorch build. Runtimes and KohakuGBC already took PyTorch from the CUDA wheel index. The local training environment did not: installTrainerRuntime ran pip install -e <trainer> from PyPI, whose Windows wheel is CPU only. Now:

  • Index selection. PyTorch is installed first. torchIndexes (main/services/trainers.ts) decides where it comes from:
    • On Windows, the CUDA indexes the NVIDIA driver runs (cu130 ≥ 580, cu128 ≥ 570, cu126 ≥ 560), newest first. A driver too old for all of them gets cu126 alone. A driver of unknown age gets the oldest first.
    • The install takes the first index that carries the version the trainer pins. That ordering matters: the trainer pins torch>=2.13,<2.15, and cu128 stops at 2.11, while cu126 and cu130 carry 2.13–2.14.1.
    • It moves on to the next index only when pip or uv say the version is missing there (versionUnavailable), not on network errors.
    • Linux and macOS keep plain PyPI, whose wheels already use CUDA or MPS. 设置's PyTorch source or backend overrides all of this.
  • Environment record. The source used is recorded on the environment (TrainerRuntimeInfo.torchIndex).
    • A ready environment from another source is reinstalled. So is an older Windows environment, which predates the record, on an NVIDIA machine.
    • The replaced environment is deleted once no version uses it. An unfinished environment is picked up again only when it was made for the same sources.
    • When nvidia-smi doesn't answer, or fails for a reason other than being missing, nothing is replaced. A CUDA build is never downgraded, since it also runs on the CPU.
    • 安装环境 now refuses while that version is training.

Download progress. installPackages (main/services/packageInstall.ts) runs pip or uv and follows their output with a pure parser (main/lib/packageProgress.ts).

  • It reports the package being fetched, its size, how far it is (pip ≥ 24.1 with --progress-bar raw; uv prints no percentage off a terminal), how many packages are done, and when installing starts.
  • Training: readiness.prepare.packages feeds the trainer row of the first-use checklist. It shows also while the base model downloads alongside, is sent at most once a second without dropping the last update, and is cleared as soon as the environment ends.
  • 看图拆区域: GbcSetupProgress.download feeds its row in 设置 › 功能.

Wording is packageProgressText in lib/format.ts, for example "正在下载 torch · 2.7 GB · 已下载 3 个包".

How it was verified

  • pnpm lint (0 errors; the warnings were already there), pnpm format:check, pnpm typecheck, pnpm test:unit: 3845 passed.
    • test/main/lib/packageProgress.test.ts runs on lines recorded from pip 26 and uv 0.9.
    • test/main/services/trainers.test.ts covers index choice per platform, driver and setting, when an environment counts as current, and network error vs missing version.
    • Training checklist rows, plus the mock backend test.
  • pnpm build && pnpm test:e2e: 448 passed.
    • training.e2e.ts: the trainer row shows the package download, with aria-valuenow 42, while the base model downloads, then the install stage.
    • gbc.e2e.ts: 安装 shows the download in its row.
  • Real indexes and installs, checked during review:
    • The torch versions on cu126, cu128 and cu130.
    • A CUDA torch already installed stays when the trainer is then installed from PyPI ("Requirement already satisfied").
    • uv's and pip's real "version missing" output.
  • pnpm test:install: not applicable.
  • Docs: docs/reference/training.md (the environment step) and docs/reference/architecture.md (GBC install).

Platforms affected

  • Windows: the fix itself. An old environment on an NVIDIA machine is installed once more.
  • Linux: unchanged, since PyPI is kept. Progress is new.
  • macOS: unchanged. Progress is new.

Notes for the reviewer

  • Remote trainers (SSH, Linux hosts) are unchanged.
  • KohakuGBC still uses resolveTorchIndex (cu128) for its unpinned torch, which works today. If its [torch] extra ever needs torch above 2.11, it should move to the same candidate list.

…package downloads

On Windows the training environment took PyTorch from PyPI, whose Windows
wheel is CPU only, so NVIDIA machines trained on the CPU. PyTorch now comes
first from the CUDA wheel indexes the driver runs, newest first, taking the
first that carries the version the trainer pins (cu128 stops at 2.11).
Linux and macOS keep PyPI, whose wheels already fit. The source is recorded
on the environment; an older Windows environment on an NVIDIA machine is
installed again and the replaced one deleted.

The download is followed from pip or uv output: the training checklist and
the 看图拆区域 install show the package being fetched, its size, how far
(pip) and how many are done.
@xycld
xycld added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit f9a9960 Nov 18, 2026
5 checks passed
@xycld
xycld deleted the fix/training-cuda-torch-progress branch November 18, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant