epicl 0.1.0__py3-none-any.whl

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.
Files changed (135) hide show
  1. epicl/__init__.py +6 -0
  2. epicl/_sdm/LICENSE +204 -0
  3. epicl/_sdm/VENDORED.md +31 -0
  4. epicl/_sdm/__init__.py +53 -0
  5. epicl/_sdm/_constants.py +6 -0
  6. epicl/_sdm/_inference.py +42 -0
  7. epicl/_sdm/_kernels/__init__.py +11 -0
  8. epicl/_sdm/_kernels/rmsnorm_cast.py +93 -0
  9. epicl/_sdm/_kernels/segment_multi_reduce.py +142 -0
  10. epicl/_sdm/_kernels/triton/__init__.py +7 -0
  11. epicl/_sdm/_kernels/triton/rmsnorm_cast.py +136 -0
  12. epicl/_sdm/_kernels/triton/segment_multi_reduce.py +173 -0
  13. epicl/_sdm/_memory.py +34 -0
  14. epicl/_sdm/_warnings.py +29 -0
  15. epicl/_sdm/cache.py +164 -0
  16. epicl/_sdm/ensemble.py +502 -0
  17. epicl/_sdm/models/__init__.py +17 -0
  18. epicl/_sdm/models/_huggingface.py +49 -0
  19. epicl/_sdm/models/base.py +967 -0
  20. epicl/_sdm/models/callback.py +63 -0
  21. epicl/_sdm/models/ecoc.py +198 -0
  22. epicl/_sdm/models/kumo/__init__.py +13 -0
  23. epicl/_sdm/models/kumo/tabular/__init__.py +12 -0
  24. epicl/_sdm/models/kumo/tabular/block.py +101 -0
  25. epicl/_sdm/models/kumo/tabular/cell_embedding.py +86 -0
  26. epicl/_sdm/models/kumo/tabular/icl.py +134 -0
  27. epicl/_sdm/models/kumo/tabular/model.py +299 -0
  28. epicl/_sdm/models/kumo/tabular/recipe.py +72 -0
  29. epicl/_sdm/models/kumo/tabular/row_embedding.py +215 -0
  30. epicl/_sdm/models/tabfm/LICENSE +209 -0
  31. epicl/_sdm/models/tabfm/__init__.py +6 -0
  32. epicl/_sdm/models/tabfm/cell_embedding.py +220 -0
  33. epicl/_sdm/models/tabiclv2/LICENSE +33 -0
  34. epicl/_sdm/nn/__init__.py +29 -0
  35. epicl/_sdm/nn/_buffer.py +91 -0
  36. epicl/_sdm/nn/attention.py +816 -0
  37. epicl/_sdm/nn/glu.py +78 -0
  38. epicl/_sdm/nn/linear.py +46 -0
  39. epicl/_sdm/nn/rms_norm.py +60 -0
  40. epicl/_sdm/nn/rope.py +107 -0
  41. epicl/_sdm/nn/scaling.py +242 -0
  42. epicl/_sdm/nn/set_transformer.py +163 -0
  43. epicl/_sdm/nn/softplus.py +65 -0
  44. epicl/_sdm/processing/__init__.py +97 -0
  45. epicl/_sdm/processing/base.py +249 -0
  46. epicl/_sdm/processing/categorical/__init__.py +17 -0
  47. epicl/_sdm/processing/categorical/_categorical.py +61 -0
  48. epicl/_sdm/processing/categorical/align.py +541 -0
  49. epicl/_sdm/processing/categorical/count.py +122 -0
  50. epicl/_sdm/processing/categorical/impute.py +108 -0
  51. epicl/_sdm/processing/categorical/shuffle.py +205 -0
  52. epicl/_sdm/processing/common/__init__.py +33 -0
  53. epicl/_sdm/processing/common/callable.py +30 -0
  54. epicl/_sdm/processing/common/choice.py +186 -0
  55. epicl/_sdm/processing/common/drop.py +29 -0
  56. epicl/_sdm/processing/common/ensemble.py +188 -0
  57. epicl/_sdm/processing/common/identity.py +19 -0
  58. epicl/_sdm/processing/common/select.py +108 -0
  59. epicl/_sdm/processing/common/sequential.py +159 -0
  60. epicl/_sdm/processing/common/shuffle.py +196 -0
  61. epicl/_sdm/processing/common/stype.py +200 -0
  62. epicl/_sdm/processing/common/table.py +121 -0
  63. epicl/_sdm/processing/common/task.py +136 -0
  64. epicl/_sdm/processing/common/to_numerical.py +61 -0
  65. epicl/_sdm/processing/datetime/__init__.py +9 -0
  66. epicl/_sdm/processing/datetime/calendar.py +197 -0
  67. epicl/_sdm/processing/ensemble.py +204 -0
  68. epicl/_sdm/processing/execution.py +419 -0
  69. epicl/_sdm/processing/numerical/__init__.py +39 -0
  70. epicl/_sdm/processing/numerical/_stats.py +22 -0
  71. epicl/_sdm/processing/numerical/cast.py +31 -0
  72. epicl/_sdm/processing/numerical/clip.py +49 -0
  73. epicl/_sdm/processing/numerical/clip_soft.py +57 -0
  74. epicl/_sdm/processing/numerical/constant.py +236 -0
  75. epicl/_sdm/processing/numerical/flip_sign.py +79 -0
  76. epicl/_sdm/processing/numerical/impute.py +49 -0
  77. epicl/_sdm/processing/numerical/pca.py +63 -0
  78. epicl/_sdm/processing/numerical/power.py +326 -0
  79. epicl/_sdm/processing/numerical/quantile.py +306 -0
  80. epicl/_sdm/processing/numerical/quantile_clip.py +64 -0
  81. epicl/_sdm/processing/numerical/random_projection.py +87 -0
  82. epicl/_sdm/processing/numerical/rank_gaussian.py +169 -0
  83. epicl/_sdm/processing/numerical/robust_scale.py +89 -0
  84. epicl/_sdm/processing/numerical/sigma_clip.py +124 -0
  85. epicl/_sdm/processing/numerical/standardize.py +74 -0
  86. epicl/_sdm/processing/output/__init__.py +15 -0
  87. epicl/_sdm/processing/output/reduce.py +87 -0
  88. epicl/_sdm/processing/output/softmax.py +49 -0
  89. epicl/_sdm/processing/output/sort.py +17 -0
  90. epicl/_sdm/processing/recipe.py +155 -0
  91. epicl/_sdm/processing/text/__init__.py +13 -0
  92. epicl/_sdm/processing/text/sentence_transformer.py +452 -0
  93. epicl/_sdm/processing/text/tfidf.py +479 -0
  94. epicl/_sdm/relational/__init__.py +17 -0
  95. epicl/_sdm/relational/backend/__init__.py +13 -0
  96. epicl/_sdm/relational/backend/_cugraph.py +547 -0
  97. epicl/_sdm/relational/backend/_pyg_lib.py +176 -0
  98. epicl/_sdm/relational/data.py +393 -0
  99. epicl/_sdm/relational/join.py +174 -0
  100. epicl/_sdm/relational/sampler.py +260 -0
  101. epicl/_sdm/relational/task.py +466 -0
  102. epicl/_sdm/stype.py +396 -0
  103. epicl/_sdm/task.py +54 -0
  104. epicl/_sdm/tensor/__init__.py +21 -0
  105. epicl/_sdm/tensor/categorical.py +954 -0
  106. epicl/_sdm/tensor/columnar.py +1128 -0
  107. epicl/_sdm/tensor/io/__init__.py +23 -0
  108. epicl/_sdm/tensor/io/arrow.py +120 -0
  109. epicl/_sdm/tensor/io/cudf.py +47 -0
  110. epicl/_sdm/tensor/mixin.py +122 -0
  111. epicl/_sdm/tensor/nullable.py +964 -0
  112. epicl/_sdm/tensor/string.py +527 -0
  113. epicl/_sdm/tensor/table.py +2036 -0
  114. epicl/_sdm/tensor/var_len.py +1487 -0
  115. epicl/_sdm/testing/__init__.py +14 -0
  116. epicl/_sdm/testing/decorators.py +50 -0
  117. epicl/_sdm/testing/memory.py +93 -0
  118. epicl/_sdm/third_party/tabpfn-extensions/LICENSE +202 -0
  119. epicl/copula.py +217 -0
  120. epicl/encode.py +64 -0
  121. epicl/gp.py +240 -0
  122. epicl/law.py +217 -0
  123. epicl/model.py +220 -0
  124. epicl/regressor.py +537 -0
  125. epicl/views.py +43 -0
  126. epicl/weights.py +35 -0
  127. epicl-0.1.0.dist-info/METADATA +257 -0
  128. epicl-0.1.0.dist-info/RECORD +135 -0
  129. epicl-0.1.0.dist-info/WHEEL +4 -0
  130. epicl-0.1.0.dist-info/licenses/LICENSE +28 -0
  131. epicl-0.1.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +17 -0
  132. epicl-0.1.0.dist-info/licenses/src/epicl/_sdm/LICENSE +204 -0
  133. epicl-0.1.0.dist-info/licenses/src/epicl/_sdm/models/tabfm/LICENSE +209 -0
  134. epicl-0.1.0.dist-info/licenses/src/epicl/_sdm/models/tabiclv2/LICENSE +33 -0
  135. epicl-0.1.0.dist-info/licenses/src/epicl/_sdm/third_party/tabpfn-extensions/LICENSE +202 -0
