torch-hungarian 0.1.0__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.
@@ -0,0 +1,85 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 - 2026-11-21
4
+
5
+ ### Added
6
+
7
+ - Add a hosted GPU test lane on Modal's serverless NVIDIA hardware, ported from [Borda/affordable-GPU-CI](https://github.com/Borda/affordable-GPU-CI). A reusable workflow runs `.modal/test_runner.py`, which installs the pinned `develop` dependency group into a CUDA container, with the Modal client coming from a separate `modal` dependency group, and uploads the pytest log. It is called on pushes to `main` and `develop`, through manual dispatch with a GPU and device count, and from the maintainer-applied `gpu-tests` pull request label, which also posts the result and removes itself. The label lane triggers on `pull_request` rather than `pull_request_target`, so fork code never receives the Modal credentials.
8
+ - Fail the Modal lane closed on GPU eligibility. Every compiled Triton test skips itself on an ineligible host, so the runner checks for a CUDA-enabled PyTorch 2.4 or newer build, the `triton` package, and the requested number of devices with compute capability 8.0 or newer before pytest starts, and exits nonzero otherwise. A fully skipped suite can no longer be reported as a passing GPU run.
9
+
10
+ ### Changed
11
+
12
+ - Point the README citation section at the published Neurocomputing and AAAI Conference on Artificial Intelligence versions of the HoTPP and DeTPP papers instead of the arXiv preprints.
13
+
14
+ ### Fixed
15
+
16
+ - Accept gradient-bearing CPU costs and unsupported-CUDA fallback costs without changing the input's autograd graph.
17
+ - Reject complex costs consistently before backend dispatch or private Triton conversion, including empty batches and private validation modes.
18
+ - Bind benchmark evidence to each worker's imported dispatch source and record the benchmark checkout's dirty state even when the revision is supplied by the copied runner.
19
+ - Bound benchmark workers to 900 seconds by default, configurable with `--worker-timeout-seconds`; record timeouts as ineligible `worker_timeout` results.
20
+
21
+ ## 0.1.0rc1 - 2026-09-08
22
+
23
+ ### Added
24
+
25
+ - Add a hosted packaging gate: one job builds the wheel and the source distribution and uploads them, and a second job downloads that artifact without a checkout, installs the wheel with pip, and imports the package to report its version.
26
+
27
+ ### Changed
28
+
29
+ - Continue the project as the [Borda/torch-hungarian](https://github.com/Borda/torch-hungarian) fork, published on PyPI as `torch-hungarian`. Ivan Karpukhin remains the author of the original project and of the `0.0.x` compiled CUDA line; Jirka Borovec is the maintainer of this fork.
30
+ - Keep the import name `torch_linear_assignment`, so code written against the upstream project and against `torch-hungarian==0.1.0rc0` needs no change.
31
+ - Point the package metadata, README badges, install command, and Colab reproduction cells at the fork, and add source, changelog, and upstream project URLs.
32
+ - Resolve the installed version from `torch-hungarian` first and from `torch-linear-assignment` second in `tests/benchmark.py` and `make benchmark`, so the fork and the frozen `0.0.6` upstream baseline are both recognized.
33
+ - Uninstall `torch-hungarian` in `make install-legacy` before installing the `0.0.6` baseline. Both distributions provide `torch_linear_assignment`, so without this the target could report the fork's version while running the legacy backend.
34
+ - Raise the PyTorch floor from `1.12.0` to `2.0.0`. The Triton path already required `2.4` at runtime, and the SciPy fallback carries the older environments no further.
35
+ - Declare all packaging metadata in `pyproject.toml` through the standard `[project]` table and delete `setup.py`. The published runtime requirements are unchanged; `Home-page` becomes a `Homepage` project URL, and the author and maintainer fields take their canonical `Name <email>` form.
36
+ - Move the package sources under `src/`, so tests and tooling can no longer import the package from the working directory by accident.
37
+ - Export `torch_linear_assignment.__version__` and read the distribution version from it through `[tool.setuptools.dynamic]`, so the package holds the single version declaration.
38
+ - Fold `requirements.txt` into `[project.dependencies]` and `requirements-ci.txt` into a pinned `develop` dependency group, alongside an unpinned `test` group for local tooling. Dependency groups stay out of the published metadata, unlike extras.
39
+ - Install the hosted validation environment with `uv`, which resolves the pinned `develop` group and reports the dependency check. The Makefile keeps `pip`, because `uv` ignores user site-packages and would shadow a local user-site install.
40
+
41
+ ### Removed
42
+
43
+ - Remove the legacy CUDA and C++ sources, the `TLA_BUILD_LEGACY_CUDA` opt-in build, and the in-process `legacy_cuda` benchmark backend. The `0.1.0+` public API never dispatched to that extension, nothing built or tested it, and the sources remain available upstream and in this repository's history.
44
+ - Legacy comparisons keep working through the documented cross-environment route: `make install-legacy` installs the exact PyPI `0.0.6` baseline, and `make benchmark` still identifies, pins, and accepts a run that executes `legacy_cuda`.
45
+
46
+ ### Fixed
47
+
48
+ - Restrict the `triton` runtime dependency to Linux `x86_64`, matching the marker PyTorch itself uses. Triton publishes no aarch64 wheel and no source distribution, so the previous Linux-wide marker made installation fail outright on ARM Linux instead of falling back to SciPy.
49
+ - Pin `triton` in the hosted CI snapshot. The CPU-only PyTorch wheel omits the `triton` dependency that the CUDA wheel carries, so `pip check` failed on every matrix job.
50
+ - Upload the CPU-only benchmark diagnostic only when the benchmark step actually ran, so a failing install no longer reports a second, misleading missing-artifact error.
51
+
52
+ ## 0.1.0rc0 - 2026-08-20
53
+
54
+ ### Added
55
+
56
+ - Add a lazy Triton CUDA backend for Linux NVIDIA GPUs with compute capability 8.0 or newer and Torch 2.4 or newer.
57
+ - Add exact SciPy parity, dtype, autocast, non-finite input, non-default stream, and large-batch regression coverage for the Triton solver.
58
+ - Add reproducible author-run GPU validation and JSONL benchmark reporting with paired SciPy and legacy `0.0.6` comparisons.
59
+ - Add a fresh-process benchmark harness: every case runs in its own interpreter with a unique empty Triton cache, retains raw cold and warm samples, and enforces exact SciPy parity on each measured call.
60
+ - Add self-authenticating JSONL evidence that binds every record to the benchmark Git revision and source digest, the imported package origin and digest, the executed backend module digest, the input digest, the CPU model, dependency versions, and available `nvidia-smi` state.
61
+ - Add `make benchmark-evidence` for paired `off`, `nonfinite_only`, `infeasibility_flag_only`, and `full` validation-overhead, memory, and isolated cold-compilation records across five process rounds.
62
+ - Add `make validate-gpu-multi`, a fail-closed two-GPU acceptance gate, and a compiled-backend regression test that keeps stream, current-device, and workspace state isolated across two CUDA devices.
63
+ - Add a pinned `requirements-ci.txt` hosted validation snapshot, a Python 3.10, 3.12, and 3.13 test matrix, a CPU-only benchmark diagnostic artifact, and a pre-commit gate in hosted CI.
64
+
65
+ ### Changed
66
+
67
+ - Ship a pure-source package by default; normal installation no longer compiles the legacy CUDA extension.
68
+ - Require Python 3.10 or newer.
69
+ - Preserve `float64` solver precision, promote `float16`, `bfloat16`, and integer inputs to `float32`, and match SciPy's infeasible and invalid-cost behavior.
70
+ - Fall back to SciPy on unsupported CUDA runtimes and return the assignment to the input device.
71
+ - Make `make benchmark` fail closed by default: missing GPU or backend execution, out-of-memory, worker failure, package or implementation identity mismatch, incomplete process rounds, and parity failure all exit nonzero. `--allow-incomplete` is only for CPU-only diagnostics, and its rows remain ineligible for performance acceptance.
72
+ - Pin `make install-legacy` to the exact PyPI `0.0.6` baseline and fail if the checkout shadows that installed distribution.
73
+ - Split the publish workflow into separate build and publish jobs, pin action digests, publish through a protected environment with trusted publishing, and verify both the wheel and the source distribution against the release tag from outside the workspace.
74
+
75
+ ### Migration
76
+
77
+ - Existing `batch_linear_assignment` and `assignment_to_indices` calls do not require API changes.
78
+ - Users who require the compiled CUDA implementation, including execution on T4 (`sm_75`), should remain on the maintenance-only `0.0.x` release line. Release `0.0.6` can be installed with `python -m pip install "torch-linear-assignment==0.0.6"`.
79
+ - The Triton path requires Linux, an NVIDIA GPU with compute capability 8.0 or newer, Torch 2.4 or newer, and Triton. Other supported environments continue through SciPy.
80
+
81
+ ### Validation status
82
+
83
+ - Exact assignment parity and all GPU tests pass on NVIDIA L4 (`sm_89`), A100 (`sm_80`), and RTX PRO 6000 Blackwell (`sm_120`) author-run environments.
84
+ - H100 validation and isolated fresh-process cold-start measurements remain pending. Published warm timings are paired with same-machine SciPy and legacy baselines; they are not generalized across hardware.
85
+ - The published tables predate this benchmark harness and carry no JSONL provenance, so they are provisional author-run evidence. Publication-grade cold claims require a source-bound, five-process rerun on each advertised GPU class.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,30 @@
1
+ # Manifest syntax https://packaging.python.org/en/latest/guides/using-manifest-in/
2
+ #graft wheelhouse
3
+
4
+ recursive-exclude __pycache__ *.py[cod] *.orig
5
+ recursive-include src *.py
6
+
7
+ # Include the README and CHANGELOG
8
+ include *.md
9
+
10
+ # Include the license file
11
+ include LICENSE
12
+
13
+
14
+ # exclude tests from package
15
+ recursive-exclude tests *
16
+ recursive-exclude site *
17
+ exclude tests
18
+
19
+ # Include the build configuration, which also carries the requirements
20
+ include pyproject.toml
21
+
22
+ # Exclude build configs
23
+ exclude *.sh
24
+ exclude *.yml
25
+ exclude *.yaml
26
+ exclude Makefile
27
+
28
+ prune .devcontainer
29
+ prune .git
30
+ prune .github
@@ -0,0 +1,275 @@
1
+ Metadata-Version: 2.4
2
+ Name: torch-hungarian
3
+ Version: 0.1.0
4
+ Summary: Batched linear assignment with PyTorch and CUDA.
5
+ Author-email: Ivan Karpukhin <karpuhini@yandex.ru>
6
+ Maintainer: Jirka Borovec (Borda)
7
+ Project-URL: Homepage, https://github.com/Borda/torch-hungarian
8
+ Project-URL: Source, https://github.com/Borda/torch-hungarian
9
+ Project-URL: Changelog, https://github.com/Borda/torch-hungarian/blob/main/CHANGELOG.md
10
+ Project-URL: Upstream, https://github.com/ivan-chai/torch-linear-assignment
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: torch>=2.0.0
15
+ Requires-Dist: scipy>=1.6.0
16
+ Requires-Dist: triton; platform_system == "Linux" and platform_machine == "x86_64"
17
+ Dynamic: license-file
18
+
19
+ # Batch linear assignment for PyTorch
20
+
21
+ [![PyPI version](https://badge.fury.io/py/torch-hungarian.svg)](https://badge.fury.io/py/torch-hungarian) [![Modal GPU Tests](https://github.com/Borda/torch-hungarian/actions/workflows/gpu-tests.yml/badge.svg?event=push)](https://github.com/Borda/torch-hungarian/actions/workflows/gpu-tests.yml) [![Build Status](https://github.com/Borda/torch-hungarian/actions/workflows/cpu-tests.yml/badge.svg)](https://github.com/Borda/torch-hungarian/actions) [![Downloads](https://img.shields.io/pypi/dm/torch-hungarian)](https://pepy.tech/project/torch-hungarian) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
22
+
23
+ <h4 align="left">
24
+ <p>
25
+ <a href="#install">Installation</a> |
26
+ <a href="#backend-and-release-policy">Backend policy</a> |
27
+ <a href="#example">Usage</a> |
28
+ <a href="#support">Support</a> |
29
+ <a href="#legacy-cuda-implementation-00x">Legacy CUDA</a> |
30
+ <a href="#acknowledgments">Acknowledgments</a> |
31
+ <a href="#citation">Citation</a>
32
+ <p>
33
+ </h4>
34
+ Batch computation of the linear assignment problem with PyTorch. The active
35
+ `0.1.0+` release line is pure source: CPU calls use SciPy, and supported CUDA
36
+ calls use the lazy Triton backend.
37
+
38
+ ## Backend and release policy
39
+
40
+ The active release line is `0.1.0+`. It uses Triton on validated Linux NVIDIA GPUs with compute capability 8.0 or newer and SciPy everywhere else. Unsupported CUDA inputs are solved by the SciPy CPU fallback and returned to the input device. The compiled CUDA extension belongs to the maintenance-only `0.0.x` line and is documented separately in [Legacy CUDA implementation (`0.0.x`)](#legacy-cuda-implementation-00x). If that backend needs a compatibility or correctness fix, the project can issue another `0.0.x` release without adopting the Triton overhaul.
41
+
42
+ ## Install
43
+
44
+ Python 3.10 or newer is required. Install the `0.1.0` release from PyPI:
45
+
46
+ ```bash
47
+ python -m pip install "torch-hungarian==0.1.0"
48
+ ```
49
+
50
+ The distribution is named `torch-hungarian`, while the import name stays `torch_linear_assignment`. Keeping the import name means code written against the upstream project, and against `torch-hungarian==0.1.0rc0`, continues to work unchanged.
51
+
52
+ No editable install, local CUDA compilation, or `--no-build-isolation` flag is needed for normal use. On Linux, the package declares Triton through a platform marker and imports it lazily only for an eligible CUDA input. macOS and Windows installs remain usable through SciPy without requiring Triton.
53
+
54
+ ## Example
55
+
56
+ ```python
57
+ import torch
58
+ from torch_linear_assignment import batch_linear_assignment
59
+
60
+ cost = torch.tensor([
61
+ 8, 4, 7,
62
+ 5, 2, 3,
63
+ 9, 6, 7,
64
+ 9, 4, 8,
65
+ ]).reshape(1, 4, 3)
66
+
67
+ assignment = batch_linear_assignment(cost)
68
+ print(assignment)
69
+ ```
70
+
71
+ The output is:
72
+
73
+ ```py
74
+ tensor([[ 0, 2, -1, 1]])
75
+ ```
76
+
77
+ To get indices in the SciPy's format:
78
+
79
+ ```py
80
+ from torch_linear_assignment import assignment_to_indices
81
+
82
+ row_ind, col_ind = assignment_to_indices(assignment)
83
+ print(row_ind)
84
+ print(col_ind)
85
+ ```
86
+
87
+ The output is:
88
+
89
+ ```py
90
+ tensor([[0, 1, 3]])
91
+ tensor([[0, 2, 1]])
92
+ ```
93
+
94
+ ## Support
95
+
96
+ The public API is `batch_linear_assignment(cost)` with cost shape `(B, W, T)`. Assignments have shape `(B, W)`, use `torch.long`, and contain `-1` for an unmatched worker.
97
+
98
+ | Input and runtime | Backend and behavior |
99
+ | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
100
+ | CPU input on any supported OS | SciPy on CPU. This remains the reference path. |
101
+ | Linux NVIDIA GPU with compute capability 8.0 or newer, Torch >= 2.4, and Triton available | Lazy Triton CUDA backend. The first call can include Triton compilation. |
102
+ | CUDA input on an unsupported OS; non-NVIDIA Linux accelerator; NVIDIA GPU below compute capability 8.0 (including T4); or missing/ineligible Triton/Torch | Warn once, solve with SciPy on CPU, and return the assignment on the input device. |
103
+
104
+ The solver promotes `float16`, `bfloat16`, and integer costs to `float32`; `float64` costs remain `float64`. Triton execution disables autocast, so precision already lost before entry cannot be recovered.
105
+
106
+ Costs may require gradients; solving leaves their autograd graph intact and returns non-differentiable integer assignments. Complex costs raise `TypeError("Complex costs are not supported.")` on every backend, including empty batches.
107
+
108
+ Non-finite costs follow the SciPy contract. `NaN` and `-inf` raise `ValueError("matrix contains invalid numeric entries")`. `+inf` represents a forbidden edge when a perfect matching still exists; if the matrix is infeasible, the call raises `ValueError("cost matrix is infeasible")` instead of terminating the process with a device assertion.
109
+
110
+ ## Validation and performance status
111
+
112
+ GPU validation is author-run rather than hosted CI. The validation targets are Linux NVIDIA GPUs with compute capability 8.0 or newer (for example, L4, A100, H100, or RTX PRO 6000 Blackwell):
113
+
114
+ ```bash
115
+ make validate # correctness once; prints GPU metadata when available
116
+ make benchmark # SciPy CPU and installed public CUDA; writes JSONL and a cold/warm table
117
+ make validate-gpu-multi # strict two-device compiled-kernel acceptance
118
+ make benchmark-evidence # validation overhead, memory, and isolated cold compilation
119
+ ```
120
+
121
+ `make validate` prints Python/platform, Torch/CUDA, Triton, and GPU compute capability metadata when a CUDA device is visible. `make benchmark` separately measures the SciPy CPU reference and installed public CUDA backend, writes complete JSONL evidence, and prints a compact cold/warm table. A clean GPU metadata skip on macOS or a machine without CUDA is expected, but is not GPU evidence.
122
+
123
+ `make validate-gpu-multi` is fail-closed: it requires Linux, CUDA-enabled Torch 2.4 or newer, Triton, and at least two visible NVIDIA GPUs with compute capability 8.0 or newer. It prints every visible GPU and runs a compiled test with distinct inputs and non-default streams on two devices. A skipped ordinary pytest run does not satisfy this gate.
124
+
125
+ `make benchmark-evidence` runs the three primary batch-208 orientations in five fresh processes per validation mode. Each Triton worker receives a unique empty Triton cache, initializes CUDA, and transfers its input before timing. JSONL records retain the first solver call, raw warm samples, exact parity, and separate cold and warm CUDA allocation boundaries. Paired `off`, `nonfinite_only`, `infeasibility_flag_only`, and `full` records include absolute and percentage overhead versus `off` plus the interaction between the two validation checks. Missing modes, process rounds, backend execution, or GPU evidence make the command fail unless `--allow-incomplete` is explicitly used for diagnostics.
126
+
127
+ `make benchmark` is fail-closed by default. Missing GPU/backend execution, OOM, worker failure, identity mismatch, incomplete process rounds, and parity failure all exit nonzero. `--allow-incomplete` is only for CPU-only diagnostics; its rows remain ineligible for performance acceptance.
128
+
129
+ Each benchmark worker has a 900-second timeout covering process startup, compilation, and all timed calls. Override it with `--worker-timeout-seconds` using a positive finite number, for example `make benchmark BENCHMARK_ARGS="--worker-timeout-seconds 1800"`. A timed-out worker produces a `worker_timeout` record with its workload and timeout limit; it cannot satisfy performance acceptance.
130
+
131
+ Each case runs in a fresh interpreter; each Triton case also uses a unique empty Triton cache. Cold is the first timed solver call after benchmark/package import and input setup. CUDA rows additionally complete context setup and input transfer before timing. Explicit private lanes resolve their backend module before timing; the default public lane includes any lazy backend import. Triton cold includes kernel compilation and execution. The default three process rounds retain three raw cold samples and reverse backend order on alternating rounds. Warm CUDA samples are synchronized, device-resident solver latency. They include backend-adapter work, implementation validation when applicable, workspace allocation, execution, and result conversion, but exclude input generation/transfer, SciPy-oracle construction, and parity diagnostics. GPU driver and hardware state are observed, not reset.
132
+
133
+ Every cold, warmup, and timed result must exactly match the promoted SciPy assignment. JSONL records bind evidence to the benchmark Git revision/source digest, imported package origin/digest, executed backend module/digest, input digest, raw samples, CPU model, dependency versions, and available `nvidia-smi` driver/clock/power/temperature state. The console table is only a one-decimal summary.
134
+
135
+ Each worker also records its imported dispatch module in `assignment_module_origin` and `assignment_module_sha256`. `benchmark_git_dirty` reports `clean`, `dirty`, or `unavailable` for the benchmark's source checkout, independently of any supplied revision. Package/dispatch hashes describe the worker's imported files, which can belong to a separately installed legacy distribution.
136
+
137
+ The first Triton call may be slower because it includes cold compilation; measure cold compilation separately from warm execution. Do not generalize performance across GPU models or workloads. The active `0.1.0+` line requires the correctness, AMP/dtype, fallback, packaging, GPU, and warm-performance gates to pass on each advertised GPU class.
138
+
139
+ Author-run evidence captured on 2026-08-20 at commit `eee95ffc` (`perf(triton): terminate completed augmentations early`) supports this matrix:
140
+
141
+ | GPU | SciPy reference comparison | Triton validation |
142
+ | ---------------------------------------- | ------------------------------- | ------------------ |
143
+ | NVIDIA L4 (`sm_89`) | Exact in all 30 benchmark cases | `78/78` tests pass |
144
+ | NVIDIA A100 (`sm_80`) | Exact in all 30 benchmark cases | `78/78` tests pass |
145
+ | NVIDIA H100 (`sm_90`) | ? | ? |
146
+ | NVIDIA RTX PRO 6000 Blackwell (`sm_120`) | Exact in all 30 benchmark cases | `78/78` tests pass |
147
+
148
+ Representative batch-208 float32 performance is shown below. Each timing cell is `transpose / square / direct` in milliseconds for `300 x 100`, `300 x 300`, and `300 x 600`. Ratios above `1.0x` mean Triton is faster. Values are rounded to one decimal; `~` marks ratios derived from the displayed timings.
149
+
150
+ | GPU / timing | SciPy CPU (ms) | Triton (ms) | SciPy / Triton |
151
+ | ------------------ | -------------------- | ---------------- | ----------------------- |
152
+ | L4 (first\*) | 71.8 / 788.6 / 421.9 | 1.0 / 7.6 / 4.3 | ~71.8x / 103.8x / 98.1x |
153
+ | L4 (warm) | 71.3 / 782.5 / 422.8 | 1.0 / 7.6 / 4.4 | 71.3x / 103.5x / 96.4x |
154
+ | A100 (first\*) | 74.8 / 788.6 / 430.3 | 1.3 / 11.6 / 4.3 | ~57.5x / 68.0x / 100.1x |
155
+ | A100 (warm) | 73.9 / 788.4 / 431.9 | 1.3 / 11.6 / 4.4 | 56.7x / 67.7x / 99.1x |
156
+ | H100 (first\*) | ? | ? | ? |
157
+ | H100 (warm) | ? | ? | ? |
158
+ | RTX 6000 (first\*) | 32.1 / 409.8 / 204.8 | 0.7 / 5.5 / 2.2 | ~45.9x / 74.5x / 93.1x |
159
+ | RTX 6000 (warm) | 32.3 / 410.1 / 204.8 | 0.5 / 5.4 / 2.2 | 60.8x / 75.8x / 94.4x |
160
+
161
+ The Triton implementation parallelizes batch items and vectorizes each current candidate-column scan. Commit `eee95ffc` also terminates the shortest-path search when an augmentation finds an unmatched sink. This removes the post-completion iterations that dominated direct matrices. Against the same-machine SciPy CPU reference, representative warm Triton speedups span `56.7x`--`103.5x` while retaining exact assignment parity.
162
+
163
+ `first*` means the first call for that case in the shared benchmark process. It is not an isolated compilation measurement: earlier shapes and dtypes can populate driver, process, and Triton disk caches. The three notebooks also predate the fresh-process benchmark-integrity harness described above, so these measurements are provisional author-run evidence rather than the final cold-performance record. They carry no self-authenticating JSONL provenance, and H100 has never been measured. Publication-grade cold claims require a source-bound, five-process rerun on each advertised GPU class.
164
+
165
+ Do not publish a Triton-only timing as a speedup. Each performance report pairs the same seeded workload with its same-machine SciPy CPU baseline.
166
+
167
+ Run both cells on each fresh Colab GPU runtime and retain the two JSONL artifacts. The first installs the exact PyPI baseline; the second reinstalls, validates, and measures the checkout. Package and implementation expectations reject checkout shadowing or fallback execution.
168
+
169
+ ```python
170
+ !git clone https://github.com/Borda/torch-hungarian.git
171
+ %cd torch-hungarian
172
+ !git checkout develop
173
+ !git rev-parse HEAD
174
+ !make install-legacy
175
+ !make benchmark BENCHMARK_ARGS="--label pypi-0.0.6 --expect-package-version 0.0.6 --expect-implementation legacy_cuda --process-rounds 5 --repetitions 30"
176
+ ```
177
+
178
+ ```python
179
+ !make validate
180
+ !make benchmark BENCHMARK_ARGS="--label current-triton --expect-package-version 0.1.0 --expect-implementation triton --process-rounds 5 --repetitions 30"
181
+ ```
182
+
183
+ Pair only matching device, shape, dtype, seed, validation mode, and timing statistic when computing `SciPy / Triton` or `legacy / Triton`. Use `make benchmark-evidence` for the bounded batch-208 validation-overhead and memory run.
184
+
185
+ For kernel diagnosis, capture a trace separately from the timing run; profiler overhead must never be reported as benchmark latency:
186
+
187
+ ```python
188
+ import sys
189
+
190
+ import torch
191
+
192
+ from torch_linear_assignment import batch_linear_assignment
193
+
194
+ generator = torch.Generator().manual_seed(320)
195
+ cpu_cost = torch.randn((208, 300, 600), generator=generator, dtype=torch.float32)
196
+ expected = batch_linear_assignment(cpu_cost)
197
+ cost = cpu_cost.cuda()
198
+ with torch.profiler.profile(
199
+ activities=[torch.profiler.ProfilerActivity.CPU, torch.profiler.ProfilerActivity.CUDA],
200
+ record_shapes=True,
201
+ profile_memory=True,
202
+ ) as profile:
203
+ actual = batch_linear_assignment(cost)
204
+ torch.cuda.synchronize()
205
+ assert "torch_linear_assignment._triton" in sys.modules
206
+ assert torch.equal(actual.cpu(), expected)
207
+ profile.export_chrome_trace("triton-direct-b208-f32.json")
208
+ ```
209
+
210
+ For direct benchmark-script options, the underlying command writes complete JSONL evidence to a run-specific file and prints a compact table containing the backend, validation mode, shape, status, cold/warm latency, and exact-parity result:
211
+
212
+ ```bash
213
+ make benchmark
214
+ python tests/benchmark.py --backends scipy,public_cuda --output benchmark-results.jsonl
215
+ ```
216
+
217
+ The command exits nonzero if any invocation fails exact parity. The JSONL file retains replay diagnostics that the console table intentionally omits.
218
+
219
+ ## Legacy CUDA implementation (`0.0.x`)
220
+
221
+ Release `0.0.6` contains the frozen, compiled plain-CUDA implementation. It is not the active default and should be pinned only when that legacy GPU path is explicitly required, including T4 (`sm_75`) execution:
222
+
223
+ ```bash
224
+ python -m pip install "torch-linear-assignment==0.0.6"
225
+ ```
226
+
227
+ The extension needs a compatible CUDA build environment and must include `sm_75`; the project does not promise a portable T4 wheel. Pinning it is also workload-dependent: in the recorded T4 comparison, SciPy was faster through batch 50, while legacy CUDA was materially faster for the tested batch-208 transpose and direct cases.
228
+
229
+ This fork carries no CUDA sources, so the legacy kernel can only be measured from its published `0.0.x` distribution; the sources remain in the upstream project and in this repository's history. In a separate baseline environment, `make install-legacy` installs the exact PyPI `0.0.6` baseline and fails if the checkout shadows that installed distribution. `make benchmark` then runs a copy of `tests/benchmark.py` from outside the checkout, so the cross-version measurement targets the installed public CUDA backend rather than the working tree. Pair those results with the same shapes, dtypes, seed, GPU, and validation mode from the current Triton run.
230
+
231
+ The following author-run batch-208 FP32 comparison uses the same `transpose / square / direct` ordering as the main table. Ratios above `1.0x` mean Triton is faster; values are rounded to one decimal, and `~` marks ratios derived from separately displayed legacy and current-package timings.
232
+
233
+ | GPU / timing | Legacy 0.0.6 (ms) | Triton (ms) | Legacy / Triton |
234
+ | ------------------ | -------------------- | ---------------- | ------------------------ |
235
+ | T4 (first\*) | 37.0 / 879.5 / 273.9 | — | — |
236
+ | T4 (warm) | 37.7 / 738.6 / 272.6 | — | — |
237
+ | L4 (first\*) | 37.9 / 648.5 / 274.5 | 1.0 / 7.6 / 4.3 | ~37.9x / 85.3x / 63.8x |
238
+ | L4 (warm) | 37.8 / 652.5 / 273.3 | 1.0 / 7.6 / 4.4 | ~37.8x / 85.9x / 62.1x |
239
+ | A100 (first\*) | 36.2 / 755.5 / 271.7 | 1.3 / 11.6 / 4.3 | ~27.8x / 65.1x / 63.2x |
240
+ | A100 (warm) | 36.2 / 731.3 / 271.6 | 1.3 / 11.6 / 4.4 | ~27.8x / 63.0x / 61.7x |
241
+ | H100 (first\*) | ? | ? | ? |
242
+ | H100 (warm) | ? | ? | ? |
243
+ | RTX 6000 (first\*) | 35.4 / 607.1 / 248.0 | 0.7 / 5.5 / 2.2 | ~50.6x / 110.4x / 112.7x |
244
+ | RTX 6000 (warm) | 35.4 / 607.6 / 249.3 | 0.5 / 5.4 / 2.2 | ~70.8x / 112.5x / 113.3x |
245
+
246
+ Triton is faster in all 30 paired warm cases on each measured supported GPU; the weakest displayed ratio is about `6.0x`. T4 has no Triton timing because it is below the supported compute capability, and H100 remains unmeasured. The `first*` caveat from the main table applies equally here.
247
+
248
+ ## Acknowledgments
249
+
250
+ The original project was written by Ivan Karpukhin and is published upstream as [ivan-chai/torch-linear-assignment](https://github.com/ivan-chai/torch-linear-assignment); the `0.0.x` compiled CUDA line remains his work. This fork continues the project as [Borda/torch-hungarian](https://github.com/Borda/torch-hungarian), maintained by [@Borda](https://github.com/Borda), who implemented the `0.1.0+` pure-source Triton backend, the GPU validation workflow, and the benchmark revamp.
251
+
252
+ ## Citation
253
+
254
+ The code was originally developed for the [HoTPP Benchmark](https://github.com/ivan-chai/hotpp-benchmark). If you use this code in your research project, please cite one of the following papers:
255
+
256
+ ```
257
+ @article{karpukhin2026hotpp,
258
+ title={HoTPP benchmark: Are we good at the long horizon events forecasting?},
259
+ author={Karpukhin, Ivan and Shipilov, Foma and Savchenko, Andrey},
260
+ journal={Neurocomputing},
261
+ pages={132771},
262
+ year={2026},
263
+ publisher={Elsevier}
264
+ }
265
+
266
+ @inproceedings{karpukhin2026detecting,
267
+ title={Detecting the future: All-at-Once event sequence forecasting with horizon matching},
268
+ author={Karpukhin, Ivan and Savchenko, Andrey},
269
+ booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
270
+ volume={40},
271
+ number={27},
272
+ pages={22536--22544},
273
+ year={2026}
274
+ }
275
+ ```