Repository navigation
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
When a nodepack changed torch or torchvision, torch_rollback() chose what to install from the torch version from before. Without a local label it sent `pip install --force` with the package names, which installs the newest releases and which uv refuses. With a label it sent the versions of a table that ends at 2.7.0, or the newest nightly build for a version that the table lacks. A nodepack that removed torch, or removed torchvision and left torch as it was, ended the restore in a KeyError. - Give torch_rollback() what was installed before and after the nodepack, and count a removed torch or torchvision as changed - Install each of torch, torchvision and torchaudio that is not the build it was before as `<name>===<build>`, torch first with its dependencies, then the other two with `--no-deps`. Name the index https://download.pytorch.org/whl/<label> for a release with a local label, and the nightly index with `--pre` for a development build - Install again the requirements of the restored torch whose files a distribution of the nodepack overwrote, such as the CUDA libraries of a torch of another CUDA version - When the nodepack changed torch and added a torchaudio to an install without one, ask last for one no newer than the restored torch: `torch===<build> torchaudio<=<public version of that torch>`, with torch's index, if it has one, as `--index-url`, sent once. pip and uv keep a torchaudio that satisfies it, so a build for another CUDA version stays and can fail to import - With uv, ask with `--dry-run` which form of a command that puts back a build resolves: as it is, with `--offline`, or with `--offline` and without the PyTorch index. Send the first that does once, or the command as it is when none does - Remove the version table - Extend tests/test_torch_rollback.py: the tests run fix_broken() with pip and with uv, and check the commands it sends and the lines it logs - Add a CHANGELOG entry An install command that fails ends the restore with "Failed to restore PyTorch" and that command. uv does not put back what it removed when a command fails while it installs, so the restore sends no command after it, and no other build is installed in place of the one from before. What the restore cannot put back is listed in #3618. The same change for main is #3617.
ltdrdata
added a commit
that referenced
this pull request
Nov 28, 2026
When a nodepack changed torch or torchvision, torch_rollback() chose what to install from the torch version from before. Without a local label it sent `pip install --force` with the package names, which installs the newest releases and which uv refuses. With a label it sent the versions of a table that ends at 2.7.0, or the newest nightly build for a version that the table lacks. A nodepack that removed torch, or removed torchvision and left torch as it was, ended the restore in a KeyError. - Give torch_rollback() what was installed before and after the nodepack, and count a removed torch or torchvision as changed - Install each of torch, torchvision and torchaudio that is not the build it was before as `<name>===<build>`, torch first with its dependencies, then the other two with `--no-deps`. Name the index https://download.pytorch.org/whl/<label> for a release with a local label, and the nightly index with `--pre` for a development build - Install again the requirements of the restored torch whose files a distribution of the nodepack overwrote, such as the CUDA libraries of a torch of another CUDA version - When the nodepack changed torch and added a torchaudio to an install without one, ask last for one no newer than the restored torch: `torch===<build> torchaudio<=<public version of that torch>`, with torch's index, if it has one, as `--index-url`, sent once. pip and uv keep a torchaudio that satisfies it, so a build for another CUDA version stays and can fail to import - With uv, ask with `--dry-run` which form of a command that puts back a build resolves: as it is, with `--offline`, or with `--offline` and without the PyTorch index. Send the first that does once, or the command as it is when none does - Remove the version table - Extend tests/test_torch_rollback.py: the tests run fix_broken() with pip and with uv, and check the commands it sends and the lines it logs - Add a CHANGELOG entry An install command that fails ends the restore with "Failed to restore PyTorch" and that command. uv does not put back what it removed when a command fails while it installs, so the restore sends no command after it, and no other build is installed in place of the one from before. What the restore cannot put back is listed in #3617. The same change for manager-v4 is #3618.
ltdrdata
force-pushed
the
fix/v4-torch-restore
branch
from
November 28, 2026 10:46
8b1348b to
09a29ba
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent and scope
When a nodepack changed torch or torchvision,
PIPFixer.fix_broken()runs the PyTorch restore,torch_rollback(). It chose what to install from the torch version from before. For a torch without a local label it sentpip install --forcewith the package names alone, which installs the newest releases and which uv refuses. For a torch with a label it installed the versions of a table that ends at 2.7.0, and for a version that the table lacks, a nightly build. A nodepack that removed torch, or removed torchvision and left torch as it was, ended the restore in aKeyError. After this change the restore installs exactly the builds that were installed before the nodepack, or it installs no other build in their place and logs the failure.torch_rollback()andPIPFixer.fix_broken()incomfyui_manager/common/manager_util.py, whichcomfyui_manager/prestartup_script.py, themanager_core.pyof both servers andcm_cli/__main__.pycall. pip and uv; uv is the default on this line.<name>===<build>, local label included. Packages that the nodepack left alone are not named.--extra-index-url:whl/<label>for a release with a label,whl/nightly/<label>with--prefor a development build, no index for a release without a label.torchaudio<=2.14.0beside torch2.14.0+cu130. It names the PyTorch index of that torch, when it has one, with--index-urland is sent once.--dry-runbefore it is sent: as it is, then from uv's cache alone (--offline), then from the cache without the PyTorch index. The first form that resolves is sent, once. When none resolves, the command is sent as it is, once.Failed to restore PyTorchand the command, and no other build is installed in place of the one from before.cuda-bindings,cuda-pathfinderandcuda-toolkitwithCache-Control: no-store, so uv keeps none of them. Outside what the restore guarantees are therefore, while the PyTorch index is not reached: a development build that was installed from there, a torch for CUDA 13 from there whosecuda-bindings,cuda-pathfinderorcuda-toolkitthe nodepack changed, a torch that pip installed, a cache that was emptied or that another version of uv wrote, and an install whose only reachable index is a mirror and whose cache cannot give the build. In that last case a command without the PyTorch index installs the build from the mirror; the restore does not send it. The restore then logs a warning and the error, and changes nothing more.--offlinecommand, in a configuration in which the one command of the base failed at the index and changed nothing.2.11.0+cu126beside2.14.0+cu130, and2.11.0from PyPI beside2.14.0+cpu, with pip and with uv. The base leaves the same torchaudio. The restore does not replace it by its local label. That was built and measured: where an index of the user is read before or beside the--index-urlof the command (UV_DEFAULT_INDEX,UV_EXTRA_INDEX_URL,PIP_EXTRA_INDEX_URL), it replaced a torchaudio that worked by one that does not import, in 6 configurations. By the same order of indexes, a torchaudio that the last command does install can come from an index of the user.cuda-bindings13.5.0 where 13.4.4 was).cm-clishows no line at info level, as before. A restore from the cache shows uv's install output and no line of Manager. A restore that failed shows the warning and the errors..dist-info, pip answersRequirement already satisfiedand installs nothing, with no error. The base does the same.cm-cli installof two nodepacks gives the restore after the second one the package list from before the first restore as the state of before, becauseget_installed_packages()returns its cached list. That restore installs the first nodepack's torch again, and the last check ofcm-cliputs the build of before back. The base reads the same cached list. Not changed here.maingets the same change in Restore the PyTorch builds that were installed before a nodepack #3617.Changes
torch_rollback()gets what was installed before and after the nodepack in place of the previous torch version, and installs each changed package as===its build from the index of that build. The version table is removed. Module:comfyui_manager/common/manager_util.py.fix_broken()readnew_pip_versions['torch'], which raisedKeyErrorfor a removed package. Module:comfyui_manager/common/manager_util.py.--dry-run, which installs nothing and whose output is not shown. Module:comfyui_manager/common/manager_util.py.tests/test_torch_rollback.py: 143 cases, 16 before. They runfix_broken()and check the dry runs and the install commands it sends, in order, and the lines it logs.CHANGELOG.md: one bullet underUnreleased,Fixed.Verification
Real ComfyUI. A disposable ComfyUI instance, ComfyUI master started with
--cpu --enable-manager, each commit installed as the Manager package of a Python 3.13.12 venv that has uv 0.13.10 and no pip. Start states of the venv, each put back before a journey: A1 torch 2.11.0+cpu and torchvision 0.26.0+cpu; B6 A1 with torchaudio 2.10.0+cpu; A1m A1 installed through a mirror set inUV_EXTRA_INDEX_URL. The nodepacks are local git repositories whose install script changes PyTorch. Each journey ran throughcm-cliand through the server (the install queued, then the restart that carries it out): 31 journeys.Real CUDA installs. The
fix_broken()of each tree, driven with real pip 26.3 and uv 0.13.9 on copies of kept venvs (Python 3.12.3), among them C0, torch 2.14.0+cu130 and torchvision 0.29.0+cu130: 98 runs, 55 of the head. After each run:pip freeze, an import of torch,torchvision.ops.nms,torchaudio.functional.lowpass_biquad, and the hash of every recorded file of torch and its requirements. No GPU computation.Script. The
fix_broken()of the base and head trees of both lines withsubprocessreplaced, nothing installed: 200,688 pairs of an input and a plan of which forms resolve and which install command fails.a1b02647409a29ba04cm-cliand serverFailed to restore PyTorchfrom aKeyError. torchvision stays removed, and ComfyUI does not come up after the restartuv pip install --no-deps torchvision===0.26.0+cpu --extra-index-url https://download.pytorch.org/whl/cpu, after the info linerestore PyTorch: torchvision 0.26.0+cpu. The builds of before, ComfyUI comes upcm-cliand server--pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu. The nodepack's torch 2.14.0+cpu stays, beside a nightly torchvision 0.30.0.devtorch===2.11.0+cpu --extra-index-url https://download.pytorch.org/whl/cpu. The builds of beforecm-cliand server--no-deps torchvision===0.26.0+cpu --extra-index-url …, each after its dry run. The builds of before--no-deps --force-reinstallof cuDNN, cuSPARSELt, NCCL and NVSHMEM. The builds of before, torch imports, 0 recorded files with another hashcm-cliand server--no-deps torchaudio===2.10.0+cpu --extra-index-url …. The builds of before, torch not moved, all three workcm-cliand servertorch===2.11.0+cpu torchaudio<=2.11.0 --index-url https://download.pytorch.org/whl/cpuwith no dry run. torchaudio 2.11.0+cpu, all three workcm-cliand servertorchvision.ops.nmsfails--offlineresolves, the--offlinecommand is sent once. The builds of before. The server log has the two info lines and nothing at warning level; the screen ofcm-clishows uv's install output and noerror:UV_EXTRA_INDEX_URLcm-cliand servertorch===2.11.0+cpu --offlineis sent once. The builds of beforecm-cliand servererror: Request failed, the warningno dry run of the command resolved, …, thenFailed to restore PyTorchwith the command--offlineformmaincounterpart, and base against baseOver the 55 real CUDA runs of the head: 67 dry runs, none changed a file of site-packages. In the 28 runs in which every install command completed, nothing is logged at warning level. Each of the 27 runs that a failed command ended has
Failed to restore PyTorchwith the command.Results
09a29ba04onmanager-v4a1b026474. The real runs usede00ee78c4, which differs from the head inCHANGELOG.mdand the commit message alone. Linux x86_64; Python 3.12.3 for the unit suite.testswithouttests/e2eandtests/playwright): 4243 passed, 17 skipped. Ona1b026474: 4116 passed, 17 skipped. The 127 more are the test file: 143 cases where the base has 16.tests/test_torch_rollback.pywith the product code ofa1b026474: 139 of 143 fail. The 4 that pass are the cases about an install without torchaudio, which the base already does.except subprocess.CalledProcessErroraround a dry run widened toexcept Exception.fix_broken()are unchanged and pass.ruff check .passes.network_mode = offline), a ComfyUI instance whose venv has pip, the legacy UI, GPU computation, Windows, macOS. uv versions before 0.13.9 were measured on themaincounterpart.Commands