epicl/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ """EpICL: tabular in-context regression with a joint predictive law and an epistemic / aleatoric split."""
2
+
3
+ from .regressor import EpICLRegressor, EpiCopulaRegressor, KumoEpiRegressor
4
+
5
+ __version__ = "0.1.0"
6
+ __all__ = ["EpICLRegressor", "EpiCopulaRegressor", "KumoEpiRegressor"]
epicl/_sdm/LICENSE ADDED
@@ -0,0 +1,204 @@
1
+ Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+
3
+
4
+ Apache License
5
+ Version 2.0, January 2004
6
+ http://www.apache.org/licenses/
7
+
8
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
9
+
10
+ 1. Definitions.
11
+
12
+ "License" shall mean the terms and conditions for use, reproduction,
13
+ and distribution as defined by Sections 1 through 9 of this document.
14
+
15
+ "Licensor" shall mean the copyright owner or entity authorized by
16
+ the copyright owner that is granting the License.
17
+
18
+ "Legal Entity" shall mean the union of the acting entity and all
19
+ other entities that control, are controlled by, or are under common
20
+ control with that entity. For the purposes of this definition,
21
+ "control" means (i) the power, direct or indirect, to cause the
22
+ direction or management of such entity, whether by contract or
23
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
24
+ outstanding shares, or (iii) beneficial ownership of such entity.
25
+
26
+ "You" (or "Your") shall mean an individual or Legal Entity
27
+ exercising permissions granted by this License.
28
+
29
+ "Source" form shall mean the preferred form for making modifications,
30
+ including but not limited to software source code, documentation
31
+ source, and configuration files.
32
+
33
+ "Object" form shall mean any form resulting from mechanical
34
+ transformation or translation of a Source form, including but
35
+ not limited to compiled object code, generated documentation,
36
+ and conversions to other media types.
37
+
38
+ "Work" shall mean the work of authorship, whether in Source or
39
+ Object form, made available under the License, as indicated by a
40
+ copyright notice that is included in or attached to the work
41
+ (an example is provided in the Appendix below).
42
+
43
+ "Derivative Works" shall mean any work, whether in Source or Object
44
+ form, that is based on (or derived from) the Work and for which the
45
+ editorial revisions, annotations, elaborations, or other modifications
46
+ represent, as a whole, an original work of authorship. For the purposes
47
+ of this License, Derivative Works shall not include works that remain
48
+ separable from, or merely link (or bind by name) to the interfaces of,
49
+ the Work and Derivative Works thereof.
50
+
51
+ "Contribution" shall mean any work of authorship, including
52
+ the original version of the Work and any modifications or additions
53
+ to that Work or Derivative Works thereof, that is intentionally
54
+ submitted to Licensor for inclusion in the Work by the copyright owner
55
+ or by an individual or Legal Entity authorized to submit on behalf of
56
+ the copyright owner. For the purposes of this definition, "submitted"
57
+ means any form of electronic, verbal, or written communication sent
58
+ to the Licensor or its representatives, including but not limited to
59
+ communication on electronic mailing lists, source code control systems,
60
+ and issue tracking systems that are managed by, or on behalf of, the
61
+ Licensor for the purpose of discussing and improving the Work, but
62
+ excluding communication that is conspicuously marked or otherwise
63
+ designated in writing by the copyright owner as "Not a Contribution."
64
+
65
+ "Contributor" shall mean Licensor and any individual or Legal Entity
66
+ on behalf of whom a Contribution has been received by Licensor and
67
+ subsequently incorporated within the Work.
68
+
69
+ 2. Grant of Copyright License. Subject to the terms and conditions of
70
+ this License, each Contributor hereby grants to You a perpetual,
71
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
72
+ copyright license to reproduce, prepare Derivative Works of,
73
+ publicly display, publicly perform, sublicense, and distribute the
74
+ Work and such Derivative Works in Source or Object form.
75
+
76
+ 3. Grant of Patent License. Subject to the terms and conditions of
77
+ this License, each Contributor hereby grants to You a perpetual,
78
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
79
+ (except as stated in this section) patent license to make, have made,
80
+ use, offer to sell, sell, import, and otherwise transfer the Work,
81
+ where such license applies only to those patent claims licensable
82
+ by such Contributor that are necessarily infringed by their
83
+ Contribution(s) alone or by combination of their Contribution(s)
84
+ with the Work to which such Contribution(s) was submitted. If You
85
+ institute patent litigation against any entity (including a
86
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
87
+ or a Contribution incorporated within the Work constitutes direct
88
+ or contributory patent infringement, then any patent licenses
89
+ granted to You under this License for that Work shall terminate
90
+ as of the date such litigation is filed.
91
+
92
+ 4. Redistribution. You may reproduce and distribute copies of the
93
+ Work or Derivative Works thereof in any medium, with or without
94
+ modifications, and in Source or Object form, provided that You
95
+ meet the following conditions:
96
+
97
+ (a) You must give any other recipients of the Work or
98
+ Derivative Works a copy of this License; and
99
+
100
+ (b) You must cause any modified files to carry prominent notices
101
+ stating that You changed the files; and
102
+
103
+ (c) You must retain, in the Source form of any Derivative Works
104
+ that You distribute, all copyright, patent, trademark, and
105
+ attribution notices from the Source form of the Work,
106
+ excluding those notices that do not pertain to any part of
107
+ the Derivative Works; and
108
+
109
+ (d) If the Work includes a "NOTICE" text file as part of its
110
+ distribution, then any Derivative Works that You distribute must
111
+ include a readable copy of the attribution notices contained
112
+ within such NOTICE file, excluding those notices that do not
113
+ pertain to any part of the Derivative Works, in at least one
114
+ of the following places: within a NOTICE text file distributed
115
+ as part of the Derivative Works; within the Source form or
116
+ documentation, if provided along with the Derivative Works; or,
117
+ within a display generated by the Derivative Works, if and
118
+ wherever such third-party notices normally appear. The contents
119
+ of the NOTICE file are for informational purposes only and
120
+ do not modify the License. You may add Your own attribution
121
+ notices within Derivative Works that You distribute, alongside
122
+ or as an addendum to the NOTICE text from the Work, provided
123
+ that such additional attribution notices cannot be construed
124
+ as modifying the License.
125
+
126
+ You may add Your own copyright statement to Your modifications and
127
+ may provide additional or different license terms and conditions
128
+ for use, reproduction, or distribution of Your modifications, or
129
+ for any such Derivative Works as a whole, provided Your use,
130
+ reproduction, and distribution of the Work otherwise complies with
131
+ the conditions stated in this License.
132
+
133
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
134
+ any Contribution intentionally submitted for inclusion in the Work
135
+ by You to the Licensor shall be under the terms and conditions of
136
+ this License, without any additional terms or conditions.
137
+ Notwithstanding the above, nothing herein shall supersede or modify
138
+ the terms of any separate license agreement you may have executed
139
+ with Licensor regarding such Contributions.
140
+
141
+ 6. Trademarks. This License does not grant permission to use the trade
142
+ names, trademarks, service marks, or product names of the Licensor,
143
+ except as required for reasonable and customary use in describing the
144
+ origin of the Work and reproducing the content of the NOTICE file.
145
+
146
+ 7. Disclaimer of Warranty. Unless required by applicable law or
147
+ agreed to in writing, Licensor provides the Work (and each
148
+ Contributor provides its Contributions) on an "AS IS" BASIS,
149
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
150
+ implied, including, without limitation, any warranties or conditions
151
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
152
+ PARTICULAR PURPOSE. You are solely responsible for determining the
153
+ appropriateness of using or redistributing the Work and assume any
154
+ risks associated with Your exercise of permissions under this License.
155
+
156
+ 8. Limitation of Liability. In no event and under no legal theory,
157
+ whether in tort (including negligence), contract, or otherwise,
158
+ unless required by applicable law (such as deliberate and grossly
159
+ negligent acts) or agreed to in writing, shall any Contributor be
160
+ liable to You for damages, including any direct, indirect, special,
161
+ incidental, or consequential damages of any character arising as a
162
+ result of this License or out of the use or inability to use the
163
+ Work (including but not limited to damages for loss of goodwill,
164
+ work stoppage, computer failure or malfunction, or any and all
165
+ other commercial damages or losses), even if such Contributor
166
+ has been advised of the possibility of such damages.
167
+
168
+ 9. Accepting Warranty or Additional Liability. While redistributing
169
+ the Work or Derivative Works thereof, You may choose to offer,
170
+ and charge a fee for, acceptance of support, warranty, indemnity,
171
+ or other liability obligations and/or rights consistent with this
172
+ License. However, in accepting such obligations, You may act only
173
+ on Your own behalf and on Your sole responsibility, not on behalf
174
+ of any other Contributor, and only if You agree to indemnify,
175
+ defend, and hold each Contributor harmless for any liability
176
+ incurred by, or claims asserted against, such Contributor by reason
177
+ of your accepting any such warranty or additional liability.
178
+
179
+ END OF TERMS AND CONDITIONS
180
+
181
+ APPENDIX: How to apply the Apache License to your work.
182
+
183
+ To apply the Apache License to your work, attach the following
184
+ boilerplate notice, with the fields enclosed by brackets "[]"
185
+ replaced with your own identifying information. (Don't include
186
+ the brackets!) The text should be enclosed in the appropriate
187
+ comment syntax for the file format. We also recommend that a
188
+ file or class name and description of purpose be included on the
189
+ same "printed page" as the copyright notice for easier
190
+ identification within third-party archives.
191
+
192
+ Copyright [yyyy] [name of copyright owner]
193
+
194
+ Licensed under the Apache License, Version 2.0 (the "License");
195
+ you may not use this file except in compliance with the License.
196
+ You may obtain a copy of the License at
197
+
198
+ http://www.apache.org/licenses/LICENSE-2.0
199
+
200
+ Unless required by applicable law or agreed to in writing, software
201
+ distributed under the License is distributed on an "AS IS" BASIS,
202
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
203
+ See the License for the specific language governing permissions and
204
+ limitations under the License.
epicl/_sdm/VENDORED.md ADDED
@@ -0,0 +1,31 @@
1
+ # Vendored copy of NVIDIA structured-data-models (`sdm`)
2
+
3
+ This folder is a frozen copy of the `sdm` package from
4
+ [NVIDIA/structured-data-models](https://github.com/NVIDIA/structured-data-models): the version the EpICL models were
5
+ trained and evaluated with. It builds Kumo-Tabular's network, whose frozen trunk EpICL runs, and runs Kumo-Tabular's
6
+ own preprocessing recipe and estimator ensemble (EpICL's views, and the marginals of `KumoEpiRegressor`). Keeping a copy means later
7
+ changes upstream (the code was reorganised since) cannot change or break this package. It is licensed under the
8
+ Apache License 2.0 (`LICENSE`, Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES).
9
+
10
+ Modifications made to the original files (Apache License 2.0, section 4(b)):
11
+
12
+ - Every `import sdm...` / `from sdm...` was rewritten to `epicl._sdm...`, so this copy never clashes with an installed
13
+ `sdm`.
14
+ - Removed the parts that Kumo-Tabular regression does not use: `models/tabiclv2` (code; its `LICENSE` is kept for
15
+ `nn/scaling.py`), `models/tabfm` (except `cell_embedding.py` and its `LICENSE`), `models/timesfm3`,
16
+ `models/kumo/relational`, `models/kumo/timeseries`, `explain`, `evaluation`.
17
+ - `__init__.py`, `models/__init__.py`, `models/kumo/__init__.py`, `models/tabfm/__init__.py`: reduced to the kept
18
+ parts. `__version__` is fixed to `"0+vendored"`.
19
+ - `nn/scaling.py`: the path of the TabICLv2 licence in its header.
20
+ - The pretrained-weight download (`KumoTabular(pretrained=True)`) is never called: `epicl` loads Kumo-Tabular's
21
+ weights from its own release.
22
+
23
+ Each of the 93 modified files says so under its header, in a line starting with `Modified by the EpICL authors`. The
24
+ 19 other Python files are unchanged copies.
25
+
26
+ Third-party code inside this copy, with its licence:
27
+
28
+ - `nn/scaling.py`: derived from TabICLv2, BSD 3-Clause, `models/tabiclv2/LICENSE`.
29
+ - `nn/glu.py`, `nn/softplus.py`, `models/tabfm/cell_embedding.py`: derived from TabFM, Apache License 2.0,
30
+ `models/tabfm/LICENSE`.
31
+ - `models/ecoc.py`: derived from TabPFN Extensions, Apache License 2.0, `third_party/tabpfn-extensions/LICENSE`.
epicl/_sdm/__init__.py ADDED
@@ -0,0 +1,53 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ # Modified by the EpICL authors (2026): reduced to the parts kept in this copy, import paths renamed
4
+ # to epicl._sdm. See epicl/_sdm/VENDORED.md.
5
+
6
+ """Structured data modeling primitives."""
7
+
8
+ from epicl._sdm._constants import NaT
9
+ from epicl._sdm.stype import Stype, StypeLike, infer_stypes
10
+ from epicl._sdm.task import Task, TaskLike
11
+ from epicl._sdm.tensor import (
12
+ VarLenTensor,
13
+ StringTensor,
14
+ NullableTensor,
15
+ CategoricalTensor,
16
+ ColumnarTensor,
17
+ TableTensor,
18
+ )
19
+ from epicl._sdm.ensemble import EnsembleData, EnsembleTable
20
+ from epicl._sdm.relational import (
21
+ Relationship,
22
+ RelationalData,
23
+ TaskLink,
24
+ RelatedTables,
25
+ )
26
+ from epicl._sdm.processing import Recipe
27
+ from epicl._sdm import models
28
+
29
+ __version__ = "0+vendored" # a frozen copy, see epicl/_sdm/VENDORED.md
30
+
31
+ __all__ = [
32
+ "NaT",
33
+ "Stype",
34
+ "StypeLike",
35
+ "Task",
36
+ "TaskLike",
37
+ "infer_stypes",
38
+ "VarLenTensor",
39
+ "StringTensor",
40
+ "NullableTensor",
41
+ "CategoricalTensor",
42
+ "ColumnarTensor",
43
+ "TableTensor",
44
+ "EnsembleData",
45
+ "EnsembleTable",
46
+ "Relationship",
47
+ "RelationalData",
48
+ "TaskLink",
49
+ "RelatedTables",
50
+ "Recipe",
51
+ "models",
52
+ "__version__",
53
+ ]
@@ -0,0 +1,6 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ from typing import Final
5
+
6
+ NaT: Final[int] = -9223372036854775808 # torch.iinfo(torch.int64).min
@@ -0,0 +1,42 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ import contextlib
5
+ from collections.abc import Iterator
6
+ from typing import Literal
7
+
8
+ import torch
9
+
10
+
11
+ @contextlib.contextmanager
12
+ def inference_mode(
13
+ mode: Literal["inference", "no_grad", "grad", "none"] = "inference",
14
+ ) -> Iterator[None]:
15
+ r"""Context manager to adjust PyTorch inference and autograd states.
16
+
17
+ Args:
18
+ mode: The desired mode. ``"inference"`` runs under
19
+ :func:`torch.inference_mode` (falling back to :func:`torch.no_grad`
20
+ inside compiled regions), ``"no_grad"`` runs under
21
+ :func:`torch.no_grad`, ``"grad"`` runs under
22
+ :func:`torch.enable_grad`, and ``"none"`` preserves the ambient
23
+ PyTorch context.
24
+ """
25
+ if mode == "inference":
26
+ # `torch.inference_mode` is not supported inside a compiled region:
27
+ # https://github.com/pytorch/pytorch/issues/180823
28
+ context = (
29
+ torch.no_grad()
30
+ if torch.compiler.is_compiling()
31
+ else torch.inference_mode()
32
+ )
33
+ elif mode == "no_grad":
34
+ context = torch.no_grad()
35
+ elif mode == "grad":
36
+ context = torch.enable_grad()
37
+ else:
38
+ assert mode == "none"
39
+ context = contextlib.nullcontext()
40
+
41
+ with context:
42
+ yield
@@ -0,0 +1,11 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ # Modified by the EpICL authors (2026): import paths renamed to epicl._sdm. See epicl/_sdm/VENDORED.md.
4
+
5
+ from epicl._sdm._kernels.segment_multi_reduce import segment_multi_reduce
6
+ from epicl._sdm._kernels.rmsnorm_cast import rmsnorm_cast
7
+
8
+ __all__ = [
9
+ "segment_multi_reduce",
10
+ "rmsnorm_cast",
11
+ ]
@@ -0,0 +1,93 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ # Modified by the EpICL authors (2026): import paths renamed to epicl._sdm. See epicl/_sdm/VENDORED.md.
4
+
5
+ from collections.abc import Callable
6
+ from typing import TypeAlias
7
+
8
+ import torch
9
+ import torch.nn.functional as F
10
+ from torch import Tensor
11
+
12
+ _RMSNormCast: TypeAlias = Callable[
13
+ [Tensor, Tensor | None, float, tuple[Tensor, Tensor] | None], Tensor
14
+ ]
15
+
16
+ _triton_rmsnorm_cast: _RMSNormCast | None = None
17
+ try:
18
+ from epicl._sdm._kernels.triton.rmsnorm_cast import (
19
+ rmsnorm_cast as _triton_rmsnorm_cast_impl,
20
+ )
21
+ except ImportError:
22
+ pass
23
+ else:
24
+ _triton_rmsnorm_cast = _triton_rmsnorm_cast_impl
25
+
26
+
27
+ def rmsnorm_cast(
28
+ x: Tensor,
29
+ weight: Tensor | None,
30
+ eps: float,
31
+ rope: tuple[Tensor, Tensor] | None = None,
32
+ ) -> Tensor:
33
+ """Apply RMSNorm over the last dimension and cast to the autocast dtype.
34
+
35
+ The output uses the configured autocast dtype for the input device,
36
+ even when autocast is disabled.
37
+
38
+ Args:
39
+ x: Input tensor with shape ``[..., C]``, where ``C`` is the number
40
+ of channels.
41
+ weight: Scale tensor with shape ``[C]``, or ``None`` for no scaling.
42
+ eps: Constant added to the mean square before normalization.
43
+ rope: Optional cosine and sine tables with shape ``[S, C // 2]``
44
+ for split-half rotary embeddings. The input then has shape
45
+ ``[..., S, H, C]``, where ``S`` is the sequence length and ``H``
46
+ is the number of heads. Rotation rounds in the input dtype.
47
+ """
48
+ if (
49
+ _triton_rmsnorm_cast is not None
50
+ and x.is_cuda
51
+ and x.dtype in {torch.float16, torch.bfloat16, torch.float32}
52
+ and x.size(-1) in {32, 64, 128, 256, 512}
53
+ and (
54
+ weight is None
55
+ or (
56
+ weight.dtype in {torch.float16, torch.bfloat16, torch.float32}
57
+ and weight.device == x.device
58
+ and weight.shape == x.shape[-1:]
59
+ )
60
+ )
61
+ and (
62
+ rope is None
63
+ or (
64
+ x.dim() >= 3
65
+ and all(
66
+ table.shape == (x.size(-3), x.size(-1) // 2)
67
+ and table.dtype == x.dtype
68
+ and table.device == x.device
69
+ for table in rope
70
+ )
71
+ )
72
+ )
73
+ and x.numel() > 0
74
+ and not (
75
+ (
76
+ x.requires_grad
77
+ or (weight is not None and weight.requires_grad)
78
+ or (
79
+ rope is not None
80
+ and any(table.requires_grad for table in rope)
81
+ )
82
+ )
83
+ and torch.is_grad_enabled()
84
+ )
85
+ ):
86
+ return _triton_rmsnorm_cast(x, weight, eps, rope)
87
+ if rope is not None:
88
+ cos, sin = (table.unsqueeze(-2) for table in rope)
89
+ x1, x2 = x.chunk(2, dim=-1)
90
+ x = torch.cat((x1 * cos - x2 * sin, x2 * cos + x1 * sin), dim=-1)
91
+ return F.rms_norm(x, (x.size(-1),), weight, eps).to(
92
+ torch.get_autocast_dtype(x.device.type)
93
+ )
@@ -0,0 +1,142 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ # Modified by the EpICL authors (2026): import paths renamed to epicl._sdm. See epicl/_sdm/VENDORED.md.
4
+
5
+ from collections.abc import Callable
6
+ from typing import TypeAlias
7
+
8
+ import torch
9
+ from torch import Tensor
10
+
11
+ _SegmentMultiReduce: TypeAlias = Callable[
12
+ [Tensor, Tensor, Tensor, Tensor, Tensor | None],
13
+ Tensor,
14
+ ]
15
+
16
+ _triton_segment_multi_reduce: _SegmentMultiReduce | None = None
17
+ try:
18
+ from epicl._sdm._kernels.triton.segment_multi_reduce import (
19
+ segment_multi_reduce as _triton_segment_multi_reduce_impl,
20
+ )
21
+ except ImportError:
22
+ pass
23
+ else:
24
+ _triton_segment_multi_reduce = _triton_segment_multi_reduce_impl
25
+
26
+
27
+ def _eager_segment_multi_reduce(
28
+ src: Tensor,
29
+ index: Tensor,
30
+ edge_attr: Tensor,
31
+ offsets: Tensor,
32
+ edge_type: Tensor | None = None,
33
+ ) -> Tensor:
34
+ if edge_type is not None:
35
+ edge_attr = edge_attr[edge_type]
36
+ values = src[index]
37
+ if src.dtype in {torch.float16, torch.bfloat16}:
38
+ values = values.float() + edge_attr.float()
39
+ else:
40
+ values = values + edge_attr
41
+ total = torch.segment_reduce(
42
+ values,
43
+ offsets=offsets,
44
+ reduce="sum",
45
+ unsafe=True,
46
+ initial=0,
47
+ )
48
+ mean = total / offsets.diff().clamp(min=1).unsqueeze(1)
49
+ variance = (
50
+ torch.segment_reduce(
51
+ values.square(),
52
+ offsets=offsets,
53
+ reduce="mean",
54
+ unsafe=True,
55
+ initial=0,
56
+ )
57
+ - mean.square()
58
+ )
59
+ std = torch.where(
60
+ variance <= 1e-5,
61
+ 0.0,
62
+ variance.clamp(min=1e-5).sqrt(),
63
+ )
64
+ minimum = torch.segment_reduce(
65
+ values,
66
+ offsets=offsets,
67
+ reduce="min",
68
+ unsafe=True,
69
+ )
70
+ maximum = torch.segment_reduce(
71
+ values,
72
+ offsets=offsets,
73
+ reduce="max",
74
+ unsafe=True,
75
+ )
76
+ minimum = torch.where(minimum.isinf(), 0.0, minimum)
77
+ maximum = torch.where(maximum.isinf(), 0.0, maximum)
78
+ return torch.stack(
79
+ (
80
+ total,
81
+ mean,
82
+ std,
83
+ minimum,
84
+ maximum,
85
+ ),
86
+ dim=1,
87
+ ).to(src.dtype)
88
+
89
+
90
+ def segment_multi_reduce(
91
+ src: Tensor,
92
+ index: Tensor,
93
+ edge_attr: Tensor,
94
+ offsets: Tensor,
95
+ edge_type: Tensor | None = None,
96
+ ) -> Tensor:
97
+ edge_attr_matches = (
98
+ edge_attr.shape == (index.numel(), src.size(1))
99
+ if edge_type is None
100
+ else (
101
+ edge_attr.dim() == 2
102
+ and edge_attr.size(1) == src.size(1)
103
+ and edge_type.numel() == index.numel()
104
+ )
105
+ )
106
+ if (
107
+ _triton_segment_multi_reduce is not None
108
+ and not (
109
+ (src.requires_grad or edge_attr.requires_grad)
110
+ and torch.is_grad_enabled()
111
+ )
112
+ and src.is_cuda
113
+ and src.dtype in {torch.float16, torch.bfloat16, torch.float32}
114
+ and edge_attr.dtype == src.dtype
115
+ and (
116
+ edge_type is None
117
+ or (
118
+ edge_type.device == src.device
119
+ and edge_type.dtype in {torch.int32, torch.int64}
120
+ )
121
+ )
122
+ and index.device == src.device
123
+ and edge_attr.device == src.device
124
+ and offsets.device == src.device
125
+ and index.dtype in {torch.int32, torch.int64}
126
+ and offsets.dtype in {torch.int32, torch.int64}
127
+ and edge_attr_matches
128
+ ):
129
+ return _triton_segment_multi_reduce(
130
+ src,
131
+ index,
132
+ edge_attr,
133
+ offsets,
134
+ edge_type,
135
+ )
136
+ return _eager_segment_multi_reduce(
137
+ src,
138
+ index,
139
+ edge_attr,
140
+ offsets,
141
+ edge_type,
142
+ )
@@ -0,0 +1,7 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ import sys
5
+
6
+ if sys.platform != "linux":
7
+ raise ImportError("Triton kernels are only available on Linux")