torch-named-linops 0.3.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- torch_named_linops-0.3.10/.github/workflows/test-python.yml +50 -0
- torch_named_linops-0.3.10/.gitignore +17 -0
- torch_named_linops-0.3.10/.gitmodules +0 -0
- torch_named_linops-0.3.10/.pre-commit-config.yaml +9 -0
- torch_named_linops-0.3.10/LICENSE.txt +202 -0
- torch_named_linops-0.3.10/PKG-INFO +71 -0
- torch_named_linops-0.3.10/README.md +51 -0
- torch_named_linops-0.3.10/dev/cuda_streams/.gitignore +12 -0
- torch_named_linops-0.3.10/dev/cuda_streams/_parallel.py +153 -0
- torch_named_linops-0.3.10/dev/cuda_streams/merge_traces.py +47 -0
- torch_named_linops-0.3.10/dev/cuda_streams/profile_distributed_batch.py +37 -0
- torch_named_linops-0.3.10/dev/cuda_streams/profile_multiprocess.py +29 -0
- torch_named_linops-0.3.10/dev/cuda_streams/profile_persistent_multiprocess.py +147 -0
- torch_named_linops-0.3.10/dev/cuda_streams/profile_persistent_multiprocess_faster.py +151 -0
- torch_named_linops-0.3.10/dev/cuda_streams/profile_streams.py +38 -0
- torch_named_linops-0.3.10/docs/Makefile +20 -0
- torch_named_linops-0.3.10/docs/make.bat +35 -0
- torch_named_linops-0.3.10/docs/source/conf.py +42 -0
- torch_named_linops-0.3.10/docs/source/explain.md +26 -0
- torch_named_linops-0.3.10/docs/source/index.md +19 -0
- torch_named_linops-0.3.10/docs/source/installation.md +46 -0
- torch_named_linops-0.3.10/docs/source/tutorial.md +15 -0
- torch_named_linops-0.3.10/pyproject.toml +100 -0
- torch_named_linops-0.3.10/renovate.json +6 -0
- torch_named_linops-0.3.10/src/torchlinops/__init__.py +4 -0
- torch_named_linops-0.3.10/src/torchlinops/alg/pcg.py +156 -0
- torch_named_linops-0.3.10/src/torchlinops/alg/poly.py +224 -0
- torch_named_linops-0.3.10/src/torchlinops/alg/powermethod.py +46 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/__init__.py +10 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_index/index.py +228 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_index/tests/bench_indexing.py +112 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_index/tests/test_index.py +33 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/.gitignore +11 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/__init__.py +2 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/_batch.py +12 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/grid.py +599 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/interp.py +152 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/kernels.py +384 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/memory.pkl +0 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/tests/_valid_pts.py +20 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/tests/bench_grid1d.py +101 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/tests/bench_grid2d.py +101 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/tests/bench_grid3d.py +101 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/tests/bench_ungrid1d.py +99 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/tests/bench_ungrid2d.py +99 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/tests/bench_ungrid3d.py +101 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/tests/conftest.py +164 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/tests/test_edgecases.py +66 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/tests/test_grid.py +71 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/tests/test_interp_diff.py +84 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/tests/test_ungrid.py +74 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_interp/ungrid.py +580 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/array_to_blocks.py +126 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/fold.py +488 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/nblocks.py +39 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/.gitignore +7 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/README.md +88 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/bench_fold1d.py +92 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/bench_fold2d.py +91 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/bench_fold3d.py +94 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/bench_unfold1d.py +84 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/bench_unfold2d.py +84 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/bench_unfold3d.py +89 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/conftest.py +163 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/memory.pkl +0 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/test_adjoint.py +86 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/test_fold.py +58 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/test_masking.py +42 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/test_unfold.py +54 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/test_unfold_diff.py +74 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/utils/__init__.py +4 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/utils/_cupy_pytorch.py +146 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/utils/_defaults.py +18 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/utils/_device.py +34 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/utils/_logging.py +52 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/tests/utils/benchmark.py +143 -0
- torch_named_linops-0.3.10/src/torchlinops/functional/_unfold/unfold.py +529 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/__init__.py +21 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/add.py +114 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/array_to_blocks.py +168 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/batch.py +257 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/breakpt.py +30 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/chain.py +167 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/concat.py +460 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/dense.py +213 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/diagonal.py +138 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/einops.py +301 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/fft.py +91 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/identity.py +89 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/interp.py +88 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/mpbatch.py +103 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/nameddim/__init__.py +5 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/nameddim/_matching.py +178 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/nameddim/_nameddim.py +60 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/nameddim/_nameddimcollection.py +169 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/nameddim/_namedshape.py +121 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/nameddim/_shapes.py +54 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/namedlinop.py +338 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/nufft.py +186 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/pad_last.py +158 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/sampling.py +97 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/scalar.py +32 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/stack.py +467 -0
- torch_named_linops-0.3.10/src/torchlinops/linops/trunc_pad.py +165 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_advanced.py +42 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_array_to_blocks.py +87 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_base.py +63 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_batch.py +40 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_concat.py +118 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_dense.py +42 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_diagonal.py +42 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_einops.py +34 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_interp.py +80 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_nameddim.py +42 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_nameddimcollection.py +11 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_namedlinop.py +34 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_namedshape.py +82 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_normal.py +42 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_nufft.py +180 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_pad_last.py +50 -0
- torch_named_linops-0.3.10/src/torchlinops/tests/test_sampling.py +42 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/__init__.py +10 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/_adjoint_helpers.py +26 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/_apply_struct.py +48 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/_batching.py +43 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/_cupy_pytorch.py +146 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/_defaults.py +18 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/_device.py +18 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/_event.py +77 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/_fft.py +21 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/_fileio.py +45 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/_log.py +57 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/_pad.py +12 -0
- torch_named_linops-0.3.10/src/torchlinops/utils/benchmark.py +177 -0
- torch_named_linops-0.3.10/uv.lock +2656 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
name: Install, Lint, and Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
- test-actions
|
|
8
|
+
pull_request: {}
|
|
9
|
+
|
|
10
|
+
concurrency:
|
|
11
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
12
|
+
cancel-in-progress: true
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
python-install-lint-test:
|
|
16
|
+
name: ${{ matrix.os }} - Python ${{ matrix.python-version }}
|
|
17
|
+
runs-on: ${{ matrix.os }}
|
|
18
|
+
timeout-minutes: 15
|
|
19
|
+
defaults:
|
|
20
|
+
run:
|
|
21
|
+
shell: bash
|
|
22
|
+
strategy:
|
|
23
|
+
max-parallel: 5
|
|
24
|
+
matrix:
|
|
25
|
+
os: [ubuntu-latest]
|
|
26
|
+
# deps: ['dev'] # 'test-cuda11' coming soon? https://github.com/github/roadmap/issues/961
|
|
27
|
+
python-version: ['3.10', '3.11', '3.12']
|
|
28
|
+
fail-fast: false
|
|
29
|
+
|
|
30
|
+
steps:
|
|
31
|
+
- name: Checkout repo
|
|
32
|
+
uses: actions/checkout@v4
|
|
33
|
+
# uv setup
|
|
34
|
+
- name: Set up python with uv
|
|
35
|
+
uses: astral-sh/setup-uv@v5
|
|
36
|
+
- name: Install python
|
|
37
|
+
run: uv python install ${{ matrix.python-version }}
|
|
38
|
+
- name: Initialize environment
|
|
39
|
+
run: uv sync --group all
|
|
40
|
+
# uv lint and test
|
|
41
|
+
- name: Lint with ruff
|
|
42
|
+
run: uv run ruff check
|
|
43
|
+
- name: Run tests with coverage
|
|
44
|
+
run: uv run pytest --cov .
|
|
45
|
+
|
|
46
|
+
# Generates warnings but still works?
|
|
47
|
+
- name: Upload coverage reports to Codecov
|
|
48
|
+
uses: codecov/codecov-action@v5.3.1
|
|
49
|
+
with:
|
|
50
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
File without changes
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025 Mark Nishimura
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: torch-named-linops
|
|
3
|
+
Version: 0.3.10
|
|
4
|
+
Summary: A flexible linear operator abstraction in pytorch.
|
|
5
|
+
Author-email: Mark Nishimura <markn1@stanford.edu>
|
|
6
|
+
License-File: LICENSE.txt
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: einops>=0.8.0
|
|
9
|
+
Requires-Dist: jaxtyping>=0.2.36
|
|
10
|
+
Requires-Dist: setuptools>=75.6.0
|
|
11
|
+
Requires-Dist: torch<2.3,>1.13; sys_platform == 'darwin' and platform_machine == 'x86_64'
|
|
12
|
+
Requires-Dist: torch>=2.5.1; sys_platform != 'darwin' or platform_machine != 'x86_64'
|
|
13
|
+
Requires-Dist: torchaudio<2.3,>1.13; sys_platform == 'darwin' and platform_machine == 'x86_64'
|
|
14
|
+
Requires-Dist: torchaudio>=2.5.1; sys_platform != 'darwin' or platform_machine != 'x86_64'
|
|
15
|
+
Requires-Dist: torchvision<0.20.1; sys_platform == 'darwin' and platform_machine == 'x86_64'
|
|
16
|
+
Requires-Dist: torchvision>=0.20.1; sys_platform != 'darwin' or platform_machine != 'x86_64'
|
|
17
|
+
Requires-Dist: tqdm>=4.67.1
|
|
18
|
+
Requires-Dist: triton>=3.0
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# torch-named-linops
|
|
22
|
+
|
|
23
|
+
A flexible linear operator abstraction implemented in PyTorch.
|
|
24
|
+
|
|
25
|
+
Heavily inspired by [einops](https://einops.rocks).
|
|
26
|
+
|
|
27
|
+
Unrelated to the (also good) [torch_linops](https://github.com/cvxgrp/torch_linops)
|
|
28
|
+
|
|
29
|
+
## Selected Feature List
|
|
30
|
+
- Dedicated abstraction for naming linear operator dimensions.
|
|
31
|
+
- A set of core linops, including:
|
|
32
|
+
- `Dense`
|
|
33
|
+
- `Diagonal`
|
|
34
|
+
- `FFT`
|
|
35
|
+
- `ArrayToBlocks`[^*] (similar to PyTorch's [unfold](https://pytorch.org/docs/stable/generated/torch.nn.Unfold.html) but in 1D/2D/3D/arbitrary dimensions)
|
|
36
|
+
- Useful for local patch extraction
|
|
37
|
+
- `Interpolate`[^*] (similar to SigPy's
|
|
38
|
+
[interpolate/gridding](https://sigpy.readthedocs.io/en/latest/generated/sigpy.linop.Interpolate.html))
|
|
39
|
+
- Comes with `kaiser_bessel` and (1D) `spline` kernels.
|
|
40
|
+
- `.H` and `.N` properties for adjoint $A^H$ and normal $A^HA$ linop creation.
|
|
41
|
+
- `Chain` and `Add` for composing linops together.
|
|
42
|
+
- `Batch` and `DistributedBatch` wrappers for splitting linops temporally on a
|
|
43
|
+
single GPU, or across multiple GPUs (via `torch.multiprocessing`).
|
|
44
|
+
- Full support for complex numbers. Adjoint takes the conjugate transpose.
|
|
45
|
+
- Full support for `autograd`-based automatic differentiation.
|
|
46
|
+
|
|
47
|
+
[^*] Includes a `functional` interface and
|
|
48
|
+
[triton](https://github.com/triton-lang/triton) backend for 1D/2D/3D.
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
### From source (recommended for developers)
|
|
52
|
+
1. Clone the repo with `git clone`
|
|
53
|
+
2. Run `pip install -e .` from the root directory.
|
|
54
|
+
- Or `uv add path/to/cloned/repo`
|
|
55
|
+
|
|
56
|
+
3. Pull upstream changes as required.
|
|
57
|
+
|
|
58
|
+
### Via `pip`'s git integration
|
|
59
|
+
Run the following, replacing `<TAG>` with the appropriate version (e.g. `0.3.7``)
|
|
60
|
+
|
|
61
|
+
- http version:
|
|
62
|
+
```sh
|
|
63
|
+
$ pip install git+https://github.com/nishi951/torch-named-linops.git@<TAG>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- ssh version:
|
|
67
|
+
``` sh
|
|
68
|
+
$ pip install git+ssh://git@github.com/nishi951/torch-named-linops.git@<TAG>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# torch-named-linops
|
|
2
|
+
|
|
3
|
+
A flexible linear operator abstraction implemented in PyTorch.
|
|
4
|
+
|
|
5
|
+
Heavily inspired by [einops](https://einops.rocks).
|
|
6
|
+
|
|
7
|
+
Unrelated to the (also good) [torch_linops](https://github.com/cvxgrp/torch_linops)
|
|
8
|
+
|
|
9
|
+
## Selected Feature List
|
|
10
|
+
- Dedicated abstraction for naming linear operator dimensions.
|
|
11
|
+
- A set of core linops, including:
|
|
12
|
+
- `Dense`
|
|
13
|
+
- `Diagonal`
|
|
14
|
+
- `FFT`
|
|
15
|
+
- `ArrayToBlocks`[^*] (similar to PyTorch's [unfold](https://pytorch.org/docs/stable/generated/torch.nn.Unfold.html) but in 1D/2D/3D/arbitrary dimensions)
|
|
16
|
+
- Useful for local patch extraction
|
|
17
|
+
- `Interpolate`[^*] (similar to SigPy's
|
|
18
|
+
[interpolate/gridding](https://sigpy.readthedocs.io/en/latest/generated/sigpy.linop.Interpolate.html))
|
|
19
|
+
- Comes with `kaiser_bessel` and (1D) `spline` kernels.
|
|
20
|
+
- `.H` and `.N` properties for adjoint $A^H$ and normal $A^HA$ linop creation.
|
|
21
|
+
- `Chain` and `Add` for composing linops together.
|
|
22
|
+
- `Batch` and `DistributedBatch` wrappers for splitting linops temporally on a
|
|
23
|
+
single GPU, or across multiple GPUs (via `torch.multiprocessing`).
|
|
24
|
+
- Full support for complex numbers. Adjoint takes the conjugate transpose.
|
|
25
|
+
- Full support for `autograd`-based automatic differentiation.
|
|
26
|
+
|
|
27
|
+
[^*] Includes a `functional` interface and
|
|
28
|
+
[triton](https://github.com/triton-lang/triton) backend for 1D/2D/3D.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
### From source (recommended for developers)
|
|
32
|
+
1. Clone the repo with `git clone`
|
|
33
|
+
2. Run `pip install -e .` from the root directory.
|
|
34
|
+
- Or `uv add path/to/cloned/repo`
|
|
35
|
+
|
|
36
|
+
3. Pull upstream changes as required.
|
|
37
|
+
|
|
38
|
+
### Via `pip`'s git integration
|
|
39
|
+
Run the following, replacing `<TAG>` with the appropriate version (e.g. `0.3.7``)
|
|
40
|
+
|
|
41
|
+
- http version:
|
|
42
|
+
```sh
|
|
43
|
+
$ pip install git+https://github.com/nishi951/torch-named-linops.git@<TAG>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- ssh version:
|
|
47
|
+
``` sh
|
|
48
|
+
$ pip install git+ssh://git@github.com/nishi951/torch-named-linops.git@<TAG>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import torch
|
|
4
|
+
import torch.nn as nn
|
|
5
|
+
import torch.multiprocessing as mp
|
|
6
|
+
from torch.profiler import profile, record_function, ProfilerActivity
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
mp.set_start_method("forkserver")
|
|
10
|
+
except RuntimeError:
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
__all__ = ["parallel_call", "merge_traces"]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def parallel_call(
|
|
17
|
+
modules: list[nn.Module],
|
|
18
|
+
args: list[tuple],
|
|
19
|
+
do_profile: bool = False,
|
|
20
|
+
):
|
|
21
|
+
"""Run a list of modules on a list of arguments in parallel
|
|
22
|
+
|
|
23
|
+
Note: if the modules have any parameters that require gradient, this might not work.
|
|
24
|
+
|
|
25
|
+
"""
|
|
26
|
+
if len(modules) != len(args):
|
|
27
|
+
raise ValueError(
|
|
28
|
+
f"modules and args must be same length but got {len(modules) } != {len(args)}"
|
|
29
|
+
)
|
|
30
|
+
# Initialize input queues, output_queues, and received queues
|
|
31
|
+
n_procs = len(modules)
|
|
32
|
+
qins = [mp.Queue() for _ in range(n_procs)]
|
|
33
|
+
qouts = [mp.Queue() for _ in range(n_procs)]
|
|
34
|
+
recvs = [mp.Event() for _ in range(n_procs)]
|
|
35
|
+
|
|
36
|
+
# Start processes and send data
|
|
37
|
+
procs = []
|
|
38
|
+
for rank, mod, args, qin, qout, recv in zip(
|
|
39
|
+
range(n_procs), modules, args, qins, qouts, recvs
|
|
40
|
+
):
|
|
41
|
+
proc = mp.Process(target=call_module, args=(rank, qin, qout, recv, do_profile))
|
|
42
|
+
proc.start()
|
|
43
|
+
qin.put((mod, args))
|
|
44
|
+
procs.append(proc)
|
|
45
|
+
|
|
46
|
+
# Receive data, signal child processes to exit,and join processes
|
|
47
|
+
outputs = []
|
|
48
|
+
for proc, qout, recv in zip(procs, qouts, recvs):
|
|
49
|
+
outputs.append(qout.get())
|
|
50
|
+
recv.set()
|
|
51
|
+
proc.join()
|
|
52
|
+
|
|
53
|
+
return outputs
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def call_module(
|
|
57
|
+
rank: int,
|
|
58
|
+
qin: mp.Queue,
|
|
59
|
+
qout: mp.Queue,
|
|
60
|
+
recv: mp.Event,
|
|
61
|
+
do_profile: bool = False,
|
|
62
|
+
):
|
|
63
|
+
"""Helper function for parallel call
|
|
64
|
+
|
|
65
|
+
rank : int
|
|
66
|
+
The id of this process
|
|
67
|
+
|
|
68
|
+
"""
|
|
69
|
+
# Get module and args from input queue
|
|
70
|
+
mod, args = qin.get()
|
|
71
|
+
|
|
72
|
+
# Run module on args
|
|
73
|
+
if do_profile:
|
|
74
|
+
with profile(
|
|
75
|
+
activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA],
|
|
76
|
+
on_trace_ready=lambda p: p.export_chrome_trace(
|
|
77
|
+
f"./worker_{rank}_trace.json"
|
|
78
|
+
),
|
|
79
|
+
) as prof:
|
|
80
|
+
out = mod(*args)
|
|
81
|
+
else:
|
|
82
|
+
out = mod(*args)
|
|
83
|
+
|
|
84
|
+
# Put output in the output queue
|
|
85
|
+
qout.put(out)
|
|
86
|
+
|
|
87
|
+
# Wait for parent process to signal received
|
|
88
|
+
recv.wait()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def merge_traces(input_files, output_file):
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
Example usage
|
|
95
|
+
trace_files = glob.glob("./worker_*_trace.json")
|
|
96
|
+
merge_traces(trace_files, "merged_trace.json")
|
|
97
|
+
"""
|
|
98
|
+
all_traces = {}
|
|
99
|
+
all_traces["traceEvents"] = []
|
|
100
|
+
|
|
101
|
+
for i, trace_file in enumerate(input_files):
|
|
102
|
+
with open(trace_file, "r") as f:
|
|
103
|
+
trace_data = json.load(f)
|
|
104
|
+
events = trace_data["traceEvents"]
|
|
105
|
+
for event in events:
|
|
106
|
+
event["pid"] = str(event["pid"]) + f"_{i}"
|
|
107
|
+
|
|
108
|
+
# Important step
|
|
109
|
+
all_traces["traceEvents"].extend(events)
|
|
110
|
+
# Less important steps
|
|
111
|
+
all_traces["schemaVersion"] = trace_data["schemaVersion"]
|
|
112
|
+
all_traces["deviceProperties"] = trace_data["deviceProperties"]
|
|
113
|
+
all_traces["traceName"] = str(output_file)
|
|
114
|
+
|
|
115
|
+
# Write combined traces to a new file
|
|
116
|
+
with open(output_file, "w") as f:
|
|
117
|
+
json.dump(all_traces, f)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
### Testing ###
|
|
121
|
+
class TestAdd(nn.Module):
|
|
122
|
+
"""Needs to be defined at top level of a module"""
|
|
123
|
+
|
|
124
|
+
def __init__(self, bias):
|
|
125
|
+
super().__init__()
|
|
126
|
+
self.bias = nn.Parameter(bias, requires_grad=False)
|
|
127
|
+
|
|
128
|
+
def forward(self, a):
|
|
129
|
+
def flipsign(x):
|
|
130
|
+
"""Test functions defined within methods"""
|
|
131
|
+
return -x
|
|
132
|
+
|
|
133
|
+
for i in range(1000):
|
|
134
|
+
flipsign(a + self.bias)
|
|
135
|
+
return flipsign(a + self.bias)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
if __name__ == "__main__":
|
|
139
|
+
n_parallel = 3
|
|
140
|
+
devs = [torch.device(f"cuda:{i}") for i in range(n_parallel)]
|
|
141
|
+
modules = [
|
|
142
|
+
TestAdd(torch.randn(i + 1, 1, device=devs[i])) for i in range(n_parallel)
|
|
143
|
+
]
|
|
144
|
+
args = [(torch.randn(i + 1, device=devs[i]),) for i in range(n_parallel)]
|
|
145
|
+
outputs = parallel_call(modules, args, do_profile=True)
|
|
146
|
+
print([f"{t.shape} : {t.device}" for t in outputs])
|
|
147
|
+
import glob, json
|
|
148
|
+
|
|
149
|
+
trace_files = glob.glob("./worker_*_trace.json")
|
|
150
|
+
print(trace_files)
|
|
151
|
+
merge_traces(trace_files, "merged_trace.json")
|
|
152
|
+
|
|
153
|
+
breakpoint()
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
#
|
|
3
|
+
import glob
|
|
4
|
+
import logging
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
logger = logging.getLogger("torchmri")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
trace_files = glob.glob("./worker_*_trace.json")
|
|
13
|
+
logger.info(f"Found trace files ", trace_files)
|
|
14
|
+
merge_traces(trace_files, "merged_trace.json")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def merge_traces(input_files, output_file):
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
Example usage
|
|
21
|
+
trace_files = glob.glob("./worker_*_trace.json")
|
|
22
|
+
merge_traces(trace_files, "merged_trace.json")
|
|
23
|
+
"""
|
|
24
|
+
all_traces = {}
|
|
25
|
+
all_traces["traceEvents"] = []
|
|
26
|
+
|
|
27
|
+
for i, trace_file in enumerate(input_files):
|
|
28
|
+
with open(trace_file, "r") as f:
|
|
29
|
+
trace_data = json.load(f)
|
|
30
|
+
events = trace_data["traceEvents"]
|
|
31
|
+
for event in events:
|
|
32
|
+
event["pid"] = str(event["pid"]) + f"_{i}"
|
|
33
|
+
|
|
34
|
+
# Important step
|
|
35
|
+
all_traces["traceEvents"].extend(events)
|
|
36
|
+
# Less important steps
|
|
37
|
+
all_traces["schemaVersion"] = trace_data["schemaVersion"]
|
|
38
|
+
all_traces["deviceProperties"] = trace_data["deviceProperties"]
|
|
39
|
+
all_traces["traceName"] = str(output_file)
|
|
40
|
+
|
|
41
|
+
# Write combined traces to a new file
|
|
42
|
+
with open(output_file, "w") as f:
|
|
43
|
+
json.dump(all_traces, f)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
|
|
3
|
+
from torchlinops import Dense, DistributedBatch
|
|
4
|
+
from torch.profiler import profile, record_function, ProfilerActivity
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def main():
|
|
8
|
+
device_idxs = [0, 1]
|
|
9
|
+
devices = [torch.device(f"cuda:{idx}") for idx in device_idxs]
|
|
10
|
+
# device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
|
11
|
+
B, M, N = 6, 100000, 10000
|
|
12
|
+
# Set up
|
|
13
|
+
weight = torch.randn(B, M, N, device="cpu")
|
|
14
|
+
A = Dense(weight, ("B", "M", "N"), ishape=("N",), oshape=("B", "M"))
|
|
15
|
+
A.to(devices[0])
|
|
16
|
+
A_batch = DistributedBatch(
|
|
17
|
+
A, devices[0], devices[0], torch.float32, torch.float32, devices=devices, B=1
|
|
18
|
+
)
|
|
19
|
+
# Prepare streams
|
|
20
|
+
# streams = [torch.cuda.Stream(devices[d % len(devices)]) for d in range(B)]
|
|
21
|
+
# default_streams = [torch.cuda.Stream(device) for device in devices]
|
|
22
|
+
# streams = [default_streams[d % len(devices)] for d in range(B)]
|
|
23
|
+
# for linop, stream in zip(A_batch._linops, streams):
|
|
24
|
+
# linop.to(stream.device)
|
|
25
|
+
|
|
26
|
+
# y = torch.empty(B, M, device=devices[0])
|
|
27
|
+
x = torch.randn(N, device="cpu")
|
|
28
|
+
with profile(
|
|
29
|
+
activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA],
|
|
30
|
+
on_trace_ready=lambda p: p.export_chrome_trace("./dist_trace.json"),
|
|
31
|
+
) as prof:
|
|
32
|
+
for i in range(10):
|
|
33
|
+
y = A_batch(x)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
main()
|