Skip to content

Add a project section to pyproject.toml, making uv sync work#153020

Closed
ezyang wants to merge 2 commits intogh/ezyang/3069/basefrom
gh/ezyang/3069/head
Closed

Add a project section to pyproject.toml, making uv sync work#153020
ezyang wants to merge 2 commits intogh/ezyang/3069/basefrom
gh/ezyang/3069/head

Conversation

@ezyang
Copy link
Copy Markdown
Contributor

@ezyang ezyang commented May 7, 2025

Stack from ghstack (oldest at bottom):

With this change, I can now run uv sync -v and get all dependencies I need and then trigger build of PyTorch. (The -v is good because the build takes a long time and uv hides progress by default.)

Signed-off-by: Edward Z. Yang ezyang@mit.edu

[ghstack-poisoned]
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 7, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/153020

Note: Links to docs will display an error until the docs builds have been completed.

❌ 11 New Failures

As of commit 90a6b77 with merge base 08f5371 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

ezyang added a commit that referenced this pull request May 7, 2025
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
ghstack-source-id: 0195a7d
Pull-Request-resolved: #153020
@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label May 7, 2025
@cyyever
Copy link
Copy Markdown
Collaborator

cyyever commented May 7, 2025

After moving dependencies to pyproject.toml, we should remove requirements.txt. Possibly fix all commands to use pyproject.toml?

@ezyang
Copy link
Copy Markdown
Contributor Author

ezyang commented May 7, 2025

@cyyever It's going to be more work to dump requirements.txt because unfortunately I'm guessing people are depending on it somehow...

Copy link
Copy Markdown
Collaborator

@cyyever cyyever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@cyyever
Copy link
Copy Markdown
Collaborator

cyyever commented May 7, 2025

Let me propose a PR later for moving.

Comment thread pyproject.toml
version = "2.8.0a0"
description = "Tensors and Dynamic neural networks in Python with strong GPU acceleration"
readme = "README.md"
requires-python = ">=3.9"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if we update ruff we can now remove the ruff specific Python min version, which is nice.

Comment thread pyproject.toml Outdated
@@ -1,3 +1,34 @@
[project]
name = "torch"
version = "2.8.0a0"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, I wish there was a way to automatically infer the version

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version = "2.8.0a0"
dynamic = ["version"]

Make the build backend responsible for it.

