Skip to content

fix: fall back to source build when version string is not PEP 440#961

Open
Chessing234 wants to merge 1 commit into
state-spaces:mainfrom
Chessing234:fix/wheel-url-invalid-version-fallback
Open

fix: fall back to source build when version string is not PEP 440#961
Chessing234 wants to merge 1 commit into
state-spaces:mainfrom
Chessing234:fix/wheel-url-invalid-version-fallback

Conversation

@Chessing234

Copy link
Copy Markdown
Contributor

Bug

CachedWheelsCommand.run() calls get_wheel_url() without catching InvalidVersion. In vendor PyTorch containers (e.g. NGC images with internal build IDs), torch.__version__ or torch.version.cuda can be a non-PEP-440 string such as gpgpu.<build-id>. packaging.version.parse raises InvalidVersion on those strings, which propagates uncaught and aborts the install entirely.

Reported in #947.

Root cause

# setup.py, CachedWheelsCommand.run()
wheel_url, wheel_filename = get_wheel_url()   # InvalidVersion escapes here
...
except urllib.error.HTTPError:
    # only catches HTTP failures, never reached
    super().run()

get_wheel_url() calls parse(torch.__version__) and parse(torch.version.cuda). Both raise InvalidVersion for non-standard version strings. The except urllib.error.HTTPError block that falls back to source build is never reached.

Fix

Import InvalidVersion from packaging.version and wrap get_wheel_url() in a try/except at the call site. When caught, fall back to super().run() (source build), consistent with how urllib.error.HTTPError is already handled.

try:
    wheel_url, wheel_filename = get_wheel_url()
except InvalidVersion:
    print("Non-PEP-440 version string detected. Building from source...")
    super().run()
    return

Why this fix is correct

The existing except urllib.error.HTTPError path already expresses the intent: if the prebuilt wheel cannot be obtained for any reason, fall back to a source build. InvalidVersion is another such reason. The fix keeps the same fallback behavior and does not change what wheels are downloaded or how they are built.

…wheel_url

packaging.version.parse raises InvalidVersion when torch.__version__ or
torch.version.cuda contains a vendor build string (e.g. 'gpgpu.<build-id>')
that does not conform to PEP 440. The exception propagated uncaught out of
get_wheel_url(), aborting the install entirely instead of falling back to a
source build. Catch InvalidVersion at the call site and invoke super().run()
so the build proceeds from source, consistent with the existing HTTPError path.
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