Skip to content

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Aug 16, 2025

Summary

There's a lot here (maybe it should go somewhere else?), but this is a complex topic and I wanted to include a lot of copy-pasteable examples for common cases.

Closes #10694.
Closes #13959.
Closes #15248.
Closes #15316.

@charliermarsh charliermarsh added the documentation Improvements or additions to documentation label Aug 16, 2025
@charliermarsh charliermarsh requested a review from zanieb August 16, 2025 16:07
@charliermarsh charliermarsh marked this pull request as ready for review August 16, 2025 16:07
Copy link

@vwxyzjn vwxyzjn left a comment

Choose a reason for hiding this comment

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

Love the examples! The flash attention one doesn't work, but I tested deep_ep and deep_gemm which all works!

Comment on lines 283 to 296
```toml title="pyproject.toml"
[project]
name = "project"
version = "0.1.0"
description = "..."
readme = "README.md"
requires-python = ">=3.12"
dependencies = ["flash-attn", "torch"]

```console
$ uv sync --extra compile
+ cchardet==2.1.7
- cython==3.0.11
- setuptools==73.0.1
[tool.uv.extra-build-dependencies]
flash-attn = [{ dependencies = ["torch"], match-runtime = true }]

[tool.uv.extra-build-variables]
flash-attn = { FLASH_ATTENTION_SKIP_CUDA_BUILD = "TRUE" }
Copy link

Choose a reason for hiding this comment

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

This doesn't work:

ubuntu@costa-dev-worker-0:~/code/thirdparty/test_uv$ cat pyproject.toml
[project]
name = "project"
version = "0.1.0"
description = "..."
readme = "README.md"
requires-python = ">=3.12"
dependencies = ["flash-attn", "torch"]

[tool.uv.extra-build-dependencies]
flash-attn = [{ dependencies = ["torch"], match-runtime = true }]

[tool.uv.extra-build-variables]
flash-attn = { FLASH_ATTENTION_SKIP_CUDA_BUILD = "TRUE" }
ubuntu@costa-dev-worker-0:~/code/thirdparty/test_uv$ uv sync
warning: Failed to parse `pyproject.toml` during settings discovery:
  TOML parse error at line 10, column 14
     |
  10 | flash-attn = [{ dependencies = ["torch"], match-runtime = true }]
     |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  data did not match any variant of untagged enum ExtraBuildDependencyWire

error: Failed to parse: `pyproject.toml`
  Caused by: TOML parse error at line 10, column 14
   |
10 | flash-attn = [{ dependencies = ["torch"], match-runtime = true }]
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
data did not match any variant of untagged enum ExtraBuildDependencyWire

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh thank you for trying this, there’s a typo 😩

@vwxyzjn
Copy link

vwxyzjn commented Aug 16, 2025

Copy link
Member

@zanieb zanieb left a comment

Choose a reason for hiding this comment

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

I have some minor edits and, as you said, we probably want to find a better home for all this content, but let's just get this in and iterate from there since it's so important.

@zanieb zanieb merged commit fa3c20a into main Aug 18, 2025
82 checks passed
@zanieb zanieb deleted the charlie/build-docs branch August 18, 2025 21:15
@tobiasdiez
Copy link

These are very nice improvements. Thanks a lot for everyone that worked on this!

