Skip to content

fix: use module attributes to detect vendor directly#44

Open
lalala-233 wants to merge 2 commits into
Comfy-Org:masterfrom
lalala-233:master
Open

fix: use module attributes to detect vendor directly#44
lalala-233 wants to merge 2 commits into
Comfy-Org:masterfrom
lalala-233:master

Conversation

@lalala-233
Copy link
Copy Markdown

Current vendor check relies on version.py's __version__:

def detect_vendor():
version = ""
try:
torch_spec = importlib.util.find_spec("torch")
for folder in torch_spec.submodule_search_locations:
ver_file = Path(folder) / "version.py"
if ver_file.is_file():
spec = importlib.util.spec_from_file_location("torch_version_import", ver_file)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
version = module.__version__
except Exception as e:
logging.warning("Failed to detect Torch version")
pass
if '+cu' in version:
return "cuda"
if '+rocm' in version:
return "rocm"
return None

However, in my PC, __version__ is 2.11.0 with no suffix, so this function returns None.

But..

#/usr/lib/python3.14/site-packages/torch/version.py
from typing import Optional

__all__ = ['__version__', 'debug', 'cuda', 'git_version', 'hip', 'rocm', 'xpu']
__version__ = '2.11.0'
debug = False
cuda: Optional[str] = '13.2'
git_version = '70d99e998b4955e0049d13a98d77ae1b14db1f45'
hip: Optional[str] = None
rocm: Optional[str] = None
xpu: Optional[str] = None

I can use cuda actually.

So I refactor detect_rendor to use module attributes directly.

But I haven't tested if it break anything in other's PC. It works well on my PC. Could someone help me test it?

Contribution Agreement

  • I agree that my contributions are licensed under the GPLv3.
  • I grant Comfy Org the rights to relicense these contributions as outlined in CONTRIBUTING.md.

@Apophis3158
Copy link
Copy Markdown
Contributor

detect_vendor uses the same method as ComfyUI's cuda_malloc.py:

It seems that torch naming rules were changed starting with CUDA 13.2? So this fix should be applied to ComfyUI side as well.

@lalala-233
Copy link
Copy Markdown
Author

lalala-233 commented May 6, 2026

I'm not sure if it is because I use Arch Linux. Arch Linux's official repo repackaged pytorch. I'm not sure if it brings this difference.

But I think using module attributes to directly detect vendor is not a bad idea :)

I'll create a PR to ComfyUI later.

@lalala-233
Copy link
Copy Markdown
Author

I found I repeated some useless code. I forgot to remove it after I copy it from my minimal test.

Now there is no problem, I hope :)

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.

2 participants