dawin 1.0.1__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.
- dawin-1.0.1/LICENSE +21 -0
- dawin-1.0.1/PKG-INFO +196 -0
- dawin-1.0.1/README.md +162 -0
- dawin-1.0.1/dawin/__init__.py +20 -0
- dawin-1.0.1/dawin/core.py +212 -0
- dawin-1.0.1/dawin/models.py +760 -0
- dawin-1.0.1/dawin/triton_scan.py +848 -0
- dawin-1.0.1/dawin.egg-info/PKG-INFO +196 -0
- dawin-1.0.1/dawin.egg-info/SOURCES.txt +12 -0
- dawin-1.0.1/dawin.egg-info/dependency_links.txt +1 -0
- dawin-1.0.1/dawin.egg-info/requires.txt +12 -0
- dawin-1.0.1/dawin.egg-info/top_level.txt +1 -0
- dawin-1.0.1/pyproject.toml +60 -0
- dawin-1.0.1/setup.cfg +4 -0
dawin-1.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Byunggu Yu and Junwhan Kim
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
dawin-1.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dawin
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Damped Atomic Wave Integration Neurons (DAWIN): A Universal Primitive for Continuous-Time Spatiotemporal Learning
|
|
5
|
+
Author-email: Byunggu Yu <byu@udc.edu>, Justin Kim <junwhan.kim@udc.edu>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/yumakemore/DAWIN
|
|
8
|
+
Project-URL: Documentation, https://github.com
|
|
9
|
+
Project-URL: Repository, https://github.com/yumakemore/DAWIN
|
|
10
|
+
Project-URL: Paper, https://arxiv.org/abs/2611.30025
|
|
11
|
+
Project-URL: Archive, https://doi.org/10.5281/zenodo.24485897
|
|
12
|
+
Keywords: deep-learning,continuous-time,irregular-time-series,state-space-models,pytorch,triton
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: torch>=2.4.0
|
|
24
|
+
Requires-Dist: numpy>=1.24.0
|
|
25
|
+
Provides-Extra: triton
|
|
26
|
+
Requires-Dist: triton>=3.0.0; extra == "triton"
|
|
27
|
+
Provides-Extra: benchmarks
|
|
28
|
+
Requires-Dist: scipy>=1.11.0; extra == "benchmarks"
|
|
29
|
+
Requires-Dist: pandas>=2.0.0; extra == "benchmarks"
|
|
30
|
+
Requires-Dist: matplotlib>=3.8.0; extra == "benchmarks"
|
|
31
|
+
Requires-Dist: gymnasium[mujoco]>=0.29.0; extra == "benchmarks"
|
|
32
|
+
Requires-Dist: scikit-learn>=1.3.0; extra == "benchmarks"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# Damped Atomic Wave Integration Neurons (DAWIN)
|
|
36
|
+
|
|
37
|
+
[](LICENSE)
|
|
38
|
+
[](https://arxiv.org/abs/2611.30025)
|
|
39
|
+
[](https://doi.org/10.5281/zenodo.24485897)
|
|
40
|
+
[](https://www.python.org/)
|
|
41
|
+
[](https://pytorch.org/)
|
|
42
|
+
[](https://triton-lang.org/)
|
|
43
|
+
[](https://colab.research.google.com/github/yumakemore/DAWIN/blob/main/DAWIN_10seed.ipynb)
|
|
44
|
+
|
|
45
|
+
Official PyTorch and Triton reference implementation for **["Damped Atomic Wave Integration Neurons (DAWIN): A Universal Primitive for Continuous-Time Spatiotemporal Learning"](https://arxiv.org/abs/2611.30025)** ([PDF](https://arxiv.org/pdf/2611.30025)) by Byunggu Yu and Justin Kim (University of the District of Columbia).
|
|
46
|
+
.
|
|
47
|
+
|
|
48
|
+
DAWIN serves as a drop-in, architecture-agnostic replacement for the conventional perceptron $y = \sigma(\mathbf{w}^\top \mathbf{x} + b)$. For each unit $m$, DAWIN combines spatial wave phase and continuous-time Zero-Order Hold (ZOH) interval scaling into an indivisible (*atomic*) complex wave packet $u_{i,m}$ and integrates it into a neuron-local state $\psi_{i,m} \in \mathbb{C}$ via:
|
|
49
|
+
|
|
50
|
+
$$
|
|
51
|
+
u_{i,m} = A_m \alpha_m(\Delta t_i) \exp\big(i(\mathbf{k}_m^\top \mathbf{x}_i - \theta_m)\big), \qquad \psi_{i,m} = \exp\big(-(\gamma_m + i\omega_m)\Delta t_i\big)\psi_{i-1,m} + u_{i,m}
|
|
52
|
+
$$
|
|
53
|
+
|
|
54
|
+
where $\alpha_m(\Delta t_i) = 1 - e^{-\gamma_m \Delta t_i}$ for $\Delta t_i > 0$ and $\alpha_m(0) = 1$.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Drop-In Usage Example
|
|
59
|
+
|
|
60
|
+
`DAWINLinear` (and its fused CUDA kernel `TritonDAWINLinear`) replaces `nn.Linear + Activation` anywhere in a model while propagating continuous-time complex quadrature states across irregular intervals $\Delta t_i$:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import torch
|
|
64
|
+
from dawin_core import DAWINLinear
|
|
65
|
+
|
|
66
|
+
# Batch size B=8, sequence length L=128, input dim d_in=16, hidden units M=64
|
|
67
|
+
x = torch.randn(8, 128, 16, device="cuda")
|
|
68
|
+
dt = torch.rand(8, 128, device="cuda") * 0.5 # irregular elapsed intervals
|
|
69
|
+
|
|
70
|
+
# Hidden layer emits paired real/imaginary quadratures [B, L, 2*M]
|
|
71
|
+
hidden_layer = DAWINLinear(in_features=16, out_features=64, mode="quad").cuda()
|
|
72
|
+
# Readout layer emits real quadrature [B, L, M]
|
|
73
|
+
out_layer = DAWINLinear(in_features=128, out_features=4, mode="real").cuda()
|
|
74
|
+
|
|
75
|
+
h = hidden_layer(x, dt) # [8, 128, 128]
|
|
76
|
+
y = out_layer(h, dt) # [8, 128, 4]
|
|
77
|
+
reg_loss = hidden_layer.laplacian_penalty() # closed-form spatiotemporal curvature penalty
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Repository Structure
|
|
83
|
+
|
|
84
|
+
### Core Model, Kernel & Dataset Modules
|
|
85
|
+
* `dawin_core.py`: Drop-in `DAWINLinear` primitive with paired-real quadrature propagation, parallel associative prefix scan (`torch._higher_order_ops.associative_scan`), exact serial fallback, component ablation toggles (`none`, `undamped`, `memoryless`, `cosine_only`, `decoupled`), and closed-form spatiotemporal Laplacian curvature regularization (`laplacian_penalty()`, `compute_dawin_laplacian_loss()`).
|
|
86
|
+
* `dawin_triton.py`: Multi-block chunked Triton parallel associative scan kernel and custom autograd bridge supporting arbitrarily long sequences ($L > 4096$) in $O(\log L)$ parallel depth without materializing intermediate complex $[B, L, M]$ tensors in HBM.
|
|
87
|
+
* `dawin_models.py`: Drop-in continuous-time backbones (`DAWINMLP`, `DAWINTransformer`, `DAWINGNN`) with automatic CUDA Triton dispatch (`use_triton=True`), alongside parameter-matched comparators (`MatchedReLUMLP`, `MatchedTimeTransformer`, `MatchedNeuralCDE`, `MatchedS5`, `MatchedMamba`, `MatchedGRUGNN`) and `find_matched_width` ($\le 2\%$ parameter parity).
|
|
88
|
+
* `dawin_datasets.py`: Standardized data loaders, training-only normalization pipelines, and task metrics for MuJoCo irregular dynamics (`HalfCheetah-v5`, `Hopper-v5`, `Reacher-v5`, `Walker2d-v5`), PhysioNet Challenge 2012 (mask-aware mortality, mask-aware imputation, and dense WSP displacement), and ETH/UCY + JAAD trajectories.
|
|
89
|
+
* `dawin_diagnostics.py`: RQ3 $\Delta t$-intervention diagnostics (true, batch-shuffled $\Delta t_{\text{perm}}$, and constant-mean $\Delta t_{\text{const}}$), RQ4 GPU throughput/memory profiling, and 20,000-resample paired bootstrap / Holm-Bonferroni significance tests.
|
|
90
|
+
|
|
91
|
+
### Experiment Runners, Exporters & Plotting Scripts
|
|
92
|
+
* `run_dawin_experiments.py`: Executes 10-seed (`101`–`110`) parameter-matched sweeps for a single task with configurable `--precision` (`fp32`, `bf16`, `fp16`) and writes `.json`, `.csv`, and `.md` summaries.
|
|
93
|
+
* `run_all_dawin_benchmarks.py`: Orchestrates sequential 10-seed sweeps across all 11 benchmark tasks, runs the `--profile-b200` RQ4 GPU scaling suite, and automatically compiles LaTeX tables and publication figures.
|
|
94
|
+
* `export_dawin_latex_tables.py`: Compiles `master_benchmark_summary_<precision>.json` and `rq4_b200_scaling_<precision>.json` into venue-agnostic (`generic`, outputting `dawin_tables_<precision>.tex`) or venue-specific (`neurips`, `iclr`, `icml`) LaTeX `booktabs` tables.
|
|
95
|
+
* `plot_dawin_figures.py`: Renders publication-ready vector (`.pdf`) and raster (`.png`) figures for RQ1/RQ2 accuracy comparisons, RQ3 causal timing interventions, and RQ4 NVIDIA B200 GPU scaling curves.
|
|
96
|
+
|
|
97
|
+
### Verification Suites & Interactive Notebook
|
|
98
|
+
* `verify_dawin_harness.py`: Validates serial-vs-scan equivalence, BIBO stability under spatial outliers ($\|\mathbf{x}\| \sim 10^6$), parameter parity, Triton-vs-PyTorch backbone gradient parity, and the end-to-end synthetic-to-LaTeX-and-figures pipeline.
|
|
99
|
+
* `verify_extended_comparators.py`: Validates forward shapes, parameter parity ($\le 2\%$), and gradient flow across all parameter-matched comparators.
|
|
100
|
+
* `verify_dawin_datasets.py`: Validates tensor shapes, non-negative $\Delta t$ invariants, and evaluation metrics across all 11 benchmark configurations.
|
|
101
|
+
* `verify_triton_dawin.py`: Verifies numerical parity of the multi-block Triton kernel under `FP32`, `BF16`, and `FP16` autocast and benchmarks GPU latency.
|
|
102
|
+
* [`DAWIN_10seed.ipynb`](DAWIN_10seed.ipynb): Self-contained Jupyter/Colab notebook for interactive GPU execution and result inspection.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Installation & Runtime Policy
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
git clone https://github.com/yumakemore/DAWIN.git
|
|
110
|
+
cd DAWIN
|
|
111
|
+
pip install -r requirements.txt
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Following our NVIDIA B200 experimental protocol, mixed-precision runs default to `--precision bf16` with matrix-multiplication TF32 disabled (`torch.backends.cuda.matmul.allow_tf32 = False`), cuDNN TF32 enabled (`torch.backends.cudnn.allow_tf32 = True`), and FP32 accumulation retained inside the associative scan recurrence.
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Quickstart & Verification
|
|
119
|
+
|
|
120
|
+
Run all four verification suites prior to launching cluster experiments:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
python verify_dawin_harness.py
|
|
124
|
+
python verify_extended_comparators.py
|
|
125
|
+
python verify_dawin_datasets.py
|
|
126
|
+
python verify_triton_dawin.py
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Interactive Execution (Google Colab)
|
|
132
|
+
|
|
133
|
+
For interactive, cell-by-cell execution on cloud GPUs (`B200`, `B100`, `G4`, `A100`, `L4`, or `T4`), open [`DAWIN_10seed.ipynb`](DAWIN_10seed.ipynb) directly in Google Colab via the badge at the top of this page.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Reproducing Benchmarks, Tables & Figures
|
|
138
|
+
|
|
139
|
+
All benchmark, profiling, and export commands save outputs to `./results_dawin` by default (override with `--results-dir <PATH>`).
|
|
140
|
+
|
|
141
|
+
### 1. Full 11-Task 10-Seed Benchmark Sweep
|
|
142
|
+
```bash
|
|
143
|
+
python run_all_dawin_benchmarks.py --precision bf16 --laplacian-weight 1e-4 --device cuda:0
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### 2. Standalone RQ4 GPU Throughput & Memory Profiling (BF16)
|
|
147
|
+
```bash
|
|
148
|
+
python run_all_dawin_benchmarks.py --profile-only --precision bf16 --device cuda:0
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### 3. Single-Task 10-Seed Sweep & Manual Table/Figure Export
|
|
152
|
+
```bash
|
|
153
|
+
python run_all_dawin_benchmarks.py --tasks HalfCheetah-v5 --precision bf16 --laplacian-weight 1e-4 --force
|
|
154
|
+
python export_dawin_latex_tables.py --results-dir results_dawin --precision bf16 --venue generic
|
|
155
|
+
python plot_dawin_figures.py --results-dir results_dawin --precision bf16 --formats pdf png
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Generated Output Artifacts
|
|
159
|
+
Running the benchmark and export scripts populates `./results_dawin` with:
|
|
160
|
+
* `master_benchmark_summary_<precision>.{json,csv,md}`: Aggregated 10-seed Mean ± SD, paired differences, 95% bootstrap CIs, Holm-Bonferroni p-values, and RQ3 $\Delta t$-intervention results.
|
|
161
|
+
* `rq4_b200_scaling_<precision>.{json,csv,md}`: GPU latency (`ms`), transition throughput (`transitions/s`), and peak VRAM (`MiB`) across batch sizes `1, 16, 256, 4096`.
|
|
162
|
+
* `dawin_tables_<precision>.tex`: Ready-to-include LaTeX `booktabs` tables (`\begin{table*}`).
|
|
163
|
+
* `figures/fig_rq*.{pdf,png}`: Publication-ready accuracy comparison, timing-intervention, and scaling figures.
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Citation
|
|
168
|
+
|
|
169
|
+
If you find DAWIN useful in your research, please cite both the paper and the software archive:
|
|
170
|
+
|
|
171
|
+
```bibtex
|
|
172
|
+
@article{yu2026dawin,
|
|
173
|
+
title = {Damped Atomic Wave Integration Neurons (DAWIN): A Universal Primitive for Continuous-Time Spatiotemporal Learning},
|
|
174
|
+
author = {Yu, Byunggu and Kim, Justin},
|
|
175
|
+
year = {2026},
|
|
176
|
+
eprint = {2611.30025},
|
|
177
|
+
archivePrefix = {arXiv},
|
|
178
|
+
primaryClass = {cs.LG},
|
|
179
|
+
doi = {10.48550/arXiv.2611.30025},
|
|
180
|
+
url = {https://arxiv.org/abs/2611.30025}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
@software{yu2026dawin_code,
|
|
184
|
+
author = {Yu, Byunggu and Kim, Justin},
|
|
185
|
+
title = {DAWIN: Damped Atomic Wave Integration Neurons (PyTorch \& Triton Reference Implementation)},
|
|
186
|
+
year = {2026},
|
|
187
|
+
publisher = {Zenodo},
|
|
188
|
+
version = {v1.0.0},
|
|
189
|
+
doi = {10.5281/zenodo.24485897},
|
|
190
|
+
url = {https://doi.org/10.5281/zenodo.24485897}
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
This project is released under the [MIT License](LICENSE).
|
dawin-1.0.1/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Damped Atomic Wave Integration Neurons (DAWIN)
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](https://arxiv.org/abs/2611.30025)
|
|
5
|
+
[](https://doi.org/10.5281/zenodo.24485897)
|
|
6
|
+
[](https://www.python.org/)
|
|
7
|
+
[](https://pytorch.org/)
|
|
8
|
+
[](https://triton-lang.org/)
|
|
9
|
+
[](https://colab.research.google.com/github/yumakemore/DAWIN/blob/main/DAWIN_10seed.ipynb)
|
|
10
|
+
|
|
11
|
+
Official PyTorch and Triton reference implementation for **["Damped Atomic Wave Integration Neurons (DAWIN): A Universal Primitive for Continuous-Time Spatiotemporal Learning"](https://arxiv.org/abs/2611.30025)** ([PDF](https://arxiv.org/pdf/2611.30025)) by Byunggu Yu and Justin Kim (University of the District of Columbia).
|
|
12
|
+
.
|
|
13
|
+
|
|
14
|
+
DAWIN serves as a drop-in, architecture-agnostic replacement for the conventional perceptron $y = \sigma(\mathbf{w}^\top \mathbf{x} + b)$. For each unit $m$, DAWIN combines spatial wave phase and continuous-time Zero-Order Hold (ZOH) interval scaling into an indivisible (*atomic*) complex wave packet $u_{i,m}$ and integrates it into a neuron-local state $\psi_{i,m} \in \mathbb{C}$ via:
|
|
15
|
+
|
|
16
|
+
$$
|
|
17
|
+
u_{i,m} = A_m \alpha_m(\Delta t_i) \exp\big(i(\mathbf{k}_m^\top \mathbf{x}_i - \theta_m)\big), \qquad \psi_{i,m} = \exp\big(-(\gamma_m + i\omega_m)\Delta t_i\big)\psi_{i-1,m} + u_{i,m}
|
|
18
|
+
$$
|
|
19
|
+
|
|
20
|
+
where $\alpha_m(\Delta t_i) = 1 - e^{-\gamma_m \Delta t_i}$ for $\Delta t_i > 0$ and $\alpha_m(0) = 1$.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Drop-In Usage Example
|
|
25
|
+
|
|
26
|
+
`DAWINLinear` (and its fused CUDA kernel `TritonDAWINLinear`) replaces `nn.Linear + Activation` anywhere in a model while propagating continuous-time complex quadrature states across irregular intervals $\Delta t_i$:
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import torch
|
|
30
|
+
from dawin_core import DAWINLinear
|
|
31
|
+
|
|
32
|
+
# Batch size B=8, sequence length L=128, input dim d_in=16, hidden units M=64
|
|
33
|
+
x = torch.randn(8, 128, 16, device="cuda")
|
|
34
|
+
dt = torch.rand(8, 128, device="cuda") * 0.5 # irregular elapsed intervals
|
|
35
|
+
|
|
36
|
+
# Hidden layer emits paired real/imaginary quadratures [B, L, 2*M]
|
|
37
|
+
hidden_layer = DAWINLinear(in_features=16, out_features=64, mode="quad").cuda()
|
|
38
|
+
# Readout layer emits real quadrature [B, L, M]
|
|
39
|
+
out_layer = DAWINLinear(in_features=128, out_features=4, mode="real").cuda()
|
|
40
|
+
|
|
41
|
+
h = hidden_layer(x, dt) # [8, 128, 128]
|
|
42
|
+
y = out_layer(h, dt) # [8, 128, 4]
|
|
43
|
+
reg_loss = hidden_layer.laplacian_penalty() # closed-form spatiotemporal curvature penalty
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Repository Structure
|
|
49
|
+
|
|
50
|
+
### Core Model, Kernel & Dataset Modules
|
|
51
|
+
* `dawin_core.py`: Drop-in `DAWINLinear` primitive with paired-real quadrature propagation, parallel associative prefix scan (`torch._higher_order_ops.associative_scan`), exact serial fallback, component ablation toggles (`none`, `undamped`, `memoryless`, `cosine_only`, `decoupled`), and closed-form spatiotemporal Laplacian curvature regularization (`laplacian_penalty()`, `compute_dawin_laplacian_loss()`).
|
|
52
|
+
* `dawin_triton.py`: Multi-block chunked Triton parallel associative scan kernel and custom autograd bridge supporting arbitrarily long sequences ($L > 4096$) in $O(\log L)$ parallel depth without materializing intermediate complex $[B, L, M]$ tensors in HBM.
|
|
53
|
+
* `dawin_models.py`: Drop-in continuous-time backbones (`DAWINMLP`, `DAWINTransformer`, `DAWINGNN`) with automatic CUDA Triton dispatch (`use_triton=True`), alongside parameter-matched comparators (`MatchedReLUMLP`, `MatchedTimeTransformer`, `MatchedNeuralCDE`, `MatchedS5`, `MatchedMamba`, `MatchedGRUGNN`) and `find_matched_width` ($\le 2\%$ parameter parity).
|
|
54
|
+
* `dawin_datasets.py`: Standardized data loaders, training-only normalization pipelines, and task metrics for MuJoCo irregular dynamics (`HalfCheetah-v5`, `Hopper-v5`, `Reacher-v5`, `Walker2d-v5`), PhysioNet Challenge 2012 (mask-aware mortality, mask-aware imputation, and dense WSP displacement), and ETH/UCY + JAAD trajectories.
|
|
55
|
+
* `dawin_diagnostics.py`: RQ3 $\Delta t$-intervention diagnostics (true, batch-shuffled $\Delta t_{\text{perm}}$, and constant-mean $\Delta t_{\text{const}}$), RQ4 GPU throughput/memory profiling, and 20,000-resample paired bootstrap / Holm-Bonferroni significance tests.
|
|
56
|
+
|
|
57
|
+
### Experiment Runners, Exporters & Plotting Scripts
|
|
58
|
+
* `run_dawin_experiments.py`: Executes 10-seed (`101`–`110`) parameter-matched sweeps for a single task with configurable `--precision` (`fp32`, `bf16`, `fp16`) and writes `.json`, `.csv`, and `.md` summaries.
|
|
59
|
+
* `run_all_dawin_benchmarks.py`: Orchestrates sequential 10-seed sweeps across all 11 benchmark tasks, runs the `--profile-b200` RQ4 GPU scaling suite, and automatically compiles LaTeX tables and publication figures.
|
|
60
|
+
* `export_dawin_latex_tables.py`: Compiles `master_benchmark_summary_<precision>.json` and `rq4_b200_scaling_<precision>.json` into venue-agnostic (`generic`, outputting `dawin_tables_<precision>.tex`) or venue-specific (`neurips`, `iclr`, `icml`) LaTeX `booktabs` tables.
|
|
61
|
+
* `plot_dawin_figures.py`: Renders publication-ready vector (`.pdf`) and raster (`.png`) figures for RQ1/RQ2 accuracy comparisons, RQ3 causal timing interventions, and RQ4 NVIDIA B200 GPU scaling curves.
|
|
62
|
+
|
|
63
|
+
### Verification Suites & Interactive Notebook
|
|
64
|
+
* `verify_dawin_harness.py`: Validates serial-vs-scan equivalence, BIBO stability under spatial outliers ($\|\mathbf{x}\| \sim 10^6$), parameter parity, Triton-vs-PyTorch backbone gradient parity, and the end-to-end synthetic-to-LaTeX-and-figures pipeline.
|
|
65
|
+
* `verify_extended_comparators.py`: Validates forward shapes, parameter parity ($\le 2\%$), and gradient flow across all parameter-matched comparators.
|
|
66
|
+
* `verify_dawin_datasets.py`: Validates tensor shapes, non-negative $\Delta t$ invariants, and evaluation metrics across all 11 benchmark configurations.
|
|
67
|
+
* `verify_triton_dawin.py`: Verifies numerical parity of the multi-block Triton kernel under `FP32`, `BF16`, and `FP16` autocast and benchmarks GPU latency.
|
|
68
|
+
* [`DAWIN_10seed.ipynb`](DAWIN_10seed.ipynb): Self-contained Jupyter/Colab notebook for interactive GPU execution and result inspection.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Installation & Runtime Policy
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
git clone https://github.com/yumakemore/DAWIN.git
|
|
76
|
+
cd DAWIN
|
|
77
|
+
pip install -r requirements.txt
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Following our NVIDIA B200 experimental protocol, mixed-precision runs default to `--precision bf16` with matrix-multiplication TF32 disabled (`torch.backends.cuda.matmul.allow_tf32 = False`), cuDNN TF32 enabled (`torch.backends.cudnn.allow_tf32 = True`), and FP32 accumulation retained inside the associative scan recurrence.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Quickstart & Verification
|
|
85
|
+
|
|
86
|
+
Run all four verification suites prior to launching cluster experiments:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
python verify_dawin_harness.py
|
|
90
|
+
python verify_extended_comparators.py
|
|
91
|
+
python verify_dawin_datasets.py
|
|
92
|
+
python verify_triton_dawin.py
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Interactive Execution (Google Colab)
|
|
98
|
+
|
|
99
|
+
For interactive, cell-by-cell execution on cloud GPUs (`B200`, `B100`, `G4`, `A100`, `L4`, or `T4`), open [`DAWIN_10seed.ipynb`](DAWIN_10seed.ipynb) directly in Google Colab via the badge at the top of this page.
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Reproducing Benchmarks, Tables & Figures
|
|
104
|
+
|
|
105
|
+
All benchmark, profiling, and export commands save outputs to `./results_dawin` by default (override with `--results-dir <PATH>`).
|
|
106
|
+
|
|
107
|
+
### 1. Full 11-Task 10-Seed Benchmark Sweep
|
|
108
|
+
```bash
|
|
109
|
+
python run_all_dawin_benchmarks.py --precision bf16 --laplacian-weight 1e-4 --device cuda:0
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 2. Standalone RQ4 GPU Throughput & Memory Profiling (BF16)
|
|
113
|
+
```bash
|
|
114
|
+
python run_all_dawin_benchmarks.py --profile-only --precision bf16 --device cuda:0
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 3. Single-Task 10-Seed Sweep & Manual Table/Figure Export
|
|
118
|
+
```bash
|
|
119
|
+
python run_all_dawin_benchmarks.py --tasks HalfCheetah-v5 --precision bf16 --laplacian-weight 1e-4 --force
|
|
120
|
+
python export_dawin_latex_tables.py --results-dir results_dawin --precision bf16 --venue generic
|
|
121
|
+
python plot_dawin_figures.py --results-dir results_dawin --precision bf16 --formats pdf png
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Generated Output Artifacts
|
|
125
|
+
Running the benchmark and export scripts populates `./results_dawin` with:
|
|
126
|
+
* `master_benchmark_summary_<precision>.{json,csv,md}`: Aggregated 10-seed Mean ± SD, paired differences, 95% bootstrap CIs, Holm-Bonferroni p-values, and RQ3 $\Delta t$-intervention results.
|
|
127
|
+
* `rq4_b200_scaling_<precision>.{json,csv,md}`: GPU latency (`ms`), transition throughput (`transitions/s`), and peak VRAM (`MiB`) across batch sizes `1, 16, 256, 4096`.
|
|
128
|
+
* `dawin_tables_<precision>.tex`: Ready-to-include LaTeX `booktabs` tables (`\begin{table*}`).
|
|
129
|
+
* `figures/fig_rq*.{pdf,png}`: Publication-ready accuracy comparison, timing-intervention, and scaling figures.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Citation
|
|
134
|
+
|
|
135
|
+
If you find DAWIN useful in your research, please cite both the paper and the software archive:
|
|
136
|
+
|
|
137
|
+
```bibtex
|
|
138
|
+
@article{yu2026dawin,
|
|
139
|
+
title = {Damped Atomic Wave Integration Neurons (DAWIN): A Universal Primitive for Continuous-Time Spatiotemporal Learning},
|
|
140
|
+
author = {Yu, Byunggu and Kim, Justin},
|
|
141
|
+
year = {2026},
|
|
142
|
+
eprint = {2611.30025},
|
|
143
|
+
archivePrefix = {arXiv},
|
|
144
|
+
primaryClass = {cs.LG},
|
|
145
|
+
doi = {10.48550/arXiv.2611.30025},
|
|
146
|
+
url = {https://arxiv.org/abs/2611.30025}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@software{yu2026dawin_code,
|
|
150
|
+
author = {Yu, Byunggu and Kim, Justin},
|
|
151
|
+
title = {DAWIN: Damped Atomic Wave Integration Neurons (PyTorch \& Triton Reference Implementation)},
|
|
152
|
+
year = {2026},
|
|
153
|
+
publisher = {Zenodo},
|
|
154
|
+
version = {v1.0.0},
|
|
155
|
+
doi = {10.5281/zenodo.24485897},
|
|
156
|
+
url = {https://doi.org/10.5281/zenodo.24485897}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
This project is released under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from .core import DAWINLinear, compute_dawin_laplacian_loss
|
|
2
|
+
from .models import DAWINMLP, DAWINTransformer, DAWINGNN
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
from .triton_scan import TritonDAWINLinear, triton_dawin_scan
|
|
6
|
+
except ImportError:
|
|
7
|
+
TritonDAWINLinear = None
|
|
8
|
+
triton_dawin_scan = None
|
|
9
|
+
|
|
10
|
+
__version__ = "1.0.1"
|
|
11
|
+
__all__ = [
|
|
12
|
+
"DAWINLinear",
|
|
13
|
+
"TritonDAWINLinear",
|
|
14
|
+
"triton_dawin_scan",
|
|
15
|
+
"compute_dawin_laplacian_loss",
|
|
16
|
+
"DAWINMLP",
|
|
17
|
+
"DAWINTransformer",
|
|
18
|
+
"DAWINGNN",
|
|
19
|
+
]
|
|
20
|
+
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from typing import Optional, Tuple
|
|
3
|
+
import torch
|
|
4
|
+
import torch.nn as nn
|
|
5
|
+
import torch.nn.functional as F
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
from torch._higher_order_ops import associative_scan
|
|
9
|
+
HAS_ASSOC_SCAN = True
|
|
10
|
+
except ImportError:
|
|
11
|
+
HAS_ASSOC_SCAN = False
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _dawin_binary_op(
|
|
15
|
+
elem_l: Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor],
|
|
16
|
+
elem_r: Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor],
|
|
17
|
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
|
18
|
+
"""
|
|
19
|
+
Associative binary operator for paired-real complex tuples:
|
|
20
|
+
(d_r, u_r) (+) (d_l, u_l) = (d_r * d_l, d_r * u_l + u_r)
|
|
21
|
+
where d = d_re + i * d_im and u = u_re + i * u_im.
|
|
22
|
+
"""
|
|
23
|
+
d_re_l, d_im_l, u_re_l, u_im_l = elem_l
|
|
24
|
+
d_re_r, d_im_r, u_re_r, u_im_r = elem_r
|
|
25
|
+
|
|
26
|
+
# Complex multiplication: d_new = d_r * d_l
|
|
27
|
+
d_re = d_re_r * d_re_l - d_im_r * d_im_l
|
|
28
|
+
d_im = d_re_r * d_im_l + d_im_r * d_re_l
|
|
29
|
+
|
|
30
|
+
# Complex multiply-add: u_new = d_r * u_l + u_r
|
|
31
|
+
u_re = (d_re_r * u_re_l - d_im_r * u_im_l) + u_re_r
|
|
32
|
+
u_im = (d_re_r * u_im_l + d_im_r * u_re_l) + u_im_r
|
|
33
|
+
return (d_re, d_im, u_re, u_im)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class DAWINLinear(nn.Module):
|
|
37
|
+
"""
|
|
38
|
+
Damped Atomic Wave Integration Neuron (DAWIN) Layer.
|
|
39
|
+
|
|
40
|
+
Drop-in replacement for Linear + Activation blocks across MLPs, Transformers,
|
|
41
|
+
and GNNs. Supports exact parallel associative scan, serial recurrence fallback,
|
|
42
|
+
and built-in component ablation modes:
|
|
43
|
+
- 'none': Full DAWIN neuron (atomic spatiotemporal phase + damped integration)
|
|
44
|
+
- 'undamped': Removes damping (gamma = 0)
|
|
45
|
+
- 'memoryless': Instantaneous damping (gamma -> inf, recovers WFB 1.0)
|
|
46
|
+
- 'cosine_only': Zeroes imaginary quadrature propagation between steps
|
|
47
|
+
- 'decoupled': Removes spatial wavevector k^T x from phase (linear injection SSM control)
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(
|
|
51
|
+
self,
|
|
52
|
+
in_features: int,
|
|
53
|
+
out_features: int,
|
|
54
|
+
mode: str = "quad",
|
|
55
|
+
gamma_min: float = 1e-4,
|
|
56
|
+
omega_init_max: float = math.pi,
|
|
57
|
+
use_parallel_scan: bool = True,
|
|
58
|
+
ablation: str = "none",
|
|
59
|
+
):
|
|
60
|
+
super().__init__()
|
|
61
|
+
if mode not in ("real", "quad"):
|
|
62
|
+
raise ValueError(f"mode must be 'real' or 'quad', got {mode!r}")
|
|
63
|
+
if ablation not in ("none", "undamped", "memoryless", "cosine_only", "decoupled"):
|
|
64
|
+
raise ValueError(f"Unsupported ablation mode: {ablation!r}")
|
|
65
|
+
|
|
66
|
+
self.in_features = in_features
|
|
67
|
+
self.out_features = out_features
|
|
68
|
+
self.mode = mode
|
|
69
|
+
self.gamma_min = gamma_min
|
|
70
|
+
self.use_parallel_scan = use_parallel_scan and HAS_ASSOC_SCAN
|
|
71
|
+
self.ablation = ablation
|
|
72
|
+
|
|
73
|
+
# Learnable atomic wave & damper parameters
|
|
74
|
+
self.k = nn.Parameter(torch.randn(out_features, in_features) / math.sqrt(max(1, in_features)))
|
|
75
|
+
self.theta = nn.Parameter(torch.zeros(out_features))
|
|
76
|
+
self.omega = nn.Parameter(torch.linspace(0.1, omega_init_max, out_features))
|
|
77
|
+
self.raw_amp = nn.Parameter(torch.full((out_features,), math.log(math.e - 1.0)))
|
|
78
|
+
self.raw_gamma = nn.Parameter(torch.linspace(-2.0, 1.0, out_features))
|
|
79
|
+
|
|
80
|
+
if ablation == "decoupled":
|
|
81
|
+
self.linear_inj = nn.Linear(in_features, out_features, bias=False)
|
|
82
|
+
else:
|
|
83
|
+
self.register_parameter("linear_inj", None)
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def amplitude(self) -> torch.Tensor:
|
|
87
|
+
return F.softplus(self.raw_amp)
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def gamma(self) -> torch.Tensor:
|
|
91
|
+
if self.ablation == "undamped":
|
|
92
|
+
return torch.zeros_like(self.raw_gamma)
|
|
93
|
+
return F.softplus(self.raw_gamma) + self.gamma_min
|
|
94
|
+
|
|
95
|
+
def laplacian_penalty(self) -> torch.Tensor:
|
|
96
|
+
k = getattr(self, "k", getattr(self, "wavevector", getattr(self, "wavenumber", None)))
|
|
97
|
+
if k is None:
|
|
98
|
+
k = next(param for param in self.parameters() if param.ndim == 2)
|
|
99
|
+
k2 = k.float().pow(2).sum(dim=-1)
|
|
100
|
+
w2 = self.omega.float().pow(2) if hasattr(self, "omega") else torch.zeros_like(k2)
|
|
101
|
+
if hasattr(self, "raw_gamma"):
|
|
102
|
+
g = torch.nn.functional.softplus(self.raw_gamma.float()) + float(getattr(self, "gamma_min", 1e-4))
|
|
103
|
+
elif hasattr(self, "gamma"):
|
|
104
|
+
g = self.gamma.float() if isinstance(self.gamma, torch.Tensor) else self.gamma().float()
|
|
105
|
+
else:
|
|
106
|
+
g = torch.zeros_like(k2)
|
|
107
|
+
if hasattr(self, "amp"):
|
|
108
|
+
a = self.amp.float() if isinstance(self.amp, torch.Tensor) else self.amp().float()
|
|
109
|
+
elif hasattr(self, "raw_amp"):
|
|
110
|
+
a = torch.nn.functional.softplus(self.raw_amp.float())
|
|
111
|
+
else:
|
|
112
|
+
a = torch.ones_like(k2)
|
|
113
|
+
return (a.pow(2) * (k2 + w2 + g.pow(2)).pow(2)).mean()
|
|
114
|
+
|
|
115
|
+
def forward(
|
|
116
|
+
self,
|
|
117
|
+
x: torch.Tensor,
|
|
118
|
+
dt: Optional[torch.Tensor] = None,
|
|
119
|
+
reset_mask: Optional[torch.Tensor] = None,
|
|
120
|
+
) -> torch.Tensor:
|
|
121
|
+
"""
|
|
122
|
+
Args:
|
|
123
|
+
x: Spatial input tensor of shape [B, L, d_in]
|
|
124
|
+
dt: Non-negative elapsed intervals of shape [B, L] or [B, L, 1]
|
|
125
|
+
reset_mask: Optional binary reset mask [B, L] (1 resets carried state)
|
|
126
|
+
Returns:
|
|
127
|
+
Output tensor of shape [B, L, M] (mode='real') or [B, L, 2M] (mode='quad')
|
|
128
|
+
"""
|
|
129
|
+
B, L, _ = x.shape
|
|
130
|
+
if dt is None:
|
|
131
|
+
dt = torch.zeros(B, L, 1, device=x.device, dtype=x.dtype)
|
|
132
|
+
elif dt.dim() == 2:
|
|
133
|
+
dt = dt.unsqueeze(-1)
|
|
134
|
+
|
|
135
|
+
# Retain FP32 precision inside wave phase & recurrence scan
|
|
136
|
+
orig_dtype = x.dtype
|
|
137
|
+
x_f = x.float()
|
|
138
|
+
dt_f = dt.float().clamp(min=0.0)
|
|
139
|
+
|
|
140
|
+
amp = self.amplitude.float().view(1, 1, -1)
|
|
141
|
+
gamma = self.gamma.float().view(1, 1, -1)
|
|
142
|
+
omega = self.omega.float().view(1, 1, -1)
|
|
143
|
+
theta = self.theta.float().view(1, 1, -1)
|
|
144
|
+
|
|
145
|
+
zoh = torch.where(dt_f > 0.0, 1.0 - torch.exp(-gamma * dt_f), torch.ones_like(dt_f))
|
|
146
|
+
if self.ablation == "decoupled":
|
|
147
|
+
phi = -dt_f * omega - theta
|
|
148
|
+
inj_scale = F.linear(x_f, self.linear_inj.weight.float())
|
|
149
|
+
u_re = (inj_scale * amp * zoh) * torch.cos(phi)
|
|
150
|
+
u_im = (inj_scale * amp * zoh) * torch.sin(phi)
|
|
151
|
+
else:
|
|
152
|
+
phi = F.linear(x_f, self.k.float()) - theta
|
|
153
|
+
u_re = (amp * zoh) * torch.cos(phi)
|
|
154
|
+
u_im = (amp * zoh) * torch.sin(phi)
|
|
155
|
+
|
|
156
|
+
if self.ablation == "memoryless":
|
|
157
|
+
p = u_re
|
|
158
|
+
q = torch.zeros_like(u_im) if self.ablation == "cosine_only" else u_im
|
|
159
|
+
out = p if self.mode == "real" else torch.cat([p, q], dim=-1)
|
|
160
|
+
return out.to(orig_dtype)
|
|
161
|
+
|
|
162
|
+
decay = torch.exp(-gamma * dt_f)
|
|
163
|
+
if reset_mask is not None:
|
|
164
|
+
decay = decay * (1.0 - reset_mask.unsqueeze(-1).float())
|
|
165
|
+
|
|
166
|
+
rot_angle = -omega * dt_f
|
|
167
|
+
d_re = decay * torch.cos(rot_angle)
|
|
168
|
+
d_im = decay * torch.sin(rot_angle)
|
|
169
|
+
|
|
170
|
+
if self.ablation == "cosine_only":
|
|
171
|
+
# Ablate quadrature coupling: propagate only real scalar state
|
|
172
|
+
p_list = []
|
|
173
|
+
p_prev = torch.zeros(B, self.out_features, device=x.device, dtype=torch.float32)
|
|
174
|
+
for t in range(L):
|
|
175
|
+
p_curr = d_re[:, t] * p_prev + u_re[:, t]
|
|
176
|
+
p_list.append(p_curr)
|
|
177
|
+
p_prev = p_curr
|
|
178
|
+
p = torch.stack(p_list, dim=1)
|
|
179
|
+
q = torch.zeros_like(p)
|
|
180
|
+
elif self.use_parallel_scan and L > 1:
|
|
181
|
+
_, _, p, q = associative_scan(
|
|
182
|
+
_dawin_binary_op, (d_re, d_im, u_re, u_im), dim=1, combine_mode="generic"
|
|
183
|
+
)
|
|
184
|
+
else:
|
|
185
|
+
p_list, q_list = [], []
|
|
186
|
+
p_prev = torch.zeros(B, self.out_features, device=x.device, dtype=torch.float32)
|
|
187
|
+
q_prev = torch.zeros_like(p_prev)
|
|
188
|
+
for t in range(L):
|
|
189
|
+
p_curr = d_re[:, t] * p_prev - d_im[:, t] * q_prev + u_re[:, t]
|
|
190
|
+
q_curr = d_re[:, t] * q_prev + d_im[:, t] * p_prev + u_im[:, t]
|
|
191
|
+
p_list.append(p_curr)
|
|
192
|
+
q_list.append(q_curr)
|
|
193
|
+
p_prev, q_prev = p_curr, q_curr
|
|
194
|
+
p = torch.stack(p_list, dim=1)
|
|
195
|
+
q = torch.stack(q_list, dim=1)
|
|
196
|
+
|
|
197
|
+
out = p if self.mode == "real" else torch.cat([p, q], dim=-1)
|
|
198
|
+
return out.to(orig_dtype)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def compute_dawin_laplacian_loss(model: nn.Module) -> torch.Tensor:
|
|
202
|
+
pens = []
|
|
203
|
+
for mod in model.modules():
|
|
204
|
+
if hasattr(mod, "laplacian_penalty"):
|
|
205
|
+
pens.append(mod.laplacian_penalty())
|
|
206
|
+
elif hasattr(mod, "k") and hasattr(mod, "omega"):
|
|
207
|
+
k2 = mod.k.float().pow(2).sum(dim=-1)
|
|
208
|
+
w2 = mod.omega.float().pow(2)
|
|
209
|
+
g = (torch.nn.functional.softplus(mod.raw_gamma.float()) + float(getattr(mod, "gamma_min", 1e-4))) if hasattr(mod, "raw_gamma") else (mod.gamma.float() if hasattr(mod, "gamma") else torch.zeros_like(k2))
|
|
210
|
+
a = torch.nn.functional.softplus(mod.raw_amp.float()) if hasattr(mod, "raw_amp") else (mod.amp.float() if hasattr(mod, "amp") else torch.ones_like(k2))
|
|
211
|
+
pens.append((a.pow(2) * (k2 + w2 + g.pow(2)).pow(2)).mean())
|
|
212
|
+
return torch.stack(pens).mean() if pens else torch.zeros((), device=next(model.parameters()).device, dtype=torch.float32)
|