Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying different dependency versions for different platforms #9515

Closed
merajhashemi opened this issue Nov 29, 2024 · 4 comments
Closed

Specifying different dependency versions for different platforms #9515

merajhashemi opened this issue Nov 29, 2024 · 4 comments
Labels
question Asking for clarification or support

Comments

@merajhashemi
Copy link

Hello,
I've encountered an issue while trying to specify different versions of PyTorch for Intel macOS in my project.
Here is a minimal pyproject.toml that shows the issue:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "test"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
    "torch>=1.13.1,<2.3; sys_platform == 'darwin' and platform_machine == 'x86_64'",
    "torch>=1.13.1; sys_platform != 'darwin' or platform_machine == 'arm64'",
]

I’m trying to make sure that Intel macOS (darwin_x86_64) uses a specific version of PyTorch as there are no new wheels available for versions 2.3 and above. But the dependency resolver seems to apply this constraint universally when generating the lock file, resulting in version 2.2.2 being installed across all platforms.

Is there a better way to set these conditions, maybe in a tool.uv section? Any tips would be super helpful!


$ uv --version
uv 0.5.5

Related to #8358.

@charliermarsh
Copy link
Member

I'd probably suggest something like this:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "test"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
    "torch>=<2.3; sys_platform == 'darwin' and platform_machine == 'x86_64'",
    "torch>=2.3; sys_platform != 'darwin' or platform_machine != 'x86_64'",
]

@charliermarsh charliermarsh added the question Asking for clarification or support label Nov 29, 2024
@merajhashemi
Copy link
Author

Thanks @charliermarsh.
This seems to work as expected:

dependencies = [
    "torch>1.13,<2.3; sys_platform == 'darwin' and platform_machine == 'x86_64'",
    "torch>=2.3; sys_platform != 'darwin' or platform_machine != 'x86_64'",
]

However, our library is designed to support PyTorch versions greater than 1.13 across all platforms. When we specify the dependencies as follows:

dependencies = [
    "torch>1.13,<2.3; sys_platform == 'darwin' and platform_machine == 'x86_64'",
    "torch>=1.13; sys_platform != 'darwin' or platform_machine != 'x86_64'",
]

it still results in all platforms installing version 2.2.2.

@charliermarsh
Copy link
Member

Yeah, that's intended. If you provide constraints that can be solved with fewer total versions, uv will prefer to use fewer versions. In that case, 2.2.2 satisfies both of your constraints, so uv chooses 2.2.2 rather than creating a more heterogenous environment (i.e., an environment that's less consistent across platforms).

If you're looking for a change in that behavior, follow #8686 and #7190. But uv is doing the intended thing given those constraints.

@merajhashemi
Copy link
Author

merajhashemi commented Nov 29, 2024

Thank you, @charliermarsh. I've just noticed that this behavior doesn't align with the pip interface. When I execute uv pip install . with the following dependencies:

dependencies = [
    "torch>1.13,<2.3; sys_platform == 'darwin' and platform_machine == 'x86_64'",
    "torch>=1.13; sys_platform != 'darwin' or platform_machine != 'x86_64'",
]

it successfully installs the latest version of PyTorch on linux. Could we have other uv commands, such as uv sync and uv lock, behave similarly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for clarification or support
Projects
None yet
Development

No branches or pull requests

2 participants