stackformers 6.0.0rc2__tar.gz → 6.0.0rc3__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.0rc3}/PKG-INFO +1 -1
  2. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/examples/spatial_encoder.py +7 -8
  3. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/pyproject.toml +1 -1
  4. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/DEVLOG.md +93 -0
  5. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/__init__.py +2 -4
  6. stackformers-6.0.0rc3/stackformers/attention2d/README.md +77 -0
  7. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention2d/__init__.py +3 -4
  8. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention2d/centroid_queries.py +8 -13
  9. stackformers-6.0.0rc3/stackformers/attention2d/coordinates.py +77 -0
  10. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention2d/cross_attn_pooling.py +16 -41
  11. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention2d/factory.py +5 -12
  12. stackformers-6.0.0rc3/stackformers/attention2d/figures/window_cross_attention_2d.svg +1 -0
  13. stackformers-6.0.0rc3/stackformers/attention2d/figures/window_self_attention_2d.svg +1 -0
  14. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention2d/geometry_precision.py +1 -1
  15. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention2d/packed_windows.py +29 -30
  16. stackformers-6.0.0rc3/stackformers/attention2d/protocols.py +55 -0
  17. stackformers-6.0.0rc3/stackformers/attention2d/query_anchors.py +61 -0
  18. stackformers-6.0.0rc3/stackformers/attention2d/self_attn.py +57 -0
  19. stackformers-6.0.0rc3/stackformers/attention2d/sequence.py +149 -0
  20. stackformers-6.0.0rc3/stackformers/attention2d/windows.py +9 -0
  21. stackformers-6.0.0rc3/stackformers/encoder2d/README.md +63 -0
  22. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/encoder2d/_callable_stage.py +3 -13
  23. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/encoder2d/encoder.py +4 -14
  24. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/encoder2d/layer.py +8 -18
  25. stackformers-6.0.0rc3/stackformers/encoder2d/protocols.py +31 -0
  26. stackformers-6.0.0rc3/stackformers/encoder2d/tokenwise.py +20 -0
  27. stackformers-6.0.0rc3/stackformers/encoder2d/window_stage.py +47 -0
  28. stackformers-6.0.0rc3/tests/attention2d/conftest.py +79 -0
  29. stackformers-6.0.0rc3/tests/attention2d/test_coordinates.py +46 -0
  30. stackformers-6.0.0rc3/tests/attention2d/test_cross_attn_pooling.py +217 -0
  31. stackformers-6.0.0rc3/tests/attention2d/test_export.py +33 -0
  32. stackformers-6.0.0rc3/tests/attention2d/test_factory.py +35 -0
  33. stackformers-6.0.0rc3/tests/attention2d/test_packed_windows.py +50 -0
  34. stackformers-6.0.0rc3/tests/attention2d/test_query_anchors.py +88 -0
  35. stackformers-6.0.0rc3/tests/attention2d/test_self_attn.py +162 -0
  36. stackformers-6.0.0rc3/tests/attention2d/test_sequence.py +54 -0
  37. stackformers-6.0.0rc3/tests/attention2d/test_windows.py +12 -0
  38. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/encoder2d/conftest.py +5 -9
  39. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/encoder2d/test_encoder.py +16 -41
  40. stackformers-6.0.0rc3/tests/encoder2d/test_layer.py +57 -0
  41. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/encoder2d/test_window_stage.py +21 -29
  42. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/uv.lock +1 -1
  43. stackformers-6.0.0rc2/stackformers/attention2d/README.md +0 -243
  44. stackformers-6.0.0rc2/stackformers/attention2d/coordinates.py +0 -171
  45. stackformers-6.0.0rc2/stackformers/attention2d/figures/window_cross_attention_2d.svg +0 -1
  46. stackformers-6.0.0rc2/stackformers/attention2d/figures/window_self_attention_2d.svg +0 -1
  47. stackformers-6.0.0rc2/stackformers/attention2d/protocols.py +0 -73
  48. stackformers-6.0.0rc2/stackformers/attention2d/query_anchors.py +0 -102
  49. stackformers-6.0.0rc2/stackformers/attention2d/self_attn.py +0 -82
  50. stackformers-6.0.0rc2/stackformers/attention2d/sequence.py +0 -222
  51. stackformers-6.0.0rc2/stackformers/attention2d/windows.py +0 -113
  52. stackformers-6.0.0rc2/stackformers/encoder2d/README.md +0 -147
  53. stackformers-6.0.0rc2/stackformers/encoder2d/protocols.py +0 -37
  54. stackformers-6.0.0rc2/stackformers/encoder2d/tokenwise.py +0 -53
  55. stackformers-6.0.0rc2/stackformers/encoder2d/window_stage.py +0 -74
  56. stackformers-6.0.0rc2/tests/attention2d/conftest.py +0 -41
  57. stackformers-6.0.0rc2/tests/attention2d/test_coordinates.py +0 -68
  58. stackformers-6.0.0rc2/tests/attention2d/test_cross_attn_pooling.py +0 -238
  59. stackformers-6.0.0rc2/tests/attention2d/test_export.py +0 -63
  60. stackformers-6.0.0rc2/tests/attention2d/test_packed_windows.py +0 -30
  61. stackformers-6.0.0rc2/tests/attention2d/test_query_anchors.py +0 -75
  62. stackformers-6.0.0rc2/tests/attention2d/test_self_attn.py +0 -142
  63. stackformers-6.0.0rc2/tests/attention2d/test_sequence.py +0 -104
  64. stackformers-6.0.0rc2/tests/attention2d/test_windows.py +0 -24
  65. stackformers-6.0.0rc2/tests/encoder2d/test_layer.py +0 -68
  66. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/.claudeignore +0 -0
  67. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  68. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  69. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/.github/pull_request_template.md +0 -0
  70. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/.github/workflows/check.yml +0 -0
  71. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/.gitignore +0 -0
  72. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/.python-version +0 -0
  73. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/.vscode/settings.json +0 -0
  74. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/AGENTS.md +0 -0
  75. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/CHANGELOG.md +0 -0
  76. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/CITATION.cff +0 -0
  77. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/CONTRIBUTING.md +0 -0
  78. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/Justfile +0 -0
  79. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/LICENSE +0 -0
  80. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/PLAN.md +0 -0
  81. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/README.md +0 -0
  82. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/docs/api-guide.md +0 -0
  83. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/docs/assets/social-preview.jpg +0 -0
  84. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/docs/assets/social-preview.md +0 -0
  85. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/docs/compatibility.md +0 -0
  86. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/docs/improvement-plan.md +0 -0
  87. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/docs/inference.md +0 -0
  88. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/docs/research.md +0 -0
  89. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/examples/README.md +0 -0
  90. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/examples/causal_language_model.py +0 -0
  91. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/examples/encoder_decoder_onnxruntime.py +0 -0
  92. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/examples/image_encoder.py +0 -0
  93. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/examples/padded_and_packed.py +0 -0
  94. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/examples/point_cloud_encoder.py +0 -0
  95. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/examples/subclassed_encoder.py +0 -0
  96. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/pyrefly.toml +0 -0
  97. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/pytest.ini +0 -0
  98. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/ruff.toml +0 -0
  99. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/_decoder_equations.py +0 -0
  100. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/_projection_packing.py +0 -0
  101. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/_result.py +0 -0
  102. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/alignment.py +0 -0
  103. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/all_valid_decoder.py +0 -0
  104. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/README.md +0 -0
  105. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/__init__.py +0 -0
  106. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/all_valid.py +0 -0
  107. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/bias.py +0 -0
  108. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/cache.py +0 -0
  109. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/cache_validation.py +0 -0
  110. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/cached.py +0 -0
  111. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/config.py +0 -0
  112. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/cross_attn.py +0 -0
  113. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/distance_bias.py +0 -0
  114. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/factory.py +0 -0
  115. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/layout.py +0 -0
  116. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/masking.py +0 -0
  117. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/onnx_backend.py +0 -0
  118. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/ops.py +0 -0
  119. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/packed_cross_attn.py +0 -0
  120. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/packed_self_attn.py +0 -0
  121. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/protocols.py +0 -0
  122. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/self_attn.py +0 -0
  123. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention/varlen_backend.py +0 -0
  124. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/attention2d/_geometry_module.py +0 -0
  125. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/config.py +0 -0
  126. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/cross_attender.py +0 -0
  127. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/decoder.py +0 -0
  128. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/decoder_cache.py +0 -0
  129. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/encoder.py +0 -0
  130. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/encoder2d/__init__.py +0 -0
  131. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/DEVLOG.md +0 -0
  132. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/README.md +0 -0
  133. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/__init__.py +0 -0
  134. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/config.py +0 -0
  135. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/factory.py +0 -0
  136. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/geglu.py +0 -0
  137. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/gelu.py +0 -0
  138. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/hardswish_glu.py +0 -0
  139. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/packed_geglu.py +0 -0
  140. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/packed_hardswish_glu.py +0 -0
  141. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/packed_swiglu.py +0 -0
  142. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/protocols.py +0 -0
  143. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/relu_squared.py +0 -0
  144. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/feedforward/swiglu.py +0 -0
  145. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/layers.py +0 -0
  146. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/mlm/README.md +0 -0
  147. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/mlm/config.py +0 -0
  148. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/mlm/head.py +0 -0
  149. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/mlm/head_cosine.py +0 -0
  150. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/mlm/masking.py +0 -0
  151. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/mlm/protocols.py +0 -0
  152. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/mlm/wrapper.py +0 -0
  153. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/norm/README.md +0 -0
  154. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/norm/__init__.py +0 -0
  155. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/norm/config.py +0 -0
  156. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/norm/factory.py +0 -0
  157. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/norm/protocols.py +0 -0
  158. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/packing.py +0 -0
  159. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/positional/README.md +0 -0
  160. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/positional/__init__.py +0 -0
  161. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/positional/config.py +0 -0
  162. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/positional/factory.py +0 -0
  163. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/positional/learned.py +0 -0
  164. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/positional/none.py +0 -0
  165. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/positional/protocols.py +0 -0
  166. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/positional/rope1d.py +0 -0
  167. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/positional/rope2d.py +0 -0
  168. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/positional/rope_nd.py +0 -0
  169. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/positional/validation.py +0 -0
  170. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/preallocated_decoder.py +0 -0
  171. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/presets/README.md +0 -0
  172. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/presets/__init__.py +0 -0
  173. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/presets/cross_attender.py +0 -0
  174. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/presets/decoder.py +0 -0
  175. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/presets/encoder.py +0 -0
  176. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/presets/variable_width_encoder.py +0 -0
  177. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/py.typed +0 -0
  178. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/result/README.md +0 -0
  179. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/result/__init__.py +0 -0
  180. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/stackformers/sequence.py +0 -0
  181. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/__init__.py +0 -0
  182. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/__init__.py +0 -0
  183. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/legacy_api_rc1.json +0 -0
  184. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_all_valid.py +0 -0
  185. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_cached.py +0 -0
  186. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_config.py +0 -0
  187. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_contracts.py +0 -0
  188. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_cross_attn.py +0 -0
  189. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_cross_attn_cache.py +0 -0
  190. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_distance_bias.py +0 -0
  191. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_empty_rows.py +0 -0
  192. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_factory.py +0 -0
  193. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_geometry.py +0 -0
  194. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_kernels.py +0 -0
  195. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_legacy_api.py +0 -0
  196. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_masking.py +0 -0
  197. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_onnx_backend.py +0 -0
  198. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_ops.py +0 -0
  199. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_packed_cross_attn.py +0 -0
  200. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_packed_self_attn.py +0 -0
  201. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_sdpa_export.py +0 -0
  202. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_self_attn.py +0 -0
  203. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/attention/test_varlen_backend.py +0 -0
  204. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/conftest.py +0 -0
  205. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/export_utils.py +0 -0
  206. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/feedforward/__init__.py +0 -0
  207. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/feedforward/legacy_swiglu_4_6.json +0 -0
  208. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/feedforward/test_config.py +0 -0
  209. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/feedforward/test_factory.py +0 -0
  210. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/feedforward/test_geglu.py +0 -0
  211. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/feedforward/test_gelu.py +0 -0
  212. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/feedforward/test_hardswish_glu.py +0 -0
  213. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/feedforward/test_packed_geglu.py +0 -0
  214. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/feedforward/test_packed_hardswish_glu.py +0 -0
  215. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/feedforward/test_packed_swiglu.py +0 -0
  216. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/feedforward/test_relu_squared.py +0 -0
  217. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/feedforward/test_swiglu.py +0 -0
  218. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/mlm/__init__.py +0 -0
  219. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/mlm/test_empty_selection.py +0 -0
  220. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/mlm/test_head.py +0 -0
  221. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/mlm/test_head_cosine.py +0 -0
  222. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/mlm/test_masking.py +0 -0
  223. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/mlm/test_wrapper.py +0 -0
  224. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/norm_topology_helpers.py +0 -0
  225. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/positional/__init__.py +0 -0
  226. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/positional/test_cacheable.py +0 -0
  227. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/positional/test_learned_pos.py +0 -0
  228. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/positional/test_rope.py +0 -0
  229. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/positional/test_rope_nd.py +0 -0
  230. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/presets/__init__.py +0 -0
  231. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/presets/test_cross_attender.py +0 -0
  232. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/presets/test_decoder.py +0 -0
  233. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/presets/test_encoder.py +0 -0
  234. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/presets/test_projection_packing.py +0 -0
  235. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/presets/test_variable_width_encoder.py +0 -0
  236. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_alignment.py +0 -0
  237. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_all_valid_decoder.py +0 -0
  238. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_core_results.py +0 -0
  239. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_cross_attender.py +0 -0
  240. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_decoder.py +0 -0
  241. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_decoder_cache.py +0 -0
  242. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_decoder_equations.py +0 -0
  243. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_encoder.py +0 -0
  244. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_encoder_decoder_example.py +0 -0
  245. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_examples.py +0 -0
  246. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_export_utils.py +0 -0
  247. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_layers.py +0 -0
  248. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_norm.py +0 -0
  249. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_packing.py +0 -0
  250. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_preallocated_decoder.py +0 -0
  251. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_projection_packing.py +0 -0
  252. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_public_api.py +0 -0
  253. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_result.py +0 -0
  254. {stackformers-6.0.0rc2 → stackformers-6.0.0rc3}/tests/test_sequence.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: stackformers
3
- Version: 6.0.0rc2
3
+ Version: 6.0.0rc3
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.0rc3"
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,96 @@ 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.
@@ -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,77 @@
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)
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 per-sample `cu_seqlens`, `spatial_shapes`, integer
20
+ `grid_indices`, and `max_spatial_shape`. Supplied `abs_positions` can be nonuniform;
21
+ only grid indices determine window membership. Omitted positions default to
22
+ regular row/column coordinates. Constructors validate external inputs; direct
23
+ record construction trusts metadata.
24
+
25
+ Preparation zero-aligns each rectangle to complete windows, like convolution
26
+ padding. Synthetic feature and position slots are zero and participate in
27
+ attention. There are no spatial masks, excluded slots, neighbor searches, or sorts.
28
+ Scatter builds window-major storage and arithmetic sequence boundaries.
29
+ Self-attention gathers the original slots; pooling scatters complete output tiles.
30
+ The pooled extent is `ceil(H/wh)*oh` by `ceil(W/ww)*ow`.
31
+
32
+ `to_list()` returns rectangular feature views. `to_padded()` is an optional output
33
+ adapter returning a raw dense feature tensor, never a separate spatial record or
34
+ an execution path. Spatial layers accept and return `PackedTensor2d` only.
35
+ Conversions retain gradients. Reading shapes for list conversion is eager-only.
36
+
37
+ ## Positions and queries
38
+
39
+ `AbsolutePositions` passes `abs_positions` through unchanged. It is the default.
40
+ `NormalizedWindowCoordinates` is an explicit alternative that centers complete
41
+ windows and scales each axis by mean adjacent-slot spacing. Singleton axes and
42
+ zero spacing use scale one. Its source frame is bound into the query transform.
43
+ Neither policy constructs an intermediate sequence representation.
44
+
45
+ Default RoPEND uses unit minimum separation and maximum separation
46
+ `(max(2,wh-1), max(2,ww-1))`. Inject `rope` with calibration appropriate for other
47
+ position scales. Injected attention owns its encoding; do not supply both.
48
+ The existing default RoPEND does not differentiate through rotary positions.
49
+
50
+ Pooling repeats learned query features per window. `CentroidQueryPositions`
51
+ assigns source slots to output regions using `floor(row*oh/wh)` and
52
+ `floor(col*ow/ww)`. Indexed reductions compute region centroids, including zero
53
+ alignment positions. Regions with no assigned source slots use the whole-window
54
+ centroid. Queries attend to the entire source window; regions determine positions
55
+ only. Accumulation promotes half precision to float32 and preserves float64.
56
+
57
+ ## Extension and compatibility
58
+
59
+ Implement `SelfAttn`, `CrossAttn`, `WindowCoordinates`, or `QueryPositions`
60
+ structurally in a separate file and inject it. Position and query policies accept
61
+ complete packed windows. Stateful collaborators must be modules so device moves,
62
+ optimizers, and checkpoints include their state.
63
+
64
+ Geometry signatures record policy identity, revision, and topology. Save the model
65
+ construction recipe alongside weights. Automatic normalization, spatial source
66
+ masks, and the separate dense spatial API have been removed. This changes border
67
+ attention and checkpoint recipes. Normalization and centroid signatures reflect
68
+ complete-window semantics.
69
+
70
+ Graph capture is tested through PyTorch's eager compiler backend. Packed dynamic
71
+ ONNX export is not established; there is no separate dense export implementation.
72
+ Real GPU throughput and model quality require target-workload measurement.
73
+
74
+ See [spatial encoders](../encoder2d/README.md) for partition reuse across 1D blocks.
75
+
76
+ ![Window self-attention](figures/window_self_attention_2d.svg)
77
+ ![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
3
  from stackformers.attention2d.centroid_queries import CentroidQueryPositions
4
- from stackformers.attention2d.coordinates import NormalizedWindowCoordinates, PhysicalCoordinates
4
+ from stackformers.attention2d.coordinates import AbsolutePositions, NormalizedWindowCoordinates
5
5
  from stackformers.attention2d.cross_attn_pooling import CrossAttnPooling2d
6
6
  from stackformers.attention2d.protocols import QueryPositions, SelfAttn2d, WindowCoordinates
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",
@@ -5,37 +5,32 @@ from __future__ import annotations
5
5
  from typing import TYPE_CHECKING
6
6
 
7
7
  from stackformers.attention2d._geometry_module import GeometryModule
8
- from stackformers.attention2d.query_anchors import packed_queries, padded_queries, query_regions
8
+ from stackformers.attention2d.query_anchors import packed_queries, query_regions
9
9
  from stackformers.attention2d.windows import validate_window
10
10
 
11
11
  if TYPE_CHECKING:
12
- from jaxtyping import Bool, Float, Int
12
+ from jaxtyping import Float, Int
13
13
  from torch import Tensor
14
14
 
15
- from stackformers.sequence import PackedTensor, PaddedTensor
15
+ from stackformers.sequence import PackedTensor
16
16
 
17
17
 
18
18
  class CentroidQueryPositions(GeometryModule):
19
19
  """Use integer regions to anchor queries while retaining whole-window attention."""
20
20
 
21
- regions: Bool[Tensor, "n s"]
21
+ regions: Int[Tensor, "s"]
22
22
 
23
23
  def __init__(self, window: tuple[int, int], output: tuple[int, int]) -> None:
24
- """Bind row-major source-to-query membership as a registered module buffer."""
24
+ """Bind one output-region index per source slot as a registered module buffer."""
25
25
  validate_window(window)
26
26
  validate_window(output)
27
- super().__init__(3, 1, window + output)
27
+ super().__init__(3, 2, window + output)
28
28
  self.register_buffer("regions", query_regions(window, output), persistent=False)
29
29
 
30
- def padded(self, context: PaddedTensor, features: Float[Tensor, "n d"]) -> PaddedTensor:
31
- """Repeat learned features with valid-region physical centroids."""
32
- return padded_queries(context, features, self.regions)
33
-
34
30
  def packed(
35
31
  self,
36
32
  context: PackedTensor,
37
- slots: Int[Tensor, "nt"],
38
33
  features: Float[Tensor, "n d"],
39
34
  ) -> PackedTensor:
40
- """Emit full packed tiles for nonempty windows and no tokens for empty ones."""
41
- return packed_queries(context, slots, features, self.regions)
35
+ """Emit one complete query tile for every aligned packed source window."""
36
+ return packed_queries(context, features, self.regions)
@@ -0,0 +1,77 @@
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
+ from einops import rearrange
9
+
10
+ from stackformers.attention2d._geometry_module import GeometryModule
11
+ from stackformers.attention2d.geometry_precision import accumulation_positions
12
+ from stackformers.attention2d.windows import validate_window
13
+
14
+ if TYPE_CHECKING:
15
+ from collections.abc import Callable
16
+
17
+ from stackformers.sequence import PackedTensor
18
+
19
+
20
+ class AbsolutePositions(GeometryModule):
21
+ """Pass supplied absolute positions through unchanged."""
22
+
23
+ def __init__(self) -> None:
24
+ """Version the identity position policy for checkpoint loading."""
25
+ super().__init__(1, 1, ())
26
+
27
+ def packed(
28
+ self, context: PackedTensor
29
+ ) -> tuple[PackedTensor, Callable[[PackedTensor], PackedTensor]]:
30
+ """Preserve packed source and query coordinates exactly."""
31
+ return context, _absolute_packed
32
+
33
+
34
+ def _absolute_packed(queries: PackedTensor) -> PackedTensor:
35
+ """Borrow packed queries without transforming their positions."""
36
+ return queries
37
+
38
+
39
+ class NormalizedWindowCoordinates(GeometryModule):
40
+ """Optionally center complete windows and scale by mean adjacent-axis spacing."""
41
+
42
+ def __init__(self, window: tuple[int, int]) -> None:
43
+ """Bind the rectangular window topology independently of supplied positions."""
44
+ validate_window(window)
45
+ super().__init__(2, 2, window)
46
+ self.window = window
47
+
48
+ def packed(
49
+ self, context: PackedTensor
50
+ ) -> tuple[PackedTensor, Callable[[PackedTensor], PackedTensor]]:
51
+ """Bind one frame for all slots, including zero alignment padding."""
52
+ with torch.autocast(device_type=context.x.device.type, enabled=False):
53
+ batch = context.cu_seqlens.shape[0] - 1
54
+ positions = accumulation_positions(context.abs_positions)
55
+ positions = rearrange(positions, "(b s) c -> b s c", b=batch, s=context.max_seqlen)
56
+ origin = positions[:, :1]
57
+ relative = positions - origin
58
+ center = relative.mean(dim=1, keepdim=True)
59
+ grid = rearrange(relative, "b (h w) c -> b h w c", h=self.window[0])
60
+ wh, ww = self.window
61
+ unit = positions.new_ones(positions.shape[0])
62
+ sy = (grid[:, 1:, :, 0] - grid[:, :-1, :, 0]).abs().mean((1, 2)) if wh > 1 else unit
63
+ sx = (grid[:, :, 1:, 1] - grid[:, :, :-1, 1]).abs().mean((1, 2)) if ww > 1 else unit
64
+ spacing = torch.stack((sy, sx), dim=-1)
65
+ spacing = torch.where(spacing > 0, spacing, torch.ones_like(spacing))
66
+ scale = rearrange(spacing, "b c -> b 1 c")
67
+
68
+ def transform(queries: PackedTensor) -> PackedTensor:
69
+ """Reuse source calibration for independently sized query tiles."""
70
+ with torch.autocast(device_type=queries.x.device.type, enabled=False):
71
+ positions = accumulation_positions(queries.abs_positions)
72
+ positions = rearrange(positions, "(b n) c -> b n c", b=batch, n=queries.max_seqlen)
73
+ normalized = ((positions - origin) - center) / scale
74
+ positions = rearrange(normalized.float(), "b n c -> (b n) c")
75
+ return queries._replace(abs_positions=positions)
76
+
77
+ return transform(context), transform
@@ -1,6 +1,6 @@
1
1
  """Spatial pooling adapters over existing one-dimensional cross-attention and RoPEND."""
2
2
 
3
- from typing import TYPE_CHECKING, overload
3
+ from typing import TYPE_CHECKING
4
4
 
5
5
  import torch
6
6
  import torch.nn as nn
@@ -16,8 +16,8 @@ from stackformers.attention2d.factory import (
16
16
  )
17
17
  from stackformers.attention2d.packed_windows import partition_packed_windows
18
18
  from stackformers.attention2d.protocols import QueryPositions, WindowCoordinates
19
- from stackformers.attention2d.sequence import PackedTensor2d, PaddedTensor2d
20
- from stackformers.attention2d.windows import partition_padded_windows, validate_window
19
+ from stackformers.attention2d.sequence import PackedTensor2d
20
+ from stackformers.attention2d.windows import validate_window
21
21
  from stackformers.positional.protocols import PosEncoding
22
22
 
23
23
 
@@ -26,8 +26,8 @@ class CrossAttnPooling2d(nn.Module):
26
26
 
27
27
  Learned query features are shared across windows. Query placement, coordinate
28
28
  preparation, and 1D attention are independent injected collaborators. Defaults
29
- use region centroids, normalized-window RoPEND, and existing fused cross-attention.
30
- Returned positions stay in the physical frame selected by the query policy.
29
+ use region centroids, absolute-position RoPEND, and existing fused cross-attention.
30
+ Returned positions stay in the frame selected by the query policy.
31
31
  """
32
32
 
33
33
  queries: Float[Tensor, "n d"]
@@ -55,50 +55,25 @@ class CrossAttnPooling2d(nn.Module):
55
55
  queries = output_window_size[0] * output_window_size[1]
56
56
  self.queries = nn.Parameter(torch.empty(queries, dim))
57
57
  nn.init.normal_(self.queries, std=0.02)
58
- self.coordinates = build_window_coordinates(window_size, coordinates, attention, rope)
58
+ self.coordinates = build_window_coordinates(coordinates)
59
59
  self.query_positions = build_query_positions(
60
60
  window_size, output_window_size, query_positions
61
61
  )
62
62
  self.attention = build_window_cross_attention(dim, window_size, attention, rope)
63
63
 
64
- @overload
65
- def forward(self, input: PaddedTensor2d) -> PaddedTensor2d:
66
- """Return dense output tiles, validity, query anchors, and reduced spatial extents."""
67
- ...
68
-
69
- @overload
70
- def forward(self, input: PackedTensor2d) -> PackedTensor2d:
71
- """Return valid packed output tiles with updated boundaries and integer topology."""
72
- ...
73
-
74
64
  @override
75
- def forward(self, input: PaddedTensor2d | PackedTensor2d) -> PaddedTensor2d | PackedTensor2d:
76
- """Apply existing padded/packed cross-attention to windows and restore the layout."""
65
+ def forward(self, input: PackedTensor2d) -> PackedTensor2d:
66
+ """Prepare aligned packed windows, delegate attention, and restore the grid layout."""
77
67
  if input.x.shape[-1] != self.dim:
78
68
  raise ValueError("input channel dimension must equal dim")
79
- match input:
80
- case PaddedTensor2d():
81
- windows = partition_padded_windows(
82
- input, self.window_size, self.output_window_size, crop=False
83
- )
84
- queries = self.query_positions.padded(windows.tokens, self.queries)
85
- context, transform_queries = self.coordinates.padded(windows.tokens)
86
- attention_queries = transform_queries(queries)
87
- attended = self.attention(attention_queries, context)
88
- return windows.merge(queries._replace(x=attended))
89
- case PackedTensor2d():
90
- windows = partition_packed_windows(
91
- input, self.window_size, self.output_window_size, crop=False
92
- )
93
- queries = self.query_positions.packed(
94
- windows.tokens, windows.source_slots, self.queries
95
- )
96
- context, transform_queries = self.coordinates.packed(
97
- windows.tokens, windows.source_slots
98
- )
99
- attention_queries = transform_queries(queries)
100
- attended = self.attention(attention_queries, context)
101
- return windows.merge(queries._replace(x=attended))
69
+ windows = partition_packed_windows(
70
+ input, self.window_size, self.output_window_size, crop=False
71
+ )
72
+ queries = self.query_positions.packed(windows.tokens, self.queries)
73
+ context, transform_queries = self.coordinates.packed(windows.tokens)
74
+ attention_queries = transform_queries(queries)
75
+ attended = self.attention(attention_queries, context)
76
+ return windows.merge(queries._replace(x=attended))
102
77
 
103
78
  if TYPE_CHECKING:
104
79
  __call__ = forward
@@ -11,7 +11,7 @@ from stackformers.attention import (
11
11
  build_self_attn,
12
12
  )
13
13
  from stackformers.attention2d.centroid_queries import CentroidQueryPositions
14
- from stackformers.attention2d.coordinates import NormalizedWindowCoordinates, PhysicalCoordinates
14
+ from stackformers.attention2d.coordinates import AbsolutePositions
15
15
  from stackformers.positional import RoPENDConfig, RotaryEmbeddingND
16
16
 
17
17
  if TYPE_CHECKING:
@@ -21,7 +21,7 @@ if TYPE_CHECKING:
21
21
 
22
22
 
23
23
  def _default_rope(dim_head: int, window: tuple[int, int]) -> PosEncoding:
24
- """Calibrate RoPEND for window coordinates measured in unit neighbour spacing."""
24
+ """Provide unit-grid RoPEND bounds; other absolute scales can inject an encoding."""
25
25
  return RotaryEmbeddingND(
26
26
  RoPENDConfig(
27
27
  dim_head=dim_head,
@@ -66,21 +66,14 @@ def build_window_cross_attention(
66
66
 
67
67
 
68
68
  def build_window_coordinates(
69
- window: tuple[int, int],
70
69
  coordinates: WindowCoordinates | None,
71
- attention: SelfAttn | CrossAttn | None,
72
- rope: PosEncoding | None,
73
70
  ) -> WindowCoordinates:
74
- """Honor coordinate injection; custom attention/encoding defaults to physical units."""
75
- if coordinates is not None:
76
- return coordinates
77
- if attention is not None or rope is not None:
78
- return PhysicalCoordinates()
79
- return NormalizedWindowCoordinates(window)
71
+ """Borrow absolute positions unless the caller explicitly selects a transformation."""
72
+ return AbsolutePositions() if coordinates is None else coordinates
80
73
 
81
74
 
82
75
  def build_query_positions(
83
76
  window: tuple[int, int], output: tuple[int, int], positions: QueryPositions | None
84
77
  ) -> QueryPositions:
85
- """Default to physical region centroids without constraining custom query geometry."""
78
+ """Default to absolute region centroids without constraining custom query geometry."""
86
79
  return CentroidQueryPositions(window, output) if positions is None else positions
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="1100" height="590" viewBox="0 0 1100 590" role="img" aria-labelledby="title desc"><title id="title">CrossAttnPooling2d</title><desc id="desc">Windows become independent packed 1D sequences. Existing 1D attention owns optimized kernel and fallback dispatch. Absolute positions remain in the spatial records.</desc><defs><pattern id="pad" width="6" height="6" patternUnits="userSpaceOnUse"><rect width="6" height="6" fill="#f1f5f9"/><path d="M0 6L6 0" stroke="#94a3b8"/></pattern><marker id="arrow" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto"><path d="M0 0L8 4L0 8" fill="#334155"/></marker></defs><rect width="1100" height="590" fill="white"/><g font-family="Arial, sans-serif" fill="#0f172a"><text x="550" y="38" text-anchor="middle" font-size="26">CrossAttnPooling2d</text><rect x="40.0" y="100.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="60.0" y="100.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="80.0" y="100.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="100.0" y="100.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="120.0" y="100.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="140.0" y="100.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="160.0" y="100.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="180.0" y="100.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="40.0" y="120.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="60.0" y="120.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="80.0" y="120.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="100.0" y="120.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="120.0" y="120.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="140.0" y="120.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="160.0" y="120.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="180.0" y="120.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="40.0" y="140.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="60.0" y="140.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="80.0" y="140.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="100.0" y="140.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="120.0" y="140.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="140.0" y="140.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="160.0" y="140.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="180.0" y="140.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="40.0" y="160.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="60.0" y="160.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="80.0" y="160.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="100.0" y="160.0" width="20.0" height="20.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="120.0" y="160.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="140.0" y="160.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="160.0" y="160.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="180.0" y="160.0" width="20.0" height="20.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="40.0" y="180.0" width="20.0" height="20.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="60.0" y="180.0" width="20.0" height="20.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="80.0" y="180.0" width="20.0" height="20.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="100.0" y="180.0" width="20.0" height="20.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="120.0" y="180.0" width="20.0" height="20.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="140.0" y="180.0" width="20.0" height="20.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="160.0" y="180.0" width="20.0" height="20.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="180.0" y="180.0" width="20.0" height="20.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="40.0" y="200.0" width="20.0" height="20.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="60.0" y="200.0" width="20.0" height="20.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="80.0" y="200.0" width="20.0" height="20.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="100.0" y="200.0" width="20.0" height="20.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="120.0" y="200.0" width="20.0" height="20.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="140.0" y="200.0" width="20.0" height="20.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="160.0" y="200.0" width="20.0" height="20.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="180.0" y="200.0" width="20.0" height="20.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="40.0" y="220.0" width="20.0" height="20.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="60.0" y="220.0" width="20.0" height="20.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="80.0" y="220.0" width="20.0" height="20.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="100.0" y="220.0" width="20.0" height="20.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="120.0" y="220.0" width="20.0" height="20.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="140.0" y="220.0" width="20.0" height="20.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="160.0" y="220.0" width="20.0" height="20.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="180.0" y="220.0" width="20.0" height="20.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="40.0" y="240.0" width="20.0" height="20.0" fill="url(#pad)" stroke="#94a3b8" stroke-width="0.5"/><rect x="60.0" y="240.0" width="20.0" height="20.0" fill="url(#pad)" stroke="#94a3b8" stroke-width="0.5"/><rect x="80.0" y="240.0" width="20.0" height="20.0" fill="url(#pad)" stroke="#94a3b8" stroke-width="0.5"/><rect x="100.0" y="240.0" width="20.0" height="20.0" fill="url(#pad)" stroke="#94a3b8" stroke-width="0.5"/><rect x="120.0" y="240.0" width="20.0" height="20.0" fill="url(#pad)" stroke="#94a3b8" stroke-width="0.5"/><rect x="140.0" y="240.0" width="20.0" height="20.0" fill="url(#pad)" stroke="#94a3b8" stroke-width="0.5"/><rect x="160.0" y="240.0" width="20.0" height="20.0" fill="url(#pad)" stroke="#94a3b8" stroke-width="0.5"/><rect x="180.0" y="240.0" width="20.0" height="20.0" fill="url(#pad)" stroke="#94a3b8" stroke-width="0.5"/><rect x="40" y="100" width="80" height="80" fill="none" stroke="#334155" stroke-width="2"/><text x="80" y="146" text-anchor="middle" font-size="20">1</text><rect x="120" y="100" width="80" height="80" fill="none" stroke="#334155" stroke-width="2"/><text x="160" y="146" text-anchor="middle" font-size="20">2</text><rect x="40" y="180" width="80" height="80" fill="none" stroke="#334155" stroke-width="2"/><text x="80" y="226" text-anchor="middle" font-size="20">3</text><rect x="120" y="180" width="80" height="80" fill="none" stroke="#334155" stroke-width="2"/><text x="160" y="226" text-anchor="middle" font-size="20">4</text><text x="120" y="85" text-anchor="middle" font-size="16">Input [B, 7, 8, C]</text><text x="120" y="284" text-anchor="middle" font-size="16">4 × 4 windows</text><text x="120" y="307" text-anchor="middle" font-size="14">Right / bottom padding</text><path d="M215 180H260" stroke="#334155" stroke-width="2" marker-end="url(#arrow)"/><rect x="280" y="105" width="170" height="27" rx="3" fill="#dbeafe" stroke="#334155"/><text x="365" y="124" text-anchor="middle" font-size="14">Window 1: ≤16 tokens</text><rect x="280" y="142" width="170" height="27" rx="3" fill="#dcfce7" stroke="#334155"/><text x="365" y="161" text-anchor="middle" font-size="14">Window 2: ≤16 tokens</text><rect x="280" y="179" width="170" height="27" rx="3" fill="#fef3c7" stroke="#334155"/><text x="365" y="198" text-anchor="middle" font-size="14">Window 3: ≤16 tokens</text><rect x="280" y="216" width="170" height="27" rx="3" fill="#fce7f3" stroke="#334155"/><text x="365" y="235" text-anchor="middle" font-size="14">Window 4: ≤16 tokens</text><text x="365" y="85" text-anchor="middle" font-size="16">Independent 1D sequences</text><text x="365" y="284" text-anchor="middle" font-size="14">PackedTensor</text><path d="M465 180H510" stroke="#334155" stroke-width="2" marker-end="url(#arrow)"/><rect x="530" y="105" width="275" height="145" rx="8" fill="#f8fafc" stroke="#334155" stroke-width="2"/><text x="667" y="135" text-anchor="middle" font-size="18">Existing 1D cross-attention</text><text x="667" y="164" text-anchor="middle" font-size="16">Learned queries + fused K/V</text><text x="667" y="191" text-anchor="middle" font-size="16">RoPEND → kernel / fallback</text><text x="667" y="222" text-anchor="middle" font-size="16">16 → 4 tokens</text><path d="M820 180H865" stroke="#334155" stroke-width="2" marker-end="url(#arrow)"/><rect x="895.0" y="100.0" width="40.0" height="40.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="935.0" y="100.0" width="40.0" height="40.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="975.0" y="100.0" width="40.0" height="40.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="1015.0" y="100.0" width="40.0" height="40.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="895.0" y="140.0" width="40.0" height="40.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="935.0" y="140.0" width="40.0" height="40.0" fill="#dbeafe" stroke="#94a3b8" stroke-width="0.5"/><rect x="975.0" y="140.0" width="40.0" height="40.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="1015.0" y="140.0" width="40.0" height="40.0" fill="#dcfce7" stroke="#94a3b8" stroke-width="0.5"/><rect x="895.0" y="180.0" width="40.0" height="40.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="935.0" y="180.0" width="40.0" height="40.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="975.0" y="180.0" width="40.0" height="40.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="1015.0" y="180.0" width="40.0" height="40.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="895.0" y="220.0" width="40.0" height="40.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="935.0" y="220.0" width="40.0" height="40.0" fill="#fef3c7" stroke="#94a3b8" stroke-width="0.5"/><rect x="975.0" y="220.0" width="40.0" height="40.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="1015.0" y="220.0" width="40.0" height="40.0" fill="#fce7f3" stroke="#94a3b8" stroke-width="0.5"/><rect x="895" y="100" width="80" height="80" fill="none" stroke="#334155" stroke-width="2"/><text x="935" y="146" text-anchor="middle" font-size="20">1</text><rect x="975" y="100" width="80" height="80" fill="none" stroke="#334155" stroke-width="2"/><text x="1015" y="146" text-anchor="middle" font-size="20">2</text><rect x="895" y="180" width="80" height="80" fill="none" stroke="#334155" stroke-width="2"/><text x="935" y="226" text-anchor="middle" font-size="20">3</text><rect x="975" y="180" width="80" height="80" fill="none" stroke="#334155" stroke-width="2"/><text x="1015" y="226" text-anchor="middle" font-size="20">4</text><text x="975" y="85" text-anchor="middle" font-size="16">[B, 4, 4, C]</text><text x="975" y="284" text-anchor="middle" font-size="14">Stitch full 2 × 2 tiles</text><path d="M35 335H1065" stroke="#cbd5e1"/><text x="550" y="370" text-anchor="middle" font-size="16">Topology: row-major windows become batch elements; attention never mixes their tokens.</text><text x="550" y="403" text-anchor="middle" font-size="16">Alignment: zero-padded slots participate in attention without validity masks.</text><text x="550" y="436" text-anchor="middle" font-size="16">Positions: abs_positions pass through; normalization is an explicit policy.</text><text x="550" y="469" text-anchor="middle" font-size="16">Query positions: region centroids by default; the query-placement policy is replaceable.</text><text x="550" y="502" text-anchor="middle" font-size="16">Queries and sources share one bound coordinate frame; output positions retain the supplied units.</text><text x="550" y="535" text-anchor="middle" font-size="16">Every source window emits a complete output tile; channel width C is unchanged.</text></g></svg>