Comment thread pyproject.toml Outdated
readme = "README.md"
requires-python = ">=3.9"
license = {text = "BSD"}
dependencies = [
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds another place to maintain the dependencies and make sure they all stay in sync...

Comment thread pyproject.toml Outdated
"pyyaml",
"requests",
# issue on Windows after >=75.8.2 – https://github.com/pytorch/pytorch/issues/148877
"setuptools>=62.3.0,<75.9",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we sill not have a fix for the setuptools stuff? This is going to hurt Python 3.14 since it won't support setuptools that old, won't it?

@ezyang
Copy link
Copy Markdown
Contributor Author

ezyang commented May 7, 2025

CI fails seems to be real.

2025-05-07T02:37:08.5156974Z + [[ 2.8.0a0 != *\+\g\i\t* ]]
2025-05-07T02:37:08.5157435Z + echo 'Unexpected torch version. Expected binary built from source, got 2.8.0a0'
2025-05-07T02:37:08.5158053Z Unexpected torch version. Expected binary built from source, got 2.8.0a0

We need to somehow have a +git version from pyproject.toml

2025-05-07T03:31:52.0284715Z ____________________ TestImports.test_circular_dependencies ____________________
2025-05-07T03:31:52.0285562Z Traceback (most recent call last):
2025-05-07T03:31:52.0286820Z   File "/var/lib/jenkins/workspace/test/test_testing.py", line 2383, in torch_dynamo_resume_in_test_circular_dependencies_at_2371
2025-05-07T03:31:52.0288297Z     mod = importlib.import_module(mod_name)
2025-05-07T03:31:52.0289163Z   File "/opt/conda/envs/py_3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
2025-05-07T03:31:52.0290147Z     return _bootstrap._gcd_import(name[level:], package, level)
2025-05-07T03:31:52.0291047Z   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
2025-05-07T03:31:52.0291855Z   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
2025-05-07T03:31:52.0292839Z   File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
2025-05-07T03:31:52.0293777Z   File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
2025-05-07T03:31:52.0294699Z   File "<frozen importlib._bootstrap_external>", line 850, in exec_module
2025-05-07T03:31:52.0295754Z   File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
2025-05-07T03:31:52.0297442Z   File "/opt/conda/envs/py_3.9/lib/python3.9/site-packages/torch/ao/quantization/experimental/fake_quantize.py", line 8, in <module>
2025-05-07T03:31:52.0298946Z     from torch.ao.quantization.experimental.observer import APoTObserver
2025-05-07T03:31:52.0300404Z   File "/opt/conda/envs/py_3.9/lib/python3.9/site-packages/torch/ao/quantization/experimental/observer.py", line 9, in <module>
2025-05-07T03:31:52.0301763Z     import matplotlib.pyplot as plt
2025-05-07T03:31:52.0302391Z ModuleNotFoundError: No module named 'matplotlib'
2025-05-07T03:31:52.0302879Z 
2025-05-07T03:31:52.0303260Z The above exception was the direct cause of the following exception:
2025-05-07T03:31:52.0303851Z 
2025-05-07T03:31:52.0304055Z Traceback (most recent call last):
2025-05-07T03:31:52.0304984Z   File "/var/lib/jenkins/workspace/test/test_testing.py", line 2371, in test_circular_dependencies
2025-05-07T03:31:52.0306049Z     for base, _, files in os.walk(torch_dir):
2025-05-07T03:31:52.0307237Z   File "/var/lib/jenkins/workspace/test/test_testing.py", line 2385, in torch_dynamo_resume_in_test_circular_dependencies_at_2371
2025-05-07T03:31:52.0308721Z     raise RuntimeError(f"Failed to import {mod_name}: {e}") from e
2025-05-07T03:31:52.0309994Z RuntimeError: Failed to import torch.ao.quantization.experimental.fake_quantize: No module named 'matplotlib'
2025-05-07T03:31:52.0310901Z 
2025-05-07T03:31:52.0311251Z To execute this test, run the following from the base repo dir:
2025-05-07T03:31:52.0312402Z     PYTORCH_TEST_WITH_DYNAMO=1 python test/test_testing.py TestImports.test_circular_dependencies
2025-05-07T03:31:52.0313258Z 
2025-05-07T03:31:52.0313694Z This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0

Not sure how matplotlib was showing up before, but it's no longer showing up with uv.

@Skylion007
Copy link
Copy Markdown
Collaborator

@ezyang Use https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata to dynamically fetch the requirements.txt dependencies and the version metadata. 👍

Comment thread pyproject.toml Outdated
Comment thread pyproject.toml
readme = "README.md"
requires-python = ">=3.9"
license = {text = "BSD"}
dynamic = ["version", "dependencies"]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dynamic = ["version", "dependencies"]
dynamic = [
"version",
"dependencies",
"optional-dependencies",
"readme",
"description",
]

Comment thread pyproject.toml
description = "Tensors and Dynamic neural networks in Python with strong GPU acceleration"
readme = "README.md"
requires-python = ">=3.9"
license = {text = "BSD"}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use pure BSD? Or BSD-like? Does it matter? haha

@Skylion007
Copy link
Copy Markdown
Collaborator

#153055 Unblocks uv sync support at least (tested it and works great), and shows us what we need to do migrate to more declarative pyproject.toml metadata

Copy link
Copy Markdown
Collaborator

@Skylion007 Skylion007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better populated the fields using #153055

@Skylion007 Skylion007 closed this May 8, 2025
pytorchmergebot pushed a commit that referenced this pull request May 8, 2025
Follow up to @ezyang's PR #153020 , but better uses PEP621 to reduce redundant fields and pass through metadata better to uv, setuptools, poetry and other tooling.

* Enables modern tooling like uv sync and better support for tools like poetry.
* Also allows us to set project wide settings that are respected by linters and IDE (in this example we are able centralize the minimum supported python version).
* Currently most of the values are dynamically fetched from setuptools, eventually we can migrate all the statically defined values to pyproject.toml and they will be autopopulated in the setuptool arguments.
* This controls what additional metadata shows up on PyPi . Special URL Names are listed here for rendering on pypi: https://packaging.python.org/en/latest/specifications/well-known-project-urls/#well-known-labels

These also clearly shows us what fields will need to be migrated to pyproject.toml over time from setup.py per #152276. Static fields be fairly easy to migrate, the dynamically built ones like requirements are a bit more challenging.

Without this, `uv sync` complains:
```
error: No `project` table found in: `pytorch/pyproject.toml`
```
Pull Request resolved: #153055
Approved by: https://github.com/ezyang
pytorchmergebot pushed a commit that referenced this pull request May 10, 2025
Unblocks #153020 which accidentally improves the CircularImportLinter to check all Python files. It doesn't set a logname so it errors, there is another FSDP script which already defaults LOGNAME to '' if not specified, this does the same.

Pull Request resolved: #153324
Approved by: https://github.com/awgu
pytorchmergebot pushed a commit that referenced this pull request May 11, 2025
Fixes unnecessary import for torch script. Unblocks #153020 as it appears to fix circular importer linter into importing every Python file under torch

Pull Request resolved: #153323
Approved by: https://github.com/ngimel, https://github.com/cyyever
pytorchmergebot pushed a commit that referenced this pull request May 12, 2025
Follow up to @ezyang's PR #153020 , but better uses PEP621 to reduce redundant fields and pass through metadata better to uv, setuptools, poetry and other tooling.

* Enables modern tooling like uv sync and better support for tools like poetry.
* Also allows us to set project wide settings that are respected by linters and IDE (in this example we are able centralize the minimum supported python version).
* Currently most of the values are dynamically fetched from setuptools, eventually we can migrate all the statically defined values to pyproject.toml and they will be autopopulated in the setuptool arguments.
* This controls what additional metadata shows up on PyPi . Special URL Names are listed here for rendering on pypi: https://packaging.python.org/en/latest/specifications/well-known-project-urls/#well-known-labels

These also clearly shows us what fields will need to be migrated to pyproject.toml over time from setup.py per #152276. Static fields be fairly easy to migrate, the dynamically built ones like requirements are a bit more challenging.

Without this, `uv sync` complains:
```
error: No `project` table found in: `pytorch/pyproject.toml`
```

Pull Request resolved: #153055
Approved by: https://github.com/ezyang
@github-actions github-actions Bot deleted the gh/ezyang/3069/head branch June 17, 2025 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants