stackformers 6.0.0rc2__tar.gz → 6.0.0rc8__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.
Files changed (254) hide show
  1. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/CHANGELOG.md +117 -0
  2. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/PKG-INFO +1 -1
  3. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/examples/spatial_encoder.py +7 -8
  4. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/pyproject.toml +1 -1
  5. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/DEVLOG.md +194 -0
  6. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/__init__.py +2 -4
  7. stackformers-6.0.0rc8/stackformers/attention2d/README.md +145 -0
  8. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention2d/__init__.py +4 -5
  9. stackformers-6.0.0rc8/stackformers/attention2d/coordinates.py +81 -0
  10. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention2d/cross_attn_pooling.py +14 -42
  11. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention2d/factory.py +6 -13
  12. stackformers-6.0.0rc8/stackformers/attention2d/figures/window_cross_attention_2d.svg +632 -0
  13. stackformers-6.0.0rc8/stackformers/attention2d/figures/window_self_attention_2d.svg +632 -0
  14. stackformers-6.0.0rc8/stackformers/attention2d/protocols.py +55 -0
  15. stackformers-6.0.0rc8/stackformers/attention2d/query_anchors.py +84 -0
  16. stackformers-6.0.0rc8/stackformers/attention2d/self_attn.py +56 -0
  17. stackformers-6.0.0rc8/stackformers/attention2d/sequence.py +220 -0
  18. stackformers-6.0.0rc8/stackformers/attention2d/windows.py +110 -0
  19. stackformers-6.0.0rc8/stackformers/encoder2d/README.md +79 -0
  20. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/encoder2d/_callable_stage.py +3 -13
  21. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/encoder2d/encoder.py +4 -14
  22. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/encoder2d/layer.py +8 -18
  23. stackformers-6.0.0rc8/stackformers/encoder2d/protocols.py +31 -0
  24. stackformers-6.0.0rc8/stackformers/encoder2d/tokenwise.py +20 -0
  25. stackformers-6.0.0rc8/stackformers/encoder2d/window_stage.py +46 -0
  26. stackformers-6.0.0rc8/tests/attention2d/conftest.py +79 -0
  27. stackformers-6.0.0rc8/tests/attention2d/test_coordinates.py +46 -0
  28. stackformers-6.0.0rc8/tests/attention2d/test_cross_attn_pooling.py +217 -0
  29. stackformers-6.0.0rc8/tests/attention2d/test_export.py +120 -0
  30. stackformers-6.0.0rc8/tests/attention2d/test_factory.py +35 -0
  31. stackformers-6.0.0rc8/tests/attention2d/test_query_anchors.py +88 -0
  32. stackformers-6.0.0rc8/tests/attention2d/test_self_attn.py +162 -0
  33. stackformers-6.0.0rc8/tests/attention2d/test_sequence.py +126 -0
  34. stackformers-6.0.0rc8/tests/attention2d/test_windows.py +142 -0
  35. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/encoder2d/conftest.py +5 -9
  36. stackformers-6.0.0rc8/tests/encoder2d/test_encoder.py +85 -0
  37. stackformers-6.0.0rc8/tests/encoder2d/test_layer.py +57 -0
  38. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/encoder2d/test_window_stage.py +44 -32
  39. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/uv.lock +1 -1
  40. stackformers-6.0.0rc2/stackformers/attention2d/README.md +0 -243
  41. stackformers-6.0.0rc2/stackformers/attention2d/_geometry_module.py +0 -52
  42. stackformers-6.0.0rc2/stackformers/attention2d/centroid_queries.py +0 -41
  43. stackformers-6.0.0rc2/stackformers/attention2d/coordinates.py +0 -171
  44. stackformers-6.0.0rc2/stackformers/attention2d/figures/window_cross_attention_2d.svg +0 -1
  45. stackformers-6.0.0rc2/stackformers/attention2d/figures/window_self_attention_2d.svg +0 -1
  46. stackformers-6.0.0rc2/stackformers/attention2d/geometry_precision.py +0 -17
  47. stackformers-6.0.0rc2/stackformers/attention2d/packed_windows.py +0 -135
  48. stackformers-6.0.0rc2/stackformers/attention2d/protocols.py +0 -73
  49. stackformers-6.0.0rc2/stackformers/attention2d/query_anchors.py +0 -102
  50. stackformers-6.0.0rc2/stackformers/attention2d/self_attn.py +0 -82
  51. stackformers-6.0.0rc2/stackformers/attention2d/sequence.py +0 -222
  52. stackformers-6.0.0rc2/stackformers/attention2d/windows.py +0 -113
  53. stackformers-6.0.0rc2/stackformers/encoder2d/README.md +0 -147
  54. stackformers-6.0.0rc2/stackformers/encoder2d/protocols.py +0 -37
  55. stackformers-6.0.0rc2/stackformers/encoder2d/tokenwise.py +0 -53
  56. stackformers-6.0.0rc2/stackformers/encoder2d/window_stage.py +0 -74
  57. stackformers-6.0.0rc2/tests/attention2d/conftest.py +0 -41
  58. stackformers-6.0.0rc2/tests/attention2d/test_coordinates.py +0 -68
  59. stackformers-6.0.0rc2/tests/attention2d/test_cross_attn_pooling.py +0 -238
  60. stackformers-6.0.0rc2/tests/attention2d/test_export.py +0 -63
  61. stackformers-6.0.0rc2/tests/attention2d/test_packed_windows.py +0 -30
  62. stackformers-6.0.0rc2/tests/attention2d/test_query_anchors.py +0 -75
  63. stackformers-6.0.0rc2/tests/attention2d/test_self_attn.py +0 -142
  64. stackformers-6.0.0rc2/tests/attention2d/test_sequence.py +0 -104
  65. stackformers-6.0.0rc2/tests/attention2d/test_windows.py +0 -24
  66. stackformers-6.0.0rc2/tests/encoder2d/test_encoder.py +0 -91
  67. stackformers-6.0.0rc2/tests/encoder2d/test_layer.py +0 -68
  68. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/.claudeignore +0 -0
  69. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  70. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  71. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/.github/pull_request_template.md +0 -0
  72. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/.github/workflows/check.yml +0 -0
  73. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/.gitignore +0 -0
  74. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/.python-version +0 -0
  75. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/.vscode/settings.json +0 -0
  76. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/AGENTS.md +0 -0
  77. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/CITATION.cff +0 -0
  78. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/CONTRIBUTING.md +0 -0
  79. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/Justfile +0 -0
  80. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/LICENSE +0 -0
  81. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/PLAN.md +0 -0
  82. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/README.md +0 -0
  83. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/docs/api-guide.md +0 -0
  84. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/docs/assets/social-preview.jpg +0 -0
  85. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/docs/assets/social-preview.md +0 -0
  86. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/docs/compatibility.md +0 -0
  87. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/docs/improvement-plan.md +0 -0
  88. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/docs/inference.md +0 -0
  89. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/docs/research.md +0 -0
  90. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/examples/README.md +0 -0
  91. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/examples/causal_language_model.py +0 -0
  92. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/examples/encoder_decoder_onnxruntime.py +0 -0
  93. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/examples/image_encoder.py +0 -0
  94. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/examples/padded_and_packed.py +0 -0
  95. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/examples/point_cloud_encoder.py +0 -0
  96. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/examples/subclassed_encoder.py +0 -0
  97. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/pyrefly.toml +0 -0
  98. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/pytest.ini +0 -0
  99. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/ruff.toml +0 -0
  100. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/_decoder_equations.py +0 -0
  101. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/_projection_packing.py +0 -0
  102. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/_result.py +0 -0
  103. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/alignment.py +0 -0
  104. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/all_valid_decoder.py +0 -0
  105. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/README.md +0 -0
  106. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/__init__.py +0 -0
  107. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/all_valid.py +0 -0
  108. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/bias.py +0 -0
  109. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/cache.py +0 -0
  110. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/cache_validation.py +0 -0
  111. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/cached.py +0 -0
  112. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/config.py +0 -0
  113. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/cross_attn.py +0 -0
  114. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/distance_bias.py +0 -0
  115. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/factory.py +0 -0
  116. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/layout.py +0 -0
  117. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/masking.py +0 -0
  118. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/onnx_backend.py +0 -0
  119. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/ops.py +0 -0
  120. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/packed_cross_attn.py +0 -0
  121. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/packed_self_attn.py +0 -0
  122. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/protocols.py +0 -0
  123. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/self_attn.py +0 -0
  124. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/attention/varlen_backend.py +0 -0
  125. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/config.py +0 -0
  126. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/cross_attender.py +0 -0
  127. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/decoder.py +0 -0
  128. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/decoder_cache.py +0 -0
  129. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/encoder.py +0 -0
  130. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/encoder2d/__init__.py +0 -0
  131. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/DEVLOG.md +0 -0
  132. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/README.md +0 -0
  133. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/__init__.py +0 -0
  134. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/config.py +0 -0
  135. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/factory.py +0 -0
  136. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/geglu.py +0 -0
  137. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/gelu.py +0 -0
  138. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/hardswish_glu.py +0 -0
  139. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/packed_geglu.py +0 -0
  140. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/packed_hardswish_glu.py +0 -0
  141. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/packed_swiglu.py +0 -0
  142. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/protocols.py +0 -0
  143. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/relu_squared.py +0 -0
  144. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/feedforward/swiglu.py +0 -0
  145. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/layers.py +0 -0
  146. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/mlm/README.md +0 -0
  147. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/mlm/config.py +0 -0
  148. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/mlm/head.py +0 -0
  149. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/mlm/head_cosine.py +0 -0
  150. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/mlm/masking.py +0 -0
  151. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/mlm/protocols.py +0 -0
  152. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/mlm/wrapper.py +0 -0
  153. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/norm/README.md +0 -0
  154. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/norm/__init__.py +0 -0
  155. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/norm/config.py +0 -0
  156. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/norm/factory.py +0 -0
  157. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/norm/protocols.py +0 -0
  158. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/packing.py +0 -0
  159. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/positional/README.md +0 -0
  160. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/positional/__init__.py +0 -0
  161. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/positional/config.py +0 -0
  162. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/positional/factory.py +0 -0
  163. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/positional/learned.py +0 -0
  164. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/positional/none.py +0 -0
  165. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/positional/protocols.py +0 -0
  166. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/positional/rope1d.py +0 -0
  167. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/positional/rope2d.py +0 -0
  168. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/positional/rope_nd.py +0 -0
  169. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/positional/validation.py +0 -0
  170. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/preallocated_decoder.py +0 -0
  171. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/presets/README.md +0 -0
  172. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/presets/__init__.py +0 -0
  173. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/presets/cross_attender.py +0 -0
  174. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/presets/decoder.py +0 -0
  175. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/presets/encoder.py +0 -0
  176. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/presets/variable_width_encoder.py +0 -0
  177. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/py.typed +0 -0
  178. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/result/README.md +0 -0
  179. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/result/__init__.py +0 -0
  180. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/stackformers/sequence.py +0 -0
  181. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/__init__.py +0 -0
  182. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/__init__.py +0 -0
  183. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/legacy_api_rc1.json +0 -0
  184. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_all_valid.py +0 -0
  185. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_cached.py +0 -0
  186. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_config.py +0 -0
  187. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_contracts.py +0 -0
  188. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_cross_attn.py +0 -0
  189. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_cross_attn_cache.py +0 -0
  190. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_distance_bias.py +0 -0
  191. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_empty_rows.py +0 -0
  192. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_factory.py +0 -0
  193. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_geometry.py +0 -0
  194. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_kernels.py +0 -0
  195. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_legacy_api.py +0 -0
  196. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_masking.py +0 -0
  197. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_onnx_backend.py +0 -0
  198. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_ops.py +0 -0
  199. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_packed_cross_attn.py +0 -0
  200. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_packed_self_attn.py +0 -0
  201. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_sdpa_export.py +0 -0
  202. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_self_attn.py +0 -0
  203. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/attention/test_varlen_backend.py +0 -0
  204. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/conftest.py +0 -0
  205. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/export_utils.py +0 -0
  206. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/feedforward/__init__.py +0 -0
  207. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/feedforward/legacy_swiglu_4_6.json +0 -0
  208. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/feedforward/test_config.py +0 -0
  209. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/feedforward/test_factory.py +0 -0
  210. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/feedforward/test_geglu.py +0 -0
  211. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/feedforward/test_gelu.py +0 -0
  212. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/feedforward/test_hardswish_glu.py +0 -0
  213. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/feedforward/test_packed_geglu.py +0 -0
  214. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/feedforward/test_packed_hardswish_glu.py +0 -0
  215. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/feedforward/test_packed_swiglu.py +0 -0
  216. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/feedforward/test_relu_squared.py +0 -0
  217. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/feedforward/test_swiglu.py +0 -0
  218. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/mlm/__init__.py +0 -0
  219. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/mlm/test_empty_selection.py +0 -0
  220. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/mlm/test_head.py +0 -0
  221. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/mlm/test_head_cosine.py +0 -0
  222. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/mlm/test_masking.py +0 -0
  223. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/mlm/test_wrapper.py +0 -0
  224. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/norm_topology_helpers.py +0 -0
  225. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/positional/__init__.py +0 -0
  226. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/positional/test_cacheable.py +0 -0
  227. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/positional/test_learned_pos.py +0 -0
  228. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/positional/test_rope.py +0 -0
  229. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/positional/test_rope_nd.py +0 -0
  230. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/presets/__init__.py +0 -0
  231. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/presets/test_cross_attender.py +0 -0
  232. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/presets/test_decoder.py +0 -0
  233. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/presets/test_encoder.py +0 -0
  234. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/presets/test_projection_packing.py +0 -0
  235. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/presets/test_variable_width_encoder.py +0 -0
  236. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_alignment.py +0 -0
  237. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_all_valid_decoder.py +0 -0
  238. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_core_results.py +0 -0
  239. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_cross_attender.py +0 -0
  240. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_decoder.py +0 -0
  241. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_decoder_cache.py +0 -0
  242. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_decoder_equations.py +0 -0
  243. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_encoder.py +0 -0
  244. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_encoder_decoder_example.py +0 -0
  245. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_examples.py +0 -0
  246. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_export_utils.py +0 -0
  247. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_layers.py +0 -0
  248. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_norm.py +0 -0
  249. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_packing.py +0 -0
  250. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_preallocated_decoder.py +0 -0
  251. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_projection_packing.py +0 -0
  252. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_public_api.py +0 -0
  253. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_result.py +0 -0
  254. {stackformers-6.0.0rc2 → stackformers-6.0.0rc8}/tests/test_sequence.py +0 -0
@@ -6,6 +6,123 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
6
6
  adheres to [Semantic Versioning](https://semver.org/): MAJOR for breaking public API changes,
7
7
  MINOR for backwards-compatible features, PATCH for bug fixes and internal changes.
8
8
 
9
+ ## [6.0.0rc8]
10
+
11
+ ### Backwards Incompatible Changes
12
+
13
+ - Restore actual rectangular `window_size=(height,width)` membership. This changes
14
+ attention groups and pooled placement from rc6's consecutive row-major chunks.
15
+ - Make constructor `alignment=` and `PackedTensor2d.align(...)` prepare rectangular
16
+ window-order storage as well as zero padding. `PackedTensor2d.window_size` records
17
+ this order; direct construction defaults to `(1,1)` for row-major storage.
18
+ Use the factories for consistent feature, position, and integer-grid ordering.
19
+
20
+ ### Improvements
21
+
22
+ - Partition matching prepared storage by creating cumulative sequence lengths and
23
+ borrowing the exact feature and position tensors. Self-attention retains the
24
+ prepared output order; pooling attaches output-window metadata without copying
25
+ attention output or query-position buffers.
26
+ - Pack other layouts during preparation and restore the original layout for
27
+ self-attention. Window-shape changes may require repacking; initial construction
28
+ and dense output conversion are separate from metadata-only partitioning.
29
+ - Show batch, sample, window, and pixel grouping in both spatial diagrams, including
30
+ the shared buffers and sample/window cumulative sequence boundaries.
31
+ - Verify rectangular membership, storage identity, compiled preparation, and encoder
32
+ execution without feature repacking. Extend ONNX Runtime checks to prepared and
33
+ row-major inputs with one or two samples at opsets 18–25.
34
+
35
+ ## [6.0.0rc6]
36
+
37
+ ### Backwards Incompatible Changes
38
+
39
+ - Group consecutive stored tokens into attention sequences instead of rearranging
40
+ rectangular tiles. A window contains `wh*ww` tokens in existing storage order;
41
+ this changes attention membership and pooled output placement versus rc5.
42
+ - Consolidate partitioning into `attention2d.windows.partition_windows`, which returns
43
+ a 1D `PackedTensor` and its bound merge operation. Remove `packed_windows.py`.
44
+
45
+ ### Improvements
46
+
47
+ - Add `PackedTensor2d.align(n)` and `alignment=` to both constructors. Accept a shared
48
+ positive axis multiple or a `(height, width)` pair, padding data and positions
49
+ with zeros. Already aligned records retain their storage.
50
+ - Borrow aligned features and positions when partitioning. Generate device-side
51
+ int32 sequence boundaries for existing native variable-length attention; ONNX
52
+ export uses int64 boundaries for compatibility with the installed exporter.
53
+ - Avoid feature and position concatenation for a single grid. Preserve packed
54
+ execution, mask-free alignment, and existing attention backend code.
55
+
56
+ ## [6.0.0rc5]
57
+
58
+ ### Backwards Incompatible Changes
59
+
60
+ - Remove custom geometry-policy signature buffers and checkpoint hooks. Built-in
61
+ position and query policies are ordinary modules. When loading an older state
62
+ dictionary, remove its `_geometry_signature` entries and reconstruct the original
63
+ policies explicitly; learned parameter names and tensor shapes are unchanged.
64
+ - Move `CentroidQueryPositions` into `attention2d.query_anchors` and the position
65
+ precision helper into `attention2d.coordinates`. Root package imports remain the
66
+ same; update imports that referenced the retired internal modules.
67
+
68
+ ### Improvements
69
+
70
+ - Remove three spatial wrapper/helper modules while preserving coordinate and
71
+ centroid arithmetic, packed execution, and the existing attention backend.
72
+
73
+ ## [6.0.0rc4]
74
+
75
+ ### Backwards Incompatible Changes
76
+
77
+ - Retain shape-derived per-grid dimensions in `PackedTensor2d.grid_shapes`. Direct
78
+ record construction must provide this tuple consistently with existing metadata;
79
+ prefer `from_list` or the new `from_tensor` constructor.
80
+
81
+ ### Improvements
82
+
83
+ - Replace data-dependent window topology discovery with reshape, zero alignment,
84
+ window rearrangement, and a bound inverse. Preserve arbitrary supplied absolute
85
+ positions and the existing packed spatial model API.
86
+ - Add `PackedTensor2d.from_tensor(data, abs_positions=positions)` for batched 2D
87
+ structures. List views and dense output conversion use known grid dimensions
88
+ without reading device metadata.
89
+
90
+ ### Bug Fixes
91
+
92
+ - Restore verified ONNX export through tensor I/O adapters that retain packed model
93
+ execution. Runtime parity covers static and dynamic spatial dimensions at opsets
94
+ 18–25 for attention, pooling, shared encoder stages, and composed encoders.
95
+ With the installed exporter, use deferred runtime shape assertions during capture
96
+ and `optimize=False` during conversion to avoid an invalid optimized graph.
97
+ Python layout metadata must stay outside ONNX graph outputs.
98
+
99
+ ## [6.0.0rc3]
100
+
101
+ ### Backwards Incompatible Changes
102
+
103
+ - Make 2D attention and encoders packed-only. Replace `PaddedTensor2d` construction
104
+ with `PackedTensor2d.from_list(...)`; spatial layers accept and return packed records.
105
+ Remove spatial `masks=` arguments and support for excluded interior slots.
106
+ - Return a raw dense feature tensor from `PackedTensor2d.to_padded()`, rather than a
107
+ spatial record. Use the packed record for positions and shape metadata. Remove the
108
+ separate dense spatial ONNX path; packed dynamic ONNX export remains unverified.
109
+ - Include zero alignment slots in attention and pooling centroids instead of masking
110
+ them out. This changes results at partially filled window boundaries.
111
+ - Rename `PhysicalCoordinates` to `AbsolutePositions` and pass `abs_positions` through
112
+ by default. Select `NormalizedWindowCoordinates` explicitly to normalize complete
113
+ windows. Updated normalization and centroid checkpoint signatures require an
114
+ explicit migration for older geometry policies.
115
+ - Simplify injected geometry protocols to packed inputs: implement
116
+ `WindowCoordinates.packed(context)` and `QueryPositions.packed(context, features)`
117
+ without source-slot arguments or dense methods.
118
+
119
+ ### Improvements
120
+
121
+ - Prepare aligned windows by direct scatter and restore their layout without sorting.
122
+ Compute query centroids with indexed reductions instead of token-by-query expansion.
123
+ - Remove spatial masking copies from encoder normalization and feed-forward adapters.
124
+ Preserve the existing 1D attention backend and its variable-length kernel dispatch.
125
+
9
126
  ## [6.0.0rc2]
10
127
 
11
128
  ### Bug Fixes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: stackformers
3
- Version: 6.0.0rc2
3
+ Version: 6.0.0rc8
4
4
  Summary: Composable PyTorch transformers for vision, spatial, and sequence research
5
5
  Project-URL: Homepage, https://github.com/Red-Eyed/stackformers
6
6
  Project-URL: Repository, https://github.com/Red-Eyed/stackformers
@@ -15,7 +15,7 @@ from stackformers import (
15
15
  NormalizedWindowCoordinates,
16
16
  PackedCrossAttentionConfig,
17
17
  PackedSelfAttentionConfig,
18
- PaddedTensor2d,
18
+ PackedTensor2d,
19
19
  RoPENDConfig,
20
20
  SandwichNormTransformerLayer,
21
21
  WindowEncoderStage2d,
@@ -31,10 +31,10 @@ if TYPE_CHECKING:
31
31
 
32
32
 
33
33
  class SpatialEncoderResult(NamedTuple):
34
- """Storage shapes produced by the same model on padded and packed spatial inputs."""
34
+ """Packed feature storage and rectangular output shapes."""
35
35
 
36
- padded_shape: tuple[int, ...]
37
36
  packed_shape: tuple[int, ...]
37
+ spatial_shapes: list[list[int]]
38
38
 
39
39
 
40
40
  def build_stage(dim: int, heads: int, depth: int, window: tuple[int, int]) -> WindowEncoderStage2d:
@@ -87,7 +87,7 @@ def build_encoder() -> Encoder2d:
87
87
 
88
88
 
89
89
  def run_example() -> SpatialEncoderResult:
90
- """Process nonuniform physical coordinates without resizing ragged feature grids."""
90
+ """Process nonuniform absolute coordinates without resizing ragged feature grids."""
91
91
  torch.manual_seed(0)
92
92
  grids: list[Float[Tensor, "height width d"]] = [torch.randn(8, width, 96) for width in (17, 23)]
93
93
  positions: list[Float[Tensor, "height width 2"]] = []
@@ -96,12 +96,11 @@ def run_example() -> SpatialEncoderResult:
96
96
  torch.arange(grid.shape[0]), torch.arange(grid.shape[1]), indexing="ij"
97
97
  )
98
98
  positions.append(torch.stack((y.float(), x.float().square() / 10), dim=-1))
99
- source = PaddedTensor2d.from_list(grids, abs_positions=positions)
99
+ source = PackedTensor2d.from_list(grids, abs_positions=positions)
100
100
  model = build_encoder().eval()
101
101
  with torch.no_grad():
102
- padded = model(source)
103
- packed = model(source.to_packed())
104
- return SpatialEncoderResult(tuple(padded.x.shape), tuple(packed.x.shape))
102
+ packed = model(source)
103
+ return SpatialEncoderResult(tuple(packed.x.shape), packed.spatial_shapes.tolist())
105
104
 
106
105
 
107
106
  if __name__ == "__main__":
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "stackformers"
7
- version = "6.0.0rc2"
7
+ version = "6.0.0rc8"
8
8
  description = "Composable PyTorch transformers for vision, spatial, and sequence research"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -835,3 +835,197 @@ behavior, zero-width rejection, and disabled defaults remain unchanged. This is
835
835
  Validation: repository formatting, lint, and type checks pass; 264 focused alignment,
836
836
  attention/feed-forward config, factory, and projection-packing tests pass. Runtime version
837
837
  reports 5.1.1.
838
+
839
+
840
+ ## Rectangular 2D preparation without validity masks
841
+
842
+ ### Observation and decision
843
+
844
+ The 2D adapters already delegate attention to the existing 1D implementations.
845
+ Their optional source-mask handling, automatic coordinate normalization, and
846
+ sorting added preparation work beyond the requested rectangular image workflow.
847
+
848
+ Remove spatial source masks and align right/bottom edges with ordinary zero
849
+ padding. Synthetic values and positions participate in attention. Packed windows
850
+ are prepared by direct scatter, with arithmetic sequence boundaries and a bound
851
+ gather for self-attention or scatter for pooling. No attention backend code changes.
852
+ Packed execution continues to use the existing variable-length backend when
853
+ eligible; the dense compatibility path uses its existing AllValid contract.
854
+
855
+ Use AbsolutePositions as the default pass-through policy, replacing the misleading
856
+ PhysicalCoordinates name. Keep normalization opt-in and implement it through shared
857
+ views of complete windows, without masks or neighbor search. Centroids use indexed
858
+ reductions shared across layouts instead of token-by-query expansion. Remove
859
+ spatial masking from tokenwise encoder adapters as well. Dense construction pads
860
+ grids directly, and packed to_list returns rectangular views without a batch canvas.
861
+
862
+ ### Compatibility and measurements
863
+
864
+ The 2D masks argument and dense mask field are removed. Added alignment slots now
865
+ participate in both attention and centroid geometry. Normalization and centroid
866
+ checkpoint revisions advance for the new complete-window contract. Ragged packed
867
+ samples align independently, while dense processing operates on its entire common
868
+ canvas; later dense layers can consume nonzero out-of-extent canvas outputs.
869
+
870
+ On one CPU thread, for 32,768 float32 tokens with dimension 64, 8x8 windows, and
871
+ 4x4 output queries, median partition preparation changed from 1.337 to 1.117 ms
872
+ and centroid preparation from 3.437 to 0.165 ms versus commit 001dcc0. The benchmark
873
+ uses aligned inputs so both versions process the same source token count. Profiling
874
+ shows no sort, searchsorted, bitwise, or masked_fill operations in the new partition
875
+ and centroid preparation. Identity tokenwise application shares feature storage.
876
+ These are synthetic preparation measurements, not CUDA or end-to-end throughput
877
+ claims. Real varlen kernel latency and recognition quality remain unmeasured.
878
+
879
+ ### Verification
880
+
881
+ Formatting, Ruff lint, and Pyrefly pass across the repository. The focused
882
+ attention2d and encoder2d suites pass 168 tests with 6 expected failures, including
883
+ independent numerical references, gradients, successful shared-varlen dispatch
884
+ through a CPU test kernel, fallback dispatch, and dynamic ONNX export. No real
885
+ CUDA kernel execution was available locally.
886
+
887
+ The full suite reports 3,662 passed, 21 skipped, 258 expected failures, and four
888
+ optional ONNX opset-15 rotary-export failures. All four failures reproduce from
889
+ an isolated archive of commit 001dcc0 using the same environment; their requested
890
+ opset assertion fails after exporter conversion. Attention backend and positional
891
+ implementation files are unchanged. Logs are in the ignored work_dir directory:
892
+ check_2d_simplification.log, focused_2d_simplification.log, and baseline_2d_check.log.
893
+
894
+
895
+ ## Packed-only spatial correction
896
+
897
+ Remove the separate dense spatial API and all intermediate dense sequence records
898
+ from spatial execution. Position normalization and query centroids operate directly
899
+ on tensor views of complete packed windows. The example, protocols, and tests now
900
+ use packed inputs exclusively. The existing attention backend remains unchanged
901
+ and owns all hardware compatibility fallback. Position terminology is consistently
902
+ absolute positions or coordinates in the spatial code and documentation.
903
+
904
+ A raw dense feature output adapter remains available for consumers; it does not
905
+ introduce another execution representation. The prior dense dynamic ONNX path is
906
+ removed. Packed dynamic ONNX export remains unverified. Graph-capture checks use
907
+ the eager compiler backend, in addition to numerical and gradient checks.
908
+
909
+ Mac CPU measurement correction: repeated end-to-end runs did not establish the
910
+ previously observed 14-15 percent packed encoder improvement. In the repeat at
911
+ four threads, the previous implementation measured 35.33 ms and the simplified
912
+ implementation 34.92 ms for two 96-channel blocks plus pooling on a 64x256 grid.
913
+ That is approximately unchanged. Packed pooling measured 7.21 to 6.44 ms in that
914
+ repeat. One-thread packed self-attention regressed approximately six percent in
915
+ the first run. Synthetic preparation improvements therefore do not justify an
916
+ end-to-end performance claim. Metal was not accessible in this process.
917
+
918
+ Packed-only verification: 312 spatial and public-API tests pass, including graph
919
+ capture, numerical references, gradients, successful varlen routing through the
920
+ CPU test kernel, and fallback behavior. Repository formatting, lint, and types
921
+ pass; the packed spatial example executes successfully. No padded sequence record
922
+ or old position terminology remains in the spatial implementation or documentation.
923
+
924
+ The final packed-only Mac repeat (64x256, batch one, float32, dimension 96,
925
+ 8x8 source windows, four CPU threads) measured self-attention at 9.63 ms, pooling
926
+ at 6.33 ms, and two blocks plus pooling at 34.43 ms. Compared with the repeated
927
+ baseline of 10.05, 7.21, and 35.33 ms respectively, encoder latency is approximately
928
+ unchanged within a few percent; pooling is about twelve percent lower. Raw results
929
+ are in work_dir/mac_2d_packed_only.json. Matched aligned inputs and seeded weights
930
+ agree numerically; border-padding semantics differ for unaligned inputs.
931
+
932
+
933
+ ## Shape-derived windows with PackedTensor2d retained
934
+
935
+ Version 6.0.0rc4 keeps PackedTensor2d as the spatial API and introduces known
936
+ per-grid shape metadata. Partitioning now reshapes each grid, zero-aligns it,
937
+ rearranges windows, calls the existing packed 1D attention, and reverses the bound
938
+ rearrangement. Absolute positions remain arbitrary supplied values and never
939
+ substitute for logical grid dimensions. No attention backend files change.
940
+
941
+ Real ONNX tests replace the graph-capture-only check. Sixty-four static/dynamic
942
+ cases pass at opsets 18–25 for self-attention, pooling, shared encoder stages, and
943
+ a composed encoder, including singleton and aligned runtime dimensions and
944
+ arbitrary position graph inputs. Tensor I/O adapters construct packed records
945
+ inside the traced model. Direct mixed Python/tensor record outputs remain an
946
+ exporter limitation. Dynamic conversion uses optimize=False to avoid an invalid
947
+ graph produced by the installed optimizer; runtime optimization remains available.
948
+
949
+ Alternating paired CPU benchmarks against 51a8211 show no material encoder speedup:
950
+ 35.00 to 34.74 ms for two blocks plus pooling on 64x256x96 data, four threads,
951
+ float32, batch one. Self-attention is unchanged (9.89 to 9.92 ms), while pooling
952
+ improves 6.45 to 6.22 ms. GPU performance remains unmeasured. The design and export
953
+ simplifications are established; a broad performance improvement is not.
954
+
955
+
956
+ ## Consolidate spatial policies
957
+
958
+ Version 6.0.0rc5 removes three wrapper/helper files: the geometry checkpoint base,
959
+ the separate centroid policy wrapper, and the precision helper module. Coordinate
960
+ policies now own precision selection, and query_anchors owns both centroid policy
961
+ and arithmetic. The strategy names exported by the package remain unchanged;
962
+ normalization and centroid formulas are unchanged. Position and query strategies
963
+ are ordinary nn.Modules without a custom checkpoint identity protocol.
964
+
965
+ Older state dictionaries require removal of _geometry_signature entries and an
966
+ explicit construction recipe. No learned weights or attention backend code change.
967
+
968
+ Validation for the policy consolidation: 372 targeted spatial and public API tests
969
+ pass, including the 64-case ONNX Runtime matrix. Formatting, lint, and types pass.
970
+
971
+
972
+ ## Contiguous chunks for native packed attention
973
+
974
+ Version 6.0.0rc6 uses consecutive stored tokens as attention sequences, as selected
975
+ by the caller, instead of rearranging rectangular tiles. Alignment is available
976
+ through PackedTensor2d.align and both constructors. Features and arbitrary absolute
977
+ positions receive matching zero padding. For already aligned inputs, partitioning
978
+ borrows both tensors and creates only cumulative lengths; the self-attention merge
979
+ also borrows the output storage. Single-grid construction avoids concatenation.
980
+
981
+ Native cumulative lengths use int32 on the input device. Export uses int64 because
982
+ the installed ONNX repeat_interleave lowering produces incompatible Range types
983
+ from int32 counts. Existing attention backend code remains unchanged. Partition
984
+ implementation and tests now live in windows.py, removing another module.
985
+
986
+ All 389 targeted spatial and public API tests pass, including 64 static/dynamic
987
+ ONNX Runtime cases at opsets 18–25. Checks cover gradients, arbitrary positions,
988
+ alignment, exact storage identity, and independent consecutive-chunk references.
989
+ Compiled execution retains native int32 boundaries; the export-only workaround
990
+ reads the actual export context because Dynamo folds is_exporting() to true during
991
+ ordinary compilation as well. Formatting, lint, and Pyrefly pass.
992
+ Window membership and pooled placement differ from rc5, so old latency comparisons
993
+ are not numerical-equivalence evidence for this change. CUDA kernel latency and
994
+ model quality remain unmeasured on this Mac.
995
+
996
+
997
+ ## Rectangular windows with reusable packed storage
998
+
999
+ Version 6.0.0rc7 corrects window membership after the diagram exposed the distinction
1000
+ between rectangular spatial tiles and consecutive row-major chunks. A 4x4 window
1001
+ on an 8x8 sample must use four adjacent columns from each of four adjacent rows.
1002
+ Permutation equivariance permits reordering within a window; it does not preserve
1003
+ behavior when window membership changes.
1004
+
1005
+ Constructors with alignment and the align helper now prepare contiguous rectangular
1006
+ windows and retain their window_size in the spatial record. Features, arbitrary
1007
+ positions, and integer topology follow the same order. For matching prepared storage,
1008
+ partitioning creates native cumulative lengths while borrowing both tensor objects.
1009
+ Self-attention retains that layout. Pooling attaches query-tile layout metadata to
1010
+ existing output and position buffers without moving them. Input layouts with another
1011
+ window shape require preparation; dense conversions can also move data.
1012
+
1013
+ The batch diagrams show two samples becoming eight attention sequences by changing
1014
+ sample boundaries [0,64,128] to window boundaries [0,16,32,48,64,80,96,112,128].
1015
+ Indexed-token checks now verify actual rectangular slices and sample isolation,
1016
+ rather than only pointer identity or agreement with a row-major chunk reference.
1017
+ Window shape changes are covered even for equal-area rectangles. Encoder regression
1018
+ checks reject feature packing or spatial unpacking on matching prepared inputs.
1019
+
1020
+ Initial packing is separate from the metadata-only path. A different shape after
1021
+ pooling may require repacking before the next encoder stage. Existing attention
1022
+ backend files and their kernel dispatch remain unchanged. CUDA latency and model
1023
+ quality remain unmeasured; this change establishes geometry and storage contracts.
1024
+
1025
+ Validation covers 599 distinct targeted spatial and public API cases across the
1026
+ main run and the added prepared-encoder checks. The 256-case ONNX Runtime matrix
1027
+ covers static/dynamic dimensions, one/two samples, row-major/prepared storage, all
1028
+ four spatial compositions, and opsets 18–25. On the indexed two-sample example,
1029
+ feature and position tensor identity is preserved, and partition profiling contains
1030
+ only arange, empty, and resize_ for boundary allocation. The local proof is saved in
1031
+ work_dir/rc7_partition_proof.json. These checks do not establish GPU throughput.
@@ -41,12 +41,11 @@ from stackformers.attention import (
41
41
  )
42
42
  from stackformers.attention.masking import CrossAttentionMask, SelfAttentionMask
43
43
  from stackformers.attention2d import (
44
+ AbsolutePositions,
44
45
  CentroidQueryPositions,
45
46
  CrossAttnPooling2d,
46
47
  NormalizedWindowCoordinates,
47
48
  PackedTensor2d,
48
- PaddedTensor2d,
49
- PhysicalCoordinates,
50
49
  QueryPositions,
51
50
  SelfAttn2d,
52
51
  WindowCoordinates,
@@ -203,11 +202,10 @@ __all__ = [
203
202
  "SelfAttn2d",
204
203
  "CentroidQueryPositions",
205
204
  "NormalizedWindowCoordinates",
206
- "PhysicalCoordinates",
205
+ "AbsolutePositions",
207
206
  "QueryPositions",
208
207
  "WindowCoordinates",
209
208
  "PackedTensor2d",
210
- "PaddedTensor2d",
211
209
  "CrossAttnPooling2d",
212
210
  "WindowSelfAttention2d",
213
211
  "AlignmentConfig",
@@ -0,0 +1,145 @@
1
+ # Packed spatial attention
2
+
3
+ The 2D adapters prepare existing `PackedTensor` inputs, call existing 1D attention,
4
+ and restore spatial layout. There is one execution path. Kernel selection,
5
+ `varlen_attn`, and the SDPA compatibility fallback belong to `attention/`.
6
+
7
+ ```python
8
+ from stackformers import PackedTensor2d, WindowSelfAttention2d, CrossAttnPooling2d
9
+
10
+ source = PackedTensor2d.from_list(grids, abs_positions=positions, alignment=4)
11
+ attention = WindowSelfAttention2d(96, window_size=(4, 4), num_heads=4)
12
+ pooling = CrossAttnPooling2d(96, window_size=(4, 4), output_window_size=(2, 2))
13
+ output = pooling(attention(source))
14
+ ```
15
+
16
+ ## Rectangles and alignment
17
+
18
+ Every input sample is a complete rectangle. `PackedTensor2d` concatenates features
19
+ and absolute positions with known `grid_shapes`, per-sample `cu_seqlens`,
20
+ `spatial_shapes`, integer `grid_indices`, and `max_spatial_shape`. `window_size`
21
+ records its rectangular storage order; `(1,1)` is ordinary row-major storage.
22
+ Supplied `abs_positions` can be nonuniform. Logical grid rows and columns determine
23
+ window membership independently of position values. Omitted positions default to
24
+ regular row/column coordinates. Constructors validate external inputs; direct
25
+ record construction trusts metadata, including storage order.
26
+
27
+ Preparation zero-aligns each rectangle to complete windows, like convolution
28
+ padding. Synthetic feature and position slots are zero and participate in
29
+ attention. There are no spatial masks, excluded slots, neighbor searches, or sorts.
30
+ `source.align(n)` rounds both grid axes up to multiples of `n` and packs each `n×n`
31
+ window contiguously; a tuple selects rectangular window dimensions. Both
32
+ constructors accept the same `alignment=` option. Features, positions, and integer
33
+ grid indices follow the same window order. Matching prepared records are returned
34
+ unchanged. The default alignment of one retains row-major storage.
35
+
36
+ Partitioning returns an existing 1D `PackedTensor` and a bound merge operation.
37
+ Each sequence contains the `wh*ww` tokens of an actual rectangular tile. For matching
38
+ prepared storage, partitioning borrows the exact feature and position tensors and
39
+ creates device-side int32 boundaries, matching native `varlen_attn`. For example,
40
+ two 8×8 samples prepared for 4×4 windows use sample boundaries `[0,64,128]` and
41
+ attention boundaries `[0,16,32,48,64,80,96,112,128]` over the same buffers.
42
+
43
+ Initial packing may move data. Changing the window shape may require repacking,
44
+ even when the new window has the same area. Layers automatically prepare other
45
+ layouts; use constructor `alignment=` or call `align(...)` once before repeated
46
+ matching-window layers to keep that preparation outside their execution.
47
+
48
+ The bound inverse restores each grid without discovering its topology from device
49
+ tensors. Self-attention retains matching prepared storage; for other inputs it
50
+ restores the original storage order and crops temporary padding. Pooling retains
51
+ attention output and query-position buffers directly, recording the output tile's
52
+ window order without a spatial rearrangement.
53
+ The pooled extent is `ceil(H/wh)*oh` by `ceil(W/ww)*ow`.
54
+
55
+ `to_list()` restores rectangular feature grids; undoing window order may copy.
56
+ `to_padded()` is an optional output
57
+ adapter returning a raw dense feature tensor, never a separate spatial record or
58
+ an execution path. Spatial layers accept and return `PackedTensor2d` only.
59
+ Conversions retain gradients. `to_list()` uses known `grid_shapes` without reading
60
+ device values. `PackedTensor2d.from_tensor(data, abs_positions=positions)` packs
61
+ `[b,H,W,d]` data and `[b,H,W,2]` supplied positions. Shapes are retained from tensor
62
+ dimensions, independently of position values. Direct record construction now also
63
+ requires consistent `grid_shapes` and `window_size`; prefer the factories to keep
64
+ metadata consistent. Omitting `window_size` in direct construction means row-major.
65
+
66
+ ## Positions and queries
67
+
68
+ `AbsolutePositions` passes `abs_positions` through unchanged. It is the default.
69
+ `NormalizedWindowCoordinates` is an explicit alternative that centers complete
70
+ windows and scales each axis by mean adjacent-slot spacing. Singleton axes and
71
+ zero spacing use scale one. Its source frame is bound into the query transform.
72
+ Neither policy constructs an intermediate sequence representation.
73
+
74
+ Default RoPEND uses unit minimum separation and maximum separation
75
+ `(max(2,wh-1), max(2,ww-1))`. Inject `rope` with calibration appropriate for other
76
+ position scales. Injected attention owns its encoding; do not supply both.
77
+ The existing default RoPEND does not differentiate through rotary positions.
78
+
79
+ Pooling repeats learned query features per window. `CentroidQueryPositions`
80
+ views each rectangular window as `[wh,ww]` and assigns its slots to output regions
81
+ using `floor(row*oh/wh)` and
82
+ `floor(col*ow/ww)`. Indexed reductions compute region centroids, including zero
83
+ alignment positions. Regions with no assigned source slots use the whole-window
84
+ centroid. Queries attend to the entire source window; regions determine positions
85
+ only. Accumulation promotes half precision to float32 and preserves float64.
86
+
87
+ ## Extension and compatibility
88
+
89
+ Implement `SelfAttn`, `CrossAttn`, `WindowCoordinates`, or `QueryPositions`
90
+ structurally in a separate file and inject it. Position and query policies accept
91
+ complete packed windows. Stateful collaborators must be modules so device moves,
92
+ optimizers, and checkpoints include their state.
93
+
94
+ Built-in position and query policies are ordinary modules. Save their construction
95
+ recipe alongside weights; there is no custom checkpoint-policy signature or loading
96
+ hook. For older checkpoints, remove `_geometry_signature` entries before loading
97
+ and explicitly reconstruct the original policies. Learned parameter names remain
98
+ unchanged. `CentroidQueryPositions` and its arithmetic live together in
99
+ `query_anchors.py`; coordinate policies own their accumulation-precision helper.
100
+
101
+ Automatic normalization, spatial source masks, and the separate dense spatial API
102
+ have been removed. Zero alignment slots participate in boundary attention.
103
+
104
+ ## ONNX export
105
+
106
+ ONNX Runtime parity is tested at opsets 18 through 25 for self-attention, pooling,
107
+ shared 1D encoder stages, and a composed spatial encoder. Tests cover static and
108
+ dynamic spatial dimensions, singleton axes, aligned and unaligned boundaries, and
109
+ arbitrary absolute positions supplied as graph inputs. Existing attention code is
110
+ unchanged.
111
+
112
+ During export, preparation creates int64 boundaries to avoid a type mismatch in the
113
+ installed exporter's `repeat_interleave` lowering. Eager and compiled execution
114
+ retain the native int32 contract.
115
+
116
+ Use a tensor I/O export adapter: accept data and absolute-position tensors, construct
117
+ `PackedTensor2d.from_tensor(...)` inside `forward`, call the existing spatial model,
118
+ and expose output data and positions as tensors. The model itself still consumes
119
+ and returns `PackedTensor2d`. Python layout tuples are metadata, not ONNX outputs;
120
+ exporting the mixed Python/tensor record directly is not supported by the installed
121
+ exporter. See the complete adapter and regression cases in
122
+ [`tests/attention2d/test_export.py`](../../tests/attention2d/test_export.py).
123
+
124
+ For dynamic spatial dimensions, export with the tested settings:
125
+
126
+ ```python
127
+ exported = torch.export.export(
128
+ adapter,
129
+ (data, abs_positions),
130
+ dynamic_shapes=dynamic_shapes,
131
+ prefer_deferred_runtime_asserts_over_guards=True,
132
+ )
133
+ program = torch.onnx.export(exported, opset_version=18, optimize=False)
134
+ ```
135
+
136
+ `optimize=False` avoids an invalid graph generated by the installed exporter's
137
+ optimizer for dynamic packed graphs. This does not disable ONNX Runtime's own graph
138
+ optimizations. The number of packed grids remains static per exported graph;
139
+ spatial dimensions and supplied positions can vary. Real GPU throughput and model
140
+ quality require target-workload measurement.
141
+
142
+ See [spatial encoders](../encoder2d/README.md) for partition reuse across 1D blocks.
143
+
144
+ ![Window self-attention](figures/window_self_attention_2d.svg)
145
+ ![Cross-attention pooling](figures/window_cross_attention_2d.svg)
@@ -1,19 +1,18 @@
1
1
  """Spatial records, window adapters, and replaceable geometry policies."""
2
2
 
3
- from stackformers.attention2d.centroid_queries import CentroidQueryPositions
4
- from stackformers.attention2d.coordinates import NormalizedWindowCoordinates, PhysicalCoordinates
3
+ from stackformers.attention2d.coordinates import AbsolutePositions, NormalizedWindowCoordinates
5
4
  from stackformers.attention2d.cross_attn_pooling import CrossAttnPooling2d
6
5
  from stackformers.attention2d.protocols import QueryPositions, SelfAttn2d, WindowCoordinates
6
+ from stackformers.attention2d.query_anchors import CentroidQueryPositions
7
7
  from stackformers.attention2d.self_attn import WindowSelfAttention2d
8
- from stackformers.attention2d.sequence import PackedTensor2d, PaddedTensor2d
8
+ from stackformers.attention2d.sequence import PackedTensor2d
9
9
 
10
10
  __all__ = [
11
11
  "CentroidQueryPositions",
12
12
  "CrossAttnPooling2d",
13
13
  "NormalizedWindowCoordinates",
14
14
  "PackedTensor2d",
15
- "PaddedTensor2d",
16
- "PhysicalCoordinates",
15
+ "AbsolutePositions",
17
16
  "QueryPositions",
18
17
  "SelfAttn2d",
19
18
  "WindowCoordinates",
@@ -0,0 +1,81 @@
1
+ """Normalize window coordinates independently of attention and preserve absolute metadata."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING
6
+
7
+ import torch
8
+ import torch.nn as nn
9
+ from einops import rearrange
10
+
11
+ from stackformers.attention2d.windows import validate_window
12
+
13
+ if TYPE_CHECKING:
14
+ from collections.abc import Callable
15
+
16
+ from jaxtyping import Float
17
+ from torch import Tensor
18
+
19
+ from stackformers.sequence import PackedTensor
20
+
21
+
22
+ def accumulation_positions(positions: Float[Tensor, "... c"]) -> Float[Tensor, "... c"]:
23
+ """Promote half precision while retaining supplied float64 coordinate information."""
24
+ dtype = torch.float64 if positions.dtype == torch.float64 else torch.float32
25
+ return positions.to(dtype=dtype)
26
+
27
+
28
+ class AbsolutePositions(nn.Module):
29
+ """Pass supplied absolute positions through unchanged."""
30
+
31
+ def packed(
32
+ self, context: PackedTensor
33
+ ) -> tuple[PackedTensor, Callable[[PackedTensor], PackedTensor]]:
34
+ """Preserve packed source and query coordinates exactly."""
35
+ return context, _absolute_packed
36
+
37
+
38
+ def _absolute_packed(queries: PackedTensor) -> PackedTensor:
39
+ """Borrow packed queries without transforming their positions."""
40
+ return queries
41
+
42
+
43
+ class NormalizedWindowCoordinates(nn.Module):
44
+ """Optionally center complete windows and scale by mean adjacent-axis spacing."""
45
+
46
+ def __init__(self, window: tuple[int, int]) -> None:
47
+ """Bind the rectangular window topology independently of supplied positions."""
48
+ validate_window(window)
49
+ super().__init__()
50
+ self.window = window
51
+
52
+ def packed(
53
+ self, context: PackedTensor
54
+ ) -> tuple[PackedTensor, Callable[[PackedTensor], PackedTensor]]:
55
+ """Bind one frame for all slots, including zero alignment padding."""
56
+ with torch.autocast(device_type=context.x.device.type, enabled=False):
57
+ batch = context.cu_seqlens.shape[0] - 1
58
+ positions = accumulation_positions(context.abs_positions)
59
+ positions = rearrange(positions, "(b s) c -> b s c", b=batch, s=context.max_seqlen)
60
+ origin = positions[:, :1]
61
+ relative = positions - origin
62
+ center = relative.mean(dim=1, keepdim=True)
63
+ grid = rearrange(relative, "b (h w) c -> b h w c", h=self.window[0])
64
+ wh, ww = self.window
65
+ unit = positions.new_ones(positions.shape[0])
66
+ sy = (grid[:, 1:, :, 0] - grid[:, :-1, :, 0]).abs().mean((1, 2)) if wh > 1 else unit
67
+ sx = (grid[:, :, 1:, 1] - grid[:, :, :-1, 1]).abs().mean((1, 2)) if ww > 1 else unit
68
+ spacing = torch.stack((sy, sx), dim=-1)
69
+ spacing = torch.where(spacing > 0, spacing, torch.ones_like(spacing))
70
+ scale = rearrange(spacing, "b c -> b 1 c")
71
+
72
+ def transform(queries: PackedTensor) -> PackedTensor:
73
+ """Reuse source calibration for independently sized query tiles."""
74
+ with torch.autocast(device_type=queries.x.device.type, enabled=False):
75
+ positions = accumulation_positions(queries.abs_positions)
76
+ positions = rearrange(positions, "(b n) c -> b n c", b=batch, n=queries.max_seqlen)
77
+ normalized = ((positions - origin) - center) / scale
78
+ positions = rearrange(normalized.float(), "b n c -> (b n) c")
79
+ return queries._replace(abs_positions=positions)
80
+
81
+ return transform(context), transform