Another use case of "no-build-isolation" of the main project is that some build backends (like python-meson) allow to recompile files on the fly in editable installs. For this to work, naturally the build dependencies of the main project need to be available also at runtime. (More details at #10694 (comment))
It's not clear to me if those recent changes cover this use case as well. One still needs to create an "extra" for the build dependencies, duplicating what is already in build-system.requires, and then use uv sync --extra build, right? Or is there a way to sync the build requirements of the main project without duplicating them to an extra?

@charliermarsh
Copy link
Member Author

Thanks @tobiasdiez! I can take a look and add some documentation for that. Can you give me a minimal pyproject.toml + a set of commands to reproduce, for testing?


You could run the following sequence of commands to sync `flash-attn`:
The use of `extra-build-dependencies` and `extra-build-variables` are tracked in the uv cache, such
that changes to these settings will not trigger a reinstall and rebuild of the affected packages.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a typo

Suggested change
that changes to these settings will not trigger a reinstall and rebuild of the affected packages.
that changes to these settings will trigger a reinstall and rebuild of the affected packages.

Copy link
Member Author

Choose a reason for hiding this comment

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

PR!!!

Copy link
Contributor

Choose a reason for hiding this comment

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

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Aug 21, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.8.11` -> `0.8.12` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>astral-sh/uv (astral-sh/uv)</summary>

### [`v0.8.12`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0812)

[Compare Source](astral-sh/uv@0.8.11...0.8.12)

##### Python

- Add 3.13.7
- Improve performance of zstd in Python 3.14

See the [python-build-standalone release notes](https://github.com/astral-sh/python-build-standalone/releases/tag/20250818) for details.

##### Enhancements

- Add an `aarch64-pc-windows-msvc` target for `python-platform` ([#&#8203;15347](astral-sh/uv#15347))
- Add fallback parent process detection to `uv tool update-shell` ([#&#8203;15356](astral-sh/uv#15356))
- Install non-build-isolation packages in a second phase ([#&#8203;15306](astral-sh/uv#15306))
- Add hint when virtual environments are included in source distributions ([#&#8203;15202](astral-sh/uv#15202))
- Add Docker images derived from `buildpack-deps:trixie`, `debian:trixie-slim`, `alpine:3.22` ([#&#8203;15351](astral-sh/uv#15351))

##### Bug fixes

- Reject already-installed wheels built with outdated settings ([#&#8203;15289](astral-sh/uv#15289))
- Skip interpreters that are not found on query ([#&#8203;15315](astral-sh/uv#15315))
- Handle dotted package names in script path resolution ([#&#8203;15300](astral-sh/uv#15300))
- Reject `match-runtime = true` for dynamic packages ([#&#8203;15292](astral-sh/uv#15292))

##### Documentation

- Document improvements to build-isolation setups ([#&#8203;15326](astral-sh/uv#15326))
- Fix reference documentation recommendation to use `uv cache clean` instead of `clear` ([#&#8203;15313](astral-sh/uv#15313))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS43Ni4wIiwidXBkYXRlZEluVmVyIjoiNDEuNzYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
installed in the project environment _prior_ to installing the package itself. This can be achieved
by separating out the build dependencies and the packages that require them into distinct extras.
For example:
To ensure that a build dependency matches the version of the package that is or will be installed in

Choose a reason for hiding this comment

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

Does this also ensure that the package annotated with match-runtime = true will only be built once? So in the example below (assuming that torch wouldn't ship wheels), would torch be built once as the build dependency of deepspeed and then another time to be installed in the main env? Or does uv cache the built of torch and reuses it?

I hope it is cached - in this case, match-runtime might be also a very useful option to set for packages that take a long time to build. I can open a PR to add this if wished.

@tobiasdiez
Copy link

tobiasdiez commented Sep 13, 2025

Thanks @tobiasdiez! I can take a look and add some documentation for that. Can you give me a minimal pyproject.toml + a set of commands to reproduce, for testing?

Sorry for taking so long to come back to you. Here is an example pyproject.toml that shows the problem:

[project]
name = "test"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []
[build-system]
build-backend = 'mesonpy'
requires = ["cython>=3.1.3", "meson-python>=0.18.0"]

This is just what you get with uv init plus adding the meson-python as a build backend. To run uv sync you also need a simple meson.build, say

project(
  'test',
  ['c', 'cpp', 'cython'],
  meson_version: '>=1.2',
)

py_module = import('python')
py = py_module.find_installation(pure: false)

py.install_sources(
  'main.py',
)

In a real application you would now actually use cython to compile an extension etc, but for the sake of having a simple example let's ignore that.

After uv sync the package is installed in editable mode, and in particular you have a file .venv\Lib\site-packages\_test_editable_loader.py which intercepts all imports and rebuilds the project if necessary. This means you need to have the build dependencies also installed at runtime. This is however not the case currently if you run uv sync.

Current workaround is:

uv pip install meson-python cython
uv sync --no-build-isolation

So it's similar to the problems discussed in this PR, but the difference is that the no-build-isolation concerns the main project and not one of its dependencies.

Let me know if this is sufficient to understand the problem, or if you would prefer to have a full example that actually compiles something etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
5 participants