Commit Graph

35 Commits

Author SHA1 Message Date
f16053f0c9 Switch to standard pep517 sdist generation (#152098)
Generate source tarball with PEP 517 conform build tools instead of the custom routine in place right now.

Closes #150461.

The current procedure for generating the source tarball consists in creation of a source tree by manual copying and pruning of source files.

This PR replaces that with a call to the standard [build tool](https://build.pypa.io/en/stable/), which works with the build backend to produce an sdist. For that to work correctly, the build backend also needs to be configured. In the case of Pytorch, the backend currently is (the legacy version of) the setuptools backend, the source dist part of which is mostly configured via the `MANIFEST.in` file.

The resulting source distribution can be used to install directly from source with `pip install ./torch-{version}.tar.gz` or to build wheels directly from source with `pip wheel ./torch-{version}.tar.gz`; both should be considered experimental for now.

## Issues

### sdist name
According to PEP 517, the name of the source distribution file must coincide with the project name, or [more precisely](https://peps.python.org/pep-0517/#source-distributions), the source distribution of a project that generates `{NAME}-{...}.whl` wheels are required to be named `{NAME}-{...}.tar.gz`. Currently, the source tarball is called `pytorch-{...}.tar.gz`, but the generated wheels and python package are called `torch-{...}`.

### Symbolic Links
The source tree at the moment contains a small number of symbolic links. This [has been seen as problematic](https://github.com/pypa/pip/issues/5919) largely because of lack of support on Windows, but also because of [a problem in setuptools](https://github.com/pypa/setuptools/issues/4937). Particularly unfortunate is a circular symlink in the third party `ittapi` module, which can not be resolved by replacing it with a copy.

PEP 721 (now integrated in the [Source Distribution Format Specification](https://packaging.python.org/en/latest/specifications/source-distribution-format/#source-distribution-archive-features)) allows for symbolic links, but only if they don't point outside the destination directory and if they don't contain `../` in their target.

The list of symbolic links currently is as follows:

<details>

|source|target|problem|solution|
|-|-|-|-|
| `.dockerignore` | `.gitignore` |  ok (individual file) ||
| `docs/requirements.txt` | `../.ci/docker/requirements-docs.txt` |`..` in target|swap source and target[^1]|
| `functorch/docs/source/notebooks` | `../../notebooks/` |`..` in target|swap source and target[^1]|
| `.github/ci_commit_pins/triton.txt` | `../../.ci/docker/ci_commit_pins/triton.txt` |  ok (omitted from sdist)||
| `third_party/flatbuffers/docs/source/CONTRIBUTING.md` | `../../CONTRIBUTING.md` |`..` in target|omit from sdist[^2]|
| `third_party/flatbuffers/java/src/test/java/DictionaryLookup` | `../../../../tests/DictionaryLookup` |`..` in target|omit from sdist[^3]|
| `third_party/flatbuffers/java/src/test/java/MyGame` | `../../../../tests/MyGame` |`..` in target|omit from sdist[^3]|
| `third_party/flatbuffers/java/src/test/java/NamespaceA` | `../../../../tests/namespace_test/NamespaceA` |`..` in target|omit from sdist[^3]|
| `third_party/flatbuffers/java/src/test/java/NamespaceC` | `../../../../tests/namespace_test/NamespaceC` |`..` in target|omit from sdist[^3]|
| `third_party/flatbuffers/java/src/test/java/optional_scalars` | `../../../../tests/optional_scalars` |`..` in target|omit from sdist[^3]|
| `third_party/flatbuffers/java/src/test/java/union_vector` | `../../../../tests/union_vector` |`..` in target|omit from sdist[^3]|
| `third_party/flatbuffers/kotlin/benchmark/src/jvmMain/java` | `../../../../java/src/main/java` |`..` in target|omit from sdist[^3]|
| `third_party/ittapi/rust/ittapi-sys/c-library` | `../../` |`..` in target|omit from sdist[^4]|
| `third_party/ittapi/rust/ittapi-sys/LICENSES` | `../../LICENSES` |`..` in target|omit from sdist[^4]|
| `third_party/opentelemetry-cpp/buildscripts/pre-merge-commit` | `./pre-commit` | ok (individual file)||
| `third_party/opentelemetry-cpp/third_party/prometheus-cpp/cmake/project-import-cmake/sample_client.cc` | `../../push/tests/integration/sample_client.cc` |`..` in target|omit from sdist[^5]|
| `third_party/opentelemetry-cpp/third_party/prometheus-cpp/cmake/project-import-cmake/sample_server.cc` | `../../pull/tests/integration/sample_server.cc` |`..` in target|omit from sdist[^5]|
| `third_party/opentelemetry-cpp/third_party/prometheus-cpp/cmake/project-import-pkgconfig/sample_client.cc` | `../../push/tests/integration/sample_client.cc` |`..` in target|omit from sdist[^5]|
| `third_party/opentelemetry-cpp/third_party/prometheus-cpp/cmake/project-import-pkgconfig/sample_server.cc` | `../../pull/tests/integration/sample_server.cc` |`..` in target|omit from sdist[^5]|
| `third_party/XNNPACK/tools/xngen` | `xngen.py` |  ok (individual file)||

</details>

The introduction of symbolic links inside the `.ci/docker` folder creates a new problem, however, because Docker's `COPY` command does not allow symlinks in this way. We work around that by using `tar ch` to dereference the symlinks before handing them over to `docker build`.

[^1]: These resources can be naturally considered to be part of the docs, so moving the actual files into the place of the current symlinks and replacing them with (unproblematic) symlinks can be said to improve semantics as well.

[^2]: The flatbuffers docs already actually use the original file, not the symlink and in the most recent releases, starting from flatbuffers-25.1.21 the symlink is replaced by the actual file thanks to a documentation overhaul.

[^3]: These resources are flatbuffers tests for java and kotlin and can be omitted from our sdist.

[^4]: We don't need to ship the rust bindings for ittapi.

[^5]: These are demonstration examples for how to link to prometheus-cpp using cmake and can be omitted.

### Nccl
Nccl used to be included as a submodule. However, with #146073 (first released in v2.7.0-rc1), the submodule was removed and replaced with a build time checkout procedure in `tools/build_pytorch_libs.py`, which checks out the required version of nccl from the upstream repository based on a commit pin recorded in `.ci/docker/ci_commit_pins/nccl-cu{11,12}.txt`.
This means that a crucial third party dependency is missing from the source distribution and as the `.ci` folder is omitted from the source distribution, it is not possible to use the build time download.
However, it *is* possible to use a system provided Nccl using the `USE_SYSTEM_NCCL` environment variable, which now also is the default for the official Pytorch wheels.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/152098
Approved by: https://github.com/atalman
2025-06-30 19:07:34 +00:00
e3507c3777 [BE] fix typos in functorch/ and scripts/ (#156081)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/156081
Approved by: https://github.com/albanD
ghstack dependencies: #156080
2025-06-21 02:47:40 +00:00
267f82b860 [BE] Format .ci/ / .github/ / benchmarks/ / functorch/ / tools/ / torchgen/ with ruff format (#132577)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/132577
Approved by: https://github.com/malfet
2024-10-11 18:30:26 +00:00
fd4b649e6c [BE]: Simplify some list comps to generators C419 (#132578)
Simplifies some list comprehensions to generator which is more efficient. Automatically applied diffs for the most part with ruff

Pull Request resolved: https://github.com/pytorch/pytorch/pull/132578
Approved by: https://github.com/ezyang
2024-08-04 17:46:26 +00:00
740fb22966 [BE][Easy][4/19] enforce style for empty lines in import segments in functorch/ (#129755)
See https://github.com/pytorch/pytorch/pull/129751#issue-2380881501. Most changes are auto-generated by linter.

You can review these PRs via:

```bash
git diff --ignore-all-space --ignore-blank-lines HEAD~1
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/129755
Approved by: https://github.com/zou3519
ghstack dependencies: #129752
2024-07-18 05:08:03 +00:00
e8005781be Softmax in functorch example fixed (#107988)
The output of softmax was overwritten by the output of fc2 in the following line. So, the output of the softmax is never utilized. Now, the final output of the model includes softmax.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/107988
Approved by: https://github.com/zou3519
2023-09-05 17:18:48 +00:00
02abbb8109 Fix some typos, mostly "that that" (#106901)
Fix some typos
Pull Request resolved: https://github.com/pytorch/pytorch/pull/106901
Approved by: https://github.com/janeyx99
2023-08-10 19:46:53 +00:00
e6ec0efaf8 Apply UFMT to all non test/torch files (#106205)
Signed-off-by: Edward Z. Yang <ezyang@meta.com>

Pull Request resolved: https://github.com/pytorch/pytorch/pull/106205
Approved by: https://github.com/albanD
2023-07-29 02:56:24 +00:00
5b1cedacde [BE] [2/3] Rewrite super() calls in functorch and torch (#94588)
Rewrite Python built-in class `super()` calls. Only non-semantic changes should be applied.

- #94587
- #94588
- #94592

Also, methods with only a `super()` call are removed:

```diff
class MyModule(nn.Module):
-   def __init__(self):
-       super().__init__()
-
    def forward(self, ...):
        ...
```

Some cases that change the semantics should be kept unchanged. E.g.:

f152a79be9/caffe2/python/net_printer.py (L184-L190)

f152a79be9/test/test_jit_fuser_te.py (L2628-L2635)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/94588
Approved by: https://github.com/ezyang, https://github.com/albanD
2023-02-10 21:16:33 +00:00
13ab819356 [functorch] fix AOTAutograd tutorial (#87415)
It was raising asserts previously
Pull Request resolved: https://github.com/pytorch/pytorch/pull/87415
Approved by: https://github.com/Chillee
2022-10-21 01:53:24 +00:00
eed5f0464c [functorch] fix whirlwind tour ipynb (#85974)
It was missing an "import torch"
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85974
Approved by: https://github.com/samdow
2022-09-30 20:42:32 +00:00
19c7a6b54b [functorch] Update notebooks for latest release (#85855)
This PR:
- dedups our colab notebooks with the regular functorch notebooks. The
colab notebooks were versions of the reuglar notebooks that had
install instructions. Now that functorch is easier to install, we do not
need those anymore.
- fixes the colab links

Test Plan:
- build docs locally and tested them
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85855
Approved by: https://github.com/samdow
2022-09-29 20:00:34 +00:00
0e256c2550 removed compile cache and static argnums (#85783)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85783
Approved by: https://github.com/wconstab
2022-09-28 08:33:59 +00:00
85931eaa6b Rename fake_result to val (#84331)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/84331
Approved by: https://github.com/ezyang
2022-08-31 17:44:18 +00:00
62d9f1559e Fix model type CNN->MLP in functorch ensembling notebook intro (#83603)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/83603
Approved by: https://github.com/albanD, https://github.com/zou3519
2022-08-22 21:42:37 +00:00
a0b3854548 Change seperate -> separate (#83056)
One instance was caught by Meta-internal "exact-word-misspell" linter in D38505529.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/83056
Approved by: https://github.com/huydhn, https://github.com/seemethere
2022-08-09 23:11:34 +00:00
f42ed3f98f Turn on linting for functorch (#81987)
Test Plan:
- wait for CI
Pull Request resolved: https://github.com/pytorch/pytorch/pull/81987
Approved by: https://github.com/samdow
2022-07-25 14:36:22 +00:00
5cb802a63b Delete some no-longer-neccessary debugging output (#81990)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/81990
Approved by: https://github.com/Chillee
2022-07-25 14:36:21 +00:00
c58932ea79 [functorch] Fix link for colab (pytorch/functorch#929)
Fix link to point to correct colab for ensembling example
2022-07-21 13:41:37 -07:00
e642a34627 [functorch] Add complexities and references for NTK implementations. (pytorch/functorch#907)
* Add complexities and references for NTK implementations.

* Fix result names; rename "outer product" -> "matrix product".

* Fix names
2022-07-21 13:41:36 -07:00
ff9558a2ea [functorch] Update neural_tangent_kernels.ipynb (pytorch/functorch#788)
Fix a small bug
```python3
    if compute == 'full':
        return result
    if compute == 'trace':
        return torch.einsum('NMKK->NM')        # should be torch.einsum('NMKK->NM', result)
    if compute == 'diagonal':
        return torch.einsum('NMKK->NMK')        # should be torch.einsum('NMKK->NMK', result)
```
2022-07-21 13:41:33 -07:00
b2f03d7f7d [functorch] Better intro to functorch (pytorch/functorch#688)
For our docs landing page.

Fixes https://github.com/pytorch/functorch/issues/605
2022-07-21 13:41:29 -07:00
5472f5ebfd [functorch] made some minor updates to the notebook 2022-07-21 13:41:28 -07:00
408b6c14a5 [functorch] Revmoed operator authoring 2022-07-21 13:41:27 -07:00
aab0785d6b [functorch] [skip ci] Fix typo in notebook name (pytorch/functorch#549) 2022-07-21 13:41:26 -07:00
ee61e3cc76 [functorch] Added minifier example notebook 2022-07-21 13:41:26 -07:00
8abfc81705 [functorch] Update colab install instructions (pytorch/functorch#590) 2022-07-21 13:41:26 -07:00
664cd284c5 [functorch] Docs website modification (pytorch/functorch#563)
I modified the docs website:
- It has a new install page which we'll fill out l ater
- It has a new "whirlwind tour" section with is just our README
copy-pasted
- It has a "UX Limitations" section describing arbitrary python
mutation, in-place operations, and control flow.

Please let me know if you think anything else should be here.

Future work:
- I'm going to put up a table of what operators we have support for and
which ones we don't, autogenerated via OpInfo
2022-07-21 13:41:25 -07:00
3110183992 [functorch] Neural Tangent Kernels tutorial (pytorch/functorch#540) 2022-07-21 13:41:25 -07:00
9ae520640e [functorch] Update ensembling and per-sample-grad example (pytorch/functorch#556) 2022-07-21 13:41:24 -07:00
ea1e2906cc [functorch] Synchronize jacobians_hessians tutorial (pytorch/functorch#555) 2022-07-21 13:41:24 -07:00
3adc8167c9 [functorch] Updated css to reduce badge size and code-block bottom padding (pytorch/functorch#526)
* Updated css to reduce badge size and code-block bottom padding

* [skip ci] Added new line
2022-07-21 13:41:23 -07:00
cfe8ff227f [functorch] Colab ready tutorials (3 total) with updated colab badge links (pytorch/functorch#519)
* Create readme.md

* colab version, jacobians hessians tutorial

* per sample gradients tutorial in colab

* colab ready tutorial, ensembling

* add colab badge and link to colab ready tutorial

* Delete ensembling_colab.ipynb

* add colab badge and link to colab ready version

* add colab badge and link to colab ready tutorial

* add colab badge and link to colab ready tutorial, add meta-learning mention as addtl use case
2022-07-21 13:41:23 -07:00
1a748aeadc [functorch] Aot Autograd tutorial (pytorch/functorch#476) 2022-07-21 13:41:23 -07:00
fd4d82ee0d [functorch] quick cleanup 2022-07-21 13:41:17 -07:00