stackformers 5.0.0rc22__tar.gz → 5.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. {stackformers-5.0.0rc22 → stackformers-5.1.0}/CHANGELOG.md +61 -0
  2. {stackformers-5.0.0rc22 → stackformers-5.1.0}/PKG-INFO +37 -25
  3. {stackformers-5.0.0rc22 → stackformers-5.1.0}/README.md +35 -23
  4. {stackformers-5.0.0rc22 → stackformers-5.1.0}/docs/improvement-plan.md +2 -2
  5. {stackformers-5.0.0rc22 → stackformers-5.1.0}/docs/research.md +5 -3
  6. {stackformers-5.0.0rc22 → stackformers-5.1.0}/pyproject.toml +2 -2
  7. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/DEVLOG.md +31 -0
  8. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/__init__.py +2 -0
  9. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/README.md +20 -0
  10. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/config.py +34 -1
  11. stackformers-5.1.0/stackformers/dimension_rounding.py +27 -0
  12. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/README.md +20 -0
  13. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/config.py +16 -2
  14. stackformers-5.1.0/tests/attention/test_config.py +122 -0
  15. stackformers-5.1.0/tests/feedforward/test_config.py +114 -0
  16. stackformers-5.1.0/tests/test_dimension_rounding.py +34 -0
  17. {stackformers-5.0.0rc22 → stackformers-5.1.0}/uv.lock +1 -1
  18. {stackformers-5.0.0rc22 → stackformers-5.1.0}/.claudeignore +0 -0
  19. {stackformers-5.0.0rc22 → stackformers-5.1.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  20. {stackformers-5.0.0rc22 → stackformers-5.1.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  21. {stackformers-5.0.0rc22 → stackformers-5.1.0}/.github/pull_request_template.md +0 -0
  22. {stackformers-5.0.0rc22 → stackformers-5.1.0}/.github/workflows/check.yml +0 -0
  23. {stackformers-5.0.0rc22 → stackformers-5.1.0}/.gitignore +0 -0
  24. {stackformers-5.0.0rc22 → stackformers-5.1.0}/.python-version +0 -0
  25. {stackformers-5.0.0rc22 → stackformers-5.1.0}/.vscode/settings.json +0 -0
  26. {stackformers-5.0.0rc22 → stackformers-5.1.0}/AGENTS.md +0 -0
  27. {stackformers-5.0.0rc22 → stackformers-5.1.0}/CITATION.cff +0 -0
  28. {stackformers-5.0.0rc22 → stackformers-5.1.0}/CONTRIBUTING.md +0 -0
  29. {stackformers-5.0.0rc22 → stackformers-5.1.0}/Justfile +0 -0
  30. {stackformers-5.0.0rc22 → stackformers-5.1.0}/LICENSE +0 -0
  31. {stackformers-5.0.0rc22 → stackformers-5.1.0}/PLAN.md +0 -0
  32. {stackformers-5.0.0rc22 → stackformers-5.1.0}/docs/api-guide.md +0 -0
  33. {stackformers-5.0.0rc22 → stackformers-5.1.0}/docs/assets/social-preview.jpg +0 -0
  34. {stackformers-5.0.0rc22 → stackformers-5.1.0}/docs/assets/social-preview.md +0 -0
  35. {stackformers-5.0.0rc22 → stackformers-5.1.0}/docs/compatibility.md +0 -0
  36. {stackformers-5.0.0rc22 → stackformers-5.1.0}/docs/inference.md +0 -0
  37. {stackformers-5.0.0rc22 → stackformers-5.1.0}/examples/README.md +0 -0
  38. {stackformers-5.0.0rc22 → stackformers-5.1.0}/examples/causal_language_model.py +0 -0
  39. {stackformers-5.0.0rc22 → stackformers-5.1.0}/examples/encoder_decoder_onnxruntime.py +0 -0
  40. {stackformers-5.0.0rc22 → stackformers-5.1.0}/examples/image_encoder.py +0 -0
  41. {stackformers-5.0.0rc22 → stackformers-5.1.0}/examples/padded_and_packed.py +0 -0
  42. {stackformers-5.0.0rc22 → stackformers-5.1.0}/examples/point_cloud_encoder.py +0 -0
  43. {stackformers-5.0.0rc22 → stackformers-5.1.0}/examples/subclassed_encoder.py +0 -0
  44. {stackformers-5.0.0rc22 → stackformers-5.1.0}/pyrefly.toml +0 -0
  45. {stackformers-5.0.0rc22 → stackformers-5.1.0}/pytest.ini +0 -0
  46. {stackformers-5.0.0rc22 → stackformers-5.1.0}/ruff.toml +0 -0
  47. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/_decoder_equations.py +0 -0
  48. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/_projection_packing.py +0 -0
  49. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/_result.py +0 -0
  50. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/all_valid_decoder.py +0 -0
  51. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/__init__.py +0 -0
  52. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/all_valid.py +0 -0
  53. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/bias.py +0 -0
  54. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/cache.py +0 -0
  55. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/cache_validation.py +0 -0
  56. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/cached.py +0 -0
  57. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/cross_attn.py +0 -0
  58. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/distance_bias.py +0 -0
  59. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/factory.py +0 -0
  60. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/layout.py +0 -0
  61. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/masking.py +0 -0
  62. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/onnx_backend.py +0 -0
  63. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/ops.py +0 -0
  64. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/packed_cross_attn.py +0 -0
  65. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/packed_self_attn.py +0 -0
  66. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/protocols.py +0 -0
  67. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/self_attn.py +0 -0
  68. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/attention/varlen_backend.py +0 -0
  69. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/config.py +0 -0
  70. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/cross_attender.py +0 -0
  71. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/decoder.py +0 -0
  72. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/decoder_cache.py +0 -0
  73. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/encoder.py +0 -0
  74. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/DEVLOG.md +0 -0
  75. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/__init__.py +0 -0
  76. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/factory.py +0 -0
  77. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/geglu.py +0 -0
  78. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/gelu.py +0 -0
  79. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/hardswish_glu.py +0 -0
  80. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/packed_geglu.py +0 -0
  81. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/packed_hardswish_glu.py +0 -0
  82. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/packed_swiglu.py +0 -0
  83. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/protocols.py +0 -0
  84. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/relu_squared.py +0 -0
  85. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/feedforward/swiglu.py +0 -0
  86. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/layers.py +0 -0
  87. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/mlm/README.md +0 -0
  88. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/mlm/config.py +0 -0
  89. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/mlm/head.py +0 -0
  90. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/mlm/head_cosine.py +0 -0
  91. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/mlm/masking.py +0 -0
  92. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/mlm/protocols.py +0 -0
  93. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/mlm/wrapper.py +0 -0
  94. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/norm/README.md +0 -0
  95. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/norm/__init__.py +0 -0
  96. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/norm/config.py +0 -0
  97. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/norm/factory.py +0 -0
  98. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/norm/protocols.py +0 -0
  99. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/packing.py +0 -0
  100. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/positional/README.md +0 -0
  101. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/positional/__init__.py +0 -0
  102. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/positional/config.py +0 -0
  103. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/positional/factory.py +0 -0
  104. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/positional/learned.py +0 -0
  105. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/positional/none.py +0 -0
  106. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/positional/protocols.py +0 -0
  107. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/positional/rope1d.py +0 -0
  108. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/positional/rope2d.py +0 -0
  109. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/positional/rope_nd.py +0 -0
  110. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/positional/validation.py +0 -0
  111. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/preallocated_decoder.py +0 -0
  112. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/presets/README.md +0 -0
  113. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/presets/__init__.py +0 -0
  114. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/presets/cross_attender.py +0 -0
  115. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/presets/decoder.py +0 -0
  116. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/presets/encoder.py +0 -0
  117. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/presets/variable_width_encoder.py +0 -0
  118. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/py.typed +0 -0
  119. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/result/README.md +0 -0
  120. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/result/__init__.py +0 -0
  121. {stackformers-5.0.0rc22 → stackformers-5.1.0}/stackformers/sequence.py +0 -0
  122. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/__init__.py +0 -0
  123. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/__init__.py +0 -0
  124. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/legacy_api_rc1.json +0 -0
  125. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_all_valid.py +0 -0
  126. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_cached.py +0 -0
  127. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_contracts.py +0 -0
  128. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_cross_attn.py +0 -0
  129. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_cross_attn_cache.py +0 -0
  130. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_distance_bias.py +0 -0
  131. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_empty_rows.py +0 -0
  132. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_factory.py +0 -0
  133. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_geometry.py +0 -0
  134. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_kernels.py +0 -0
  135. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_legacy_api.py +0 -0
  136. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_masking.py +0 -0
  137. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_onnx_backend.py +0 -0
  138. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_ops.py +0 -0
  139. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_packed_cross_attn.py +0 -0
  140. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_packed_self_attn.py +0 -0
  141. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_sdpa_export.py +0 -0
  142. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_self_attn.py +0 -0
  143. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/attention/test_varlen_backend.py +0 -0
  144. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/conftest.py +0 -0
  145. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/export_utils.py +0 -0
  146. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/feedforward/__init__.py +0 -0
  147. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/feedforward/legacy_swiglu_4_6.json +0 -0
  148. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/feedforward/test_factory.py +0 -0
  149. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/feedforward/test_geglu.py +0 -0
  150. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/feedforward/test_gelu.py +0 -0
  151. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/feedforward/test_hardswish_glu.py +0 -0
  152. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/feedforward/test_packed_geglu.py +0 -0
  153. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/feedforward/test_packed_hardswish_glu.py +0 -0
  154. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/feedforward/test_packed_swiglu.py +0 -0
  155. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/feedforward/test_relu_squared.py +0 -0
  156. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/feedforward/test_swiglu.py +0 -0
  157. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/mlm/__init__.py +0 -0
  158. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/mlm/test_empty_selection.py +0 -0
  159. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/mlm/test_head.py +0 -0
  160. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/mlm/test_head_cosine.py +0 -0
  161. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/mlm/test_masking.py +0 -0
  162. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/mlm/test_wrapper.py +0 -0
  163. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/norm_topology_helpers.py +0 -0
  164. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/positional/__init__.py +0 -0
  165. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/positional/test_cacheable.py +0 -0
  166. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/positional/test_learned_pos.py +0 -0
  167. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/positional/test_rope.py +0 -0
  168. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/positional/test_rope_nd.py +0 -0
  169. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/presets/__init__.py +0 -0
  170. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/presets/test_cross_attender.py +0 -0
  171. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/presets/test_decoder.py +0 -0
  172. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/presets/test_encoder.py +0 -0
  173. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/presets/test_projection_packing.py +0 -0
  174. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/presets/test_variable_width_encoder.py +0 -0
  175. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_all_valid_decoder.py +0 -0
  176. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_core_results.py +0 -0
  177. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_cross_attender.py +0 -0
  178. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_decoder.py +0 -0
  179. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_decoder_cache.py +0 -0
  180. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_decoder_equations.py +0 -0
  181. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_encoder.py +0 -0
  182. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_encoder_decoder_example.py +0 -0
  183. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_examples.py +0 -0
  184. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_export_utils.py +0 -0
  185. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_layers.py +0 -0
  186. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_norm.py +0 -0
  187. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_packing.py +0 -0
  188. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_preallocated_decoder.py +0 -0
  189. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_projection_packing.py +0 -0
  190. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_public_api.py +0 -0
  191. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_result.py +0 -0
  192. {stackformers-5.0.0rc22 → stackformers-5.1.0}/tests/test_sequence.py +0 -0
@@ -6,6 +6,67 @@ 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
+ ## [5.1.0]
10
+
11
+ ### New Features
12
+
13
+ - Add optional `DimensionRoundingConfig(multiple_of=..., rounding_mode="floor" | "ceil")`
14
+ to all attention and feed-forward variants through `dimension_rounding`. Round attention
15
+ head widths and feed-forward hidden widths without changing the external model dimension.
16
+ Defaults preserve existing geometry; opting in may change parameter counts and checkpoint
17
+ shapes. Zero-width rounding results fail config validation.
18
+
19
+ ## [5.0.0]
20
+
21
+ ### Highlights
22
+
23
+ - Release the 5.0 candidate series as stable, with canonical tensor batches, composable
24
+ architecture variants, and cached deployment adapters. Library runtime behavior is unchanged
25
+ from `5.0.0rc22`; the sections below summarize migration from 4.x and earlier candidates.
26
+
27
+ ### Backwards Incompatible Changes
28
+
29
+ - Attention configurations are immutable. Construct a new configuration and model instead of
30
+ assigning architecture fields on an existing `SelfAttentionConfig` or `CrossAttentionConfig`.
31
+ - Cross-attention requires matching padded/packed query and context layouts. Convert both inputs
32
+ to the same layout before calling it; mixed layouts raise `ValueError`.
33
+ - Custom reconstruction heads must return a differentiable zero loss when no tokens are selected.
34
+ For an empty prediction tensor, return `prediction.sum()`.
35
+ - Custom layers and attention implementations must accept and forward the runtime visibility
36
+ keywords they support (`self_attn_mask` and `cross_attn_mask`).
37
+ - Consumers of core outcomes from early candidates must replace the external `returns` API with
38
+ `stackformers.result.Ok` / `Err` keyword matching. Earlier `AllValidInput` callers must use
39
+ `PaddedTensor(x, AllValid(), positions)`.
40
+
41
+ ### Deprecations
42
+
43
+ - Prefer `PaddedTensor` and `PackedTensor` to the retained `PaddedInput` and `PackedInput` aliases.
44
+ Use their constructors and conversion methods instead of deprecated sequence helpers. No
45
+ removal version is assigned; see `5.0.0rc21` for the full compatibility list.
46
+
47
+ ### New Features
48
+
49
+ - Add list/nested-tensor adapters and padded/packed conversions preserving valid tokens,
50
+ gradients, and custom coordinates where documented.
51
+ - Add variable-width encoders, per-call attention visibility, and the HardSwishGLU variant.
52
+ - Add opt-in projection packing and unpacking for attention and gated feed-forward modules.
53
+ Convert before constructing an optimizer and save the resulting configuration with weights.
54
+ - Add cached encoder-decoder deployment adapters, including separate all-valid and preallocated
55
+ cache strategies. Their supported classes, opsets, and ownership contracts are documented in
56
+ `docs/inference.md`; custom forwards require their own deployment integration.
57
+
58
+ ### Bug Fixes
59
+
60
+ - Return finite zero losses for empty built-in MLM selections and zero attention contributions
61
+ when every key is excluded.
62
+ - Fix attention-mask and dynamic GQA export paths covered by the PyTorch/ONNX Runtime tests.
63
+
64
+ ### Documentation
65
+
66
+ - Lead installation with PyPI commands for pip and uv. Document opt-in prerelease upgrades with
67
+ `--pre` or `--prerelease allow`; keep repository cloning in contributor instructions.
68
+ - Add research reproducibility, compatibility, and citation guidance alongside runnable examples.
69
+
9
70
  ## [5.0.0rc22]
10
71
 
11
72
  ### Documentation
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: stackformers
3
- Version: 5.0.0rc22
3
+ Version: 5.1.0
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
@@ -31,7 +31,7 @@ License: MIT License
31
31
  SOFTWARE.
32
32
  License-File: LICENSE
33
33
  Keywords: attention,computer-vision,point-cloud,pytorch,research,transformer
34
- Classifier: Development Status :: 4 - Beta
34
+ Classifier: Development Status :: 5 - Production/Stable
35
35
  Classifier: Intended Audience :: Science/Research
36
36
  Classifier: License :: OSI Approved :: MIT License
37
37
  Classifier: Programming Language :: Python :: 3
@@ -52,7 +52,7 @@ Description-Content-Type: text/markdown
52
52
  # Stackformers
53
53
 
54
54
  [![CI](https://github.com/Red-Eyed/stackformers/actions/workflows/check.yml/badge.svg)](https://github.com/Red-Eyed/stackformers/actions/workflows/check.yml)
55
- [![PyPI](https://img.shields.io/pypi/v/stackformers.svg)](https://pypi.org/project/stackformers/)
55
+ [![PyPI](https://img.shields.io/badge/install-PyPI-blue.svg)](https://pypi.org/project/stackformers/)
56
56
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
57
57
 
58
58
  **Composable PyTorch transformers for research.**
@@ -68,27 +68,38 @@ individual components as your experiments evolve.
68
68
  - **Connect research and deployment:** examples cover image patches, point clouds,
69
69
  causal modeling, custom components, and cached ONNX Runtime decoding.
70
70
 
71
- ## Try the current API
71
+ ## Install
72
72
 
73
- Python 3.11 or newer is required. This checkout is on the **5.0 release-candidate series**.
74
- To run the examples shown here against the matching source:
73
+ Install from [PyPI](https://pypi.org/project/stackformers/) with pip:
75
74
 
76
75
  ```bash
77
- git clone https://github.com/Red-Eyed/stackformers.git
78
- cd stackformers
79
- uv run examples/padded_and_packed.py
76
+ pip install --upgrade stackformers
80
77
  ```
81
78
 
82
- `uv run` prepares the project environment automatically. For a published release in an
83
- existing project:
79
+ Or add it to your uv project:
84
80
 
85
81
  ```bash
86
82
  uv add stackformers
87
83
  ```
88
84
 
89
- An unpinned install may resolve a different stable release whose API differs from this
90
- checkout. Use the documentation matching your installed version. For experiments, pin the
91
- exact version or commit you validated; see the [research guide](docs/research.md).
85
+ ### Try the latest prerelease
86
+
87
+ Use `--pre` to include newer prereleases when upgrading:
88
+
89
+ ```bash
90
+ pip install --upgrade --pre stackformers
91
+ ```
92
+
93
+ With uv:
94
+
95
+ ```bash
96
+ uv add --upgrade --prerelease allow stackformers
97
+ ```
98
+
99
+ For an existing virtual environment, `uv pip install --upgrade --pre stackformers`
100
+ is also supported. These commands select the newest compatible published version,
101
+ including prereleases. Pin the version you validate for an experiment; see the
102
+ [research guide](docs/research.md).
92
103
 
93
104
  ## Run your first encoder
94
105
 
@@ -112,19 +123,20 @@ retains batch and sequence axes. See the [layout parity example](examples/padded
112
123
  for a numerical comparison. Packed input does not guarantee faster execution: backend,
113
124
  hardware, dtype, and length distribution matter.
114
125
 
115
- ## Choose an example
126
+ ## Explore examples
116
127
 
117
- Examples run on CPU without dataset or model downloads. From a repository checkout,
118
- `uv run` prepares the project environment automatically.
128
+ Browse complete examples for common tasks:
119
129
 
120
- | Your task | Start here | Run |
121
- | --- | --- | --- |
122
- | Image patches and 2-D positions | [Image encoder](examples/image_encoder.py) | `uv run examples/image_encoder.py` |
123
- | Continuous spatial coordinates | [Point-cloud encoder](examples/point_cloud_encoder.py) | `uv run examples/point_cloud_encoder.py` |
124
- | Unequal sequence lengths | [Padded and packed](examples/padded_and_packed.py) | `uv run examples/padded_and_packed.py` |
125
- | Replace a model component | [Custom encoders](examples/subclassed_encoder.py) | `uv run examples/subclassed_encoder.py` |
126
- | Autoregressive token modeling | [Causal language model](examples/causal_language_model.py) | `uv run examples/causal_language_model.py` |
127
- | Export an encoder–decoder | [ONNX Runtime guide](examples/README.md#encoderdecoder-onnx-runtime) | `uv run examples/encoder_decoder_onnxruntime.py` |
130
+ | Your task | Example |
131
+ | --- | --- |
132
+ | Image patches and 2-D positions | [Image encoder](examples/image_encoder.py) |
133
+ | Continuous spatial coordinates | [Point-cloud encoder](examples/point_cloud_encoder.py) |
134
+ | Unequal sequence lengths | [Padded and packed](examples/padded_and_packed.py) |
135
+ | Replace a model component | [Custom encoders](examples/subclassed_encoder.py) |
136
+ | Autoregressive token modeling | [Causal language model](examples/causal_language_model.py) |
137
+ | Export an encoder–decoder | [ONNX Runtime guide](examples/README.md#encoderdecoder-onnx-runtime) |
138
+
139
+ The [examples guide](examples/README.md) includes commands for running the repository examples.
128
140
 
129
141
  These are integration examples with synthetic inputs, not trained models or task-accuracy
130
142
  benchmarks. Stackformers provides transformer components; your application owns tokenization,
@@ -1,7 +1,7 @@
1
1
  # Stackformers
2
2
 
3
3
  [![CI](https://github.com/Red-Eyed/stackformers/actions/workflows/check.yml/badge.svg)](https://github.com/Red-Eyed/stackformers/actions/workflows/check.yml)
4
- [![PyPI](https://img.shields.io/pypi/v/stackformers.svg)](https://pypi.org/project/stackformers/)
4
+ [![PyPI](https://img.shields.io/badge/install-PyPI-blue.svg)](https://pypi.org/project/stackformers/)
5
5
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
6
 
7
7
  **Composable PyTorch transformers for research.**
@@ -17,27 +17,38 @@ individual components as your experiments evolve.
17
17
  - **Connect research and deployment:** examples cover image patches, point clouds,
18
18
  causal modeling, custom components, and cached ONNX Runtime decoding.
19
19
 
20
- ## Try the current API
20
+ ## Install
21
21
 
22
- Python 3.11 or newer is required. This checkout is on the **5.0 release-candidate series**.
23
- To run the examples shown here against the matching source:
22
+ Install from [PyPI](https://pypi.org/project/stackformers/) with pip:
24
23
 
25
24
  ```bash
26
- git clone https://github.com/Red-Eyed/stackformers.git
27
- cd stackformers
28
- uv run examples/padded_and_packed.py
25
+ pip install --upgrade stackformers
29
26
  ```
30
27
 
31
- `uv run` prepares the project environment automatically. For a published release in an
32
- existing project:
28
+ Or add it to your uv project:
33
29
 
34
30
  ```bash
35
31
  uv add stackformers
36
32
  ```
37
33
 
38
- An unpinned install may resolve a different stable release whose API differs from this
39
- checkout. Use the documentation matching your installed version. For experiments, pin the
40
- exact version or commit you validated; see the [research guide](docs/research.md).
34
+ ### Try the latest prerelease
35
+
36
+ Use `--pre` to include newer prereleases when upgrading:
37
+
38
+ ```bash
39
+ pip install --upgrade --pre stackformers
40
+ ```
41
+
42
+ With uv:
43
+
44
+ ```bash
45
+ uv add --upgrade --prerelease allow stackformers
46
+ ```
47
+
48
+ For an existing virtual environment, `uv pip install --upgrade --pre stackformers`
49
+ is also supported. These commands select the newest compatible published version,
50
+ including prereleases. Pin the version you validate for an experiment; see the
51
+ [research guide](docs/research.md).
41
52
 
42
53
  ## Run your first encoder
43
54
 
@@ -61,19 +72,20 @@ retains batch and sequence axes. See the [layout parity example](examples/padded
61
72
  for a numerical comparison. Packed input does not guarantee faster execution: backend,
62
73
  hardware, dtype, and length distribution matter.
63
74
 
64
- ## Choose an example
75
+ ## Explore examples
65
76
 
66
- Examples run on CPU without dataset or model downloads. From a repository checkout,
67
- `uv run` prepares the project environment automatically.
77
+ Browse complete examples for common tasks:
68
78
 
69
- | Your task | Start here | Run |
70
- | --- | --- | --- |
71
- | Image patches and 2-D positions | [Image encoder](examples/image_encoder.py) | `uv run examples/image_encoder.py` |
72
- | Continuous spatial coordinates | [Point-cloud encoder](examples/point_cloud_encoder.py) | `uv run examples/point_cloud_encoder.py` |
73
- | Unequal sequence lengths | [Padded and packed](examples/padded_and_packed.py) | `uv run examples/padded_and_packed.py` |
74
- | Replace a model component | [Custom encoders](examples/subclassed_encoder.py) | `uv run examples/subclassed_encoder.py` |
75
- | Autoregressive token modeling | [Causal language model](examples/causal_language_model.py) | `uv run examples/causal_language_model.py` |
76
- | Export an encoder–decoder | [ONNX Runtime guide](examples/README.md#encoderdecoder-onnx-runtime) | `uv run examples/encoder_decoder_onnxruntime.py` |
79
+ | Your task | Example |
80
+ | --- | --- |
81
+ | Image patches and 2-D positions | [Image encoder](examples/image_encoder.py) |
82
+ | Continuous spatial coordinates | [Point-cloud encoder](examples/point_cloud_encoder.py) |
83
+ | Unequal sequence lengths | [Padded and packed](examples/padded_and_packed.py) |
84
+ | Replace a model component | [Custom encoders](examples/subclassed_encoder.py) |
85
+ | Autoregressive token modeling | [Causal language model](examples/causal_language_model.py) |
86
+ | Export an encoder–decoder | [ONNX Runtime guide](examples/README.md#encoderdecoder-onnx-runtime) |
87
+
88
+ The [examples guide](examples/README.md) includes commands for running the repository examples.
77
89
 
78
90
  These are integration examples with synthetic inputs, not trained models or task-accuracy
79
91
  benchmarks. Stackformers provides transformer components; your application owns tokenization,
@@ -38,8 +38,8 @@ or GPU compatibility.
38
38
  report backend/fallback behavior and verify valid-token numerical parity first.
39
39
  4. Freeze an exact dependency version for the consuming paper project. Retain its config,
40
40
  checkpoints, environment, and reproduction commands; test reconstruction in that project.
41
- 5. Decide when the public API is stable enough for a non-prerelease version using compatibility
42
- evidence. Do not remove the release-candidate label for presentation alone.
41
+ 5. Preserve the stable 5.0 API contract in subsequent releases. Evaluate new interfaces through
42
+ opt-in prereleases and document migrations before the next stable version.
43
43
 
44
44
  ## Discovery and launch preparation
45
45
 
@@ -20,9 +20,11 @@ the actual version you tested. Commit that project's `uv.lock`; reproduce its en
20
20
  with `uv sync --locked`. A repository checkout can use `uv sync --locked --group dev`.
21
21
  The library's lockfile alone does not describe your application's full environment.
22
22
 
23
- The current checkout is a release candidate. Do not assume a plain install selects its API
24
- or that a later release candidate preserves every interface. Consult the
25
- [release history](../CHANGELOG.md) before upgrading and rerun your experiment's parity checks.
23
+ Stable installations use the published stable release by default. To evaluate a newer
24
+ prerelease, use `pip install --upgrade --pre stackformers` or
25
+ `uv add --upgrade --prerelease allow stackformers`, then pin the exact version you validate.
26
+ Consult the [release history](../CHANGELOG.md) before upgrading and rerun your experiment's
27
+ parity checks; prereleases can change interfaces before the corresponding stable release.
26
28
 
27
29
  ## Save configuration and weights together
28
30
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "stackformers"
7
- version = "5.0.0rc22"
7
+ version = "5.1.0"
8
8
  description = "Composable PyTorch transformers for vision, spatial, and sequence research"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -14,7 +14,7 @@ authors = [
14
14
  ]
15
15
  keywords = ["pytorch", "transformer", "computer-vision", "attention", "research", "point-cloud"]
16
16
  classifiers = [
17
- "Development Status :: 4 - Beta",
17
+ "Development Status :: 5 - Production/Stable",
18
18
  "Intended Audience :: Science/Research",
19
19
  "License :: OSI Approved :: MIT License",
20
20
  "Programming Language :: Python :: 3",
@@ -791,3 +791,34 @@ best accuracy, activation range, convergence, or ARM64 latency for the target mo
791
791
  sandwich norms constrain what enters the residual stream, but they do not prevent a large raw FFN
792
792
  down-projection output before its post-branch norm; that tensor still requires measurement during
793
793
  quantization calibration.
794
+
795
+
796
+ ## Optional internal dimension rounding
797
+
798
+ ### Observation
799
+
800
+ Attention and feed-forward configs warn when internal widths are not multiples of 64, but
801
+ previously required callers to adjust head dimensions or feed-forward multipliers manually.
802
+
803
+ ### Decision
804
+
805
+ Add shared immutable `DimensionRoundingConfig` with a positive `multiple_of` and explicit
806
+ `floor`/`ceil` rounding mode. Every attention and feed-forward variant accepts an optional
807
+ `dimension_rounding` policy. Attention stores the effective head width during field validation;
808
+ feed-forward rounds its hidden width after the existing gated/non-gated formula. Existing
809
+ factories and modules consume those dimensions without new forward-path branches. External
810
+ model width is preserved, and a zero-width floor is rejected during config admission. Defaults
811
+ preserve existing widths and warnings. Opting in can change checkpoint shapes and parameter counts.
812
+
813
+ ### Validation
814
+
815
+ Regression coverage includes both directions, exact multiples, default head widths, invalid
816
+ policies, zero-width floors, every attention/feed-forward variant, JSON round-trips, and output
817
+ parity against explicit effective dimensions across the available device/dtype combinations.
818
+ `just check` passes formatting, lint, and type checks, with 3,481 tests passed, 21 skipped,
819
+ and 252 expected failures on this machine.
820
+
821
+ ### Unproven
822
+
823
+ No throughput benchmark or training ablation establishes a speed or quality benefit. Rounding
824
+ only selects internal geometry; other matrix dimensions and the workload still affect efficiency.
@@ -65,6 +65,7 @@ from stackformers.decoder_cache import (
65
65
  CachedSandwichNormDecoderLayer,
66
66
  DecoderCrossAttentionCacheBuilder,
67
67
  )
68
+ from stackformers.dimension_rounding import DimensionRoundingConfig
68
69
  from stackformers.encoder import Encoder
69
70
  from stackformers.feedforward import (
70
71
  GEGLU,
@@ -175,6 +176,7 @@ from stackformers.sequence import (
175
176
  )
176
177
 
177
178
  __all__ = [
179
+ "DimensionRoundingConfig",
178
180
  "AllValid",
179
181
  "materialize_padding_mask",
180
182
  "AllValidCachedDecoderWrapper",
@@ -145,3 +145,23 @@ callers do not construct a second metadata record. Legacy `PackedSequence` argum
145
145
  accepted by the low-level helpers. Cached cross-attention accepts `PaddedTensor` directly
146
146
  as context validity as well as the deprecated `PaddedSequence` record. Cache builder outputs
147
147
  retain mask-only metadata for compatibility with existing exported cache structures.
148
+
149
+ ## Optional dimension rounding
150
+
151
+ Every variant accepts `dimension_rounding: DimensionRoundingConfig | None`, imported from
152
+ `stackformers`. The default `None` preserves existing widths and warnings. For example:
153
+
154
+ ```python
155
+ from stackformers import DimensionRoundingConfig
156
+
157
+ rounding = DimensionRoundingConfig(multiple_of=64, rounding_mode="ceil")
158
+ ```
159
+
160
+ Pass `dimension_rounding=rounding` to the config to round `dim_head`.
161
+ `"floor"` rounds down; `"ceil"` rounds up and is the default. Exact multiples stay unchanged;
162
+ a result of zero is rejected during config validation. The external model width stays unchanged.
163
+ This selects actual parameter shapes rather than padding tensors, so enabling it can change
164
+ parameter counts and checkpoint compatibility. Positional encodings must use the effective
165
+ attention head width. Rounding does not guarantee faster execution; alignment warnings still
166
+ apply if the effective width is not a multiple of 64. New variants should reuse the shared
167
+ config behavior so factories and modules consume the same effective width.
@@ -5,9 +5,18 @@ from __future__ import annotations
5
5
  import warnings
6
6
  from typing import Annotated, Literal, Self
7
7
 
8
- from pydantic import BaseModel, BeforeValidator, Field, JsonValue, model_validator
8
+ from pydantic import (
9
+ BaseModel,
10
+ BeforeValidator,
11
+ Field,
12
+ JsonValue,
13
+ ValidationInfo,
14
+ field_validator,
15
+ model_validator,
16
+ )
9
17
 
10
18
  from stackformers._result import unwrap_or_raise
19
+ from stackformers.dimension_rounding import DimensionRoundingConfig
11
20
  from stackformers.result import Err, Ok, Result
12
21
 
13
22
  _ALIGN = 64 # tensor-core alignment for FP16/BF16
@@ -52,8 +61,10 @@ class _SelfAttentionConfigBase(BaseModel, frozen=True):
52
61
  description="Model (embedding) dimension — input and output width of the attention sublayer.", # noqa: E501
53
62
  )
54
63
  heads: int = Field(default=8, gt=0, description="Number of query heads.")
64
+ dimension_rounding: DimensionRoundingConfig | None = None
55
65
  dim_head: int = Field(
56
66
  default=64,
67
+ validate_default=True,
57
68
  gt=0,
58
69
  description=(
59
70
  "Dimension per head. Internal query width is heads * dim_head,"
@@ -94,6 +105,16 @@ class _SelfAttentionConfigBase(BaseModel, frozen=True):
94
105
  ),
95
106
  )
96
107
 
108
+ @field_validator("dim_head")
109
+ @classmethod
110
+ def _round_dim_head(cls, value: int, info: ValidationInfo) -> int:
111
+ """Resolve head geometry before admission, warnings, and module construction."""
112
+ match info.data.get("dimension_rounding"):
113
+ case DimensionRoundingConfig() as rounding:
114
+ return unwrap_or_raise(rounding.round_dimension(value))
115
+ case _:
116
+ return value
117
+
97
118
  @model_validator(mode="after")
98
119
  def _validate(self) -> Self:
99
120
  """Translate core validation failures into the existing Pydantic error contract."""
@@ -190,8 +211,10 @@ class _CrossAttentionConfigBase(BaseModel, frozen=True):
190
211
  description="Model (embedding) dimension — input and output width of the attention sublayer.", # noqa: E501
191
212
  )
192
213
  heads: int = Field(default=8, gt=0, description="Number of query heads.")
214
+ dimension_rounding: DimensionRoundingConfig | None = None
193
215
  dim_head: int = Field(
194
216
  default=64,
217
+ validate_default=True,
195
218
  gt=0,
196
219
  description=(
197
220
  "Dimension per head. Internal query width is heads * dim_head,"
@@ -219,6 +242,16 @@ class _CrossAttentionConfigBase(BaseModel, frozen=True):
219
242
  ),
220
243
  )
221
244
 
245
+ @field_validator("dim_head")
246
+ @classmethod
247
+ def _round_dim_head(cls, value: int, info: ValidationInfo) -> int:
248
+ """Resolve head geometry before admission, warnings, and module construction."""
249
+ match info.data.get("dimension_rounding"):
250
+ case DimensionRoundingConfig() as rounding:
251
+ return unwrap_or_raise(rounding.round_dimension(value))
252
+ case _:
253
+ return value
254
+
222
255
  @model_validator(mode="after")
223
256
  def _validate(self) -> Self:
224
257
  """Translate core validation failures into the existing Pydantic error contract."""
@@ -0,0 +1,27 @@
1
+ """Construction-time rounding of internal model widths to positive multiples."""
2
+
3
+ from typing import Literal, assert_never
4
+
5
+ from pydantic import BaseModel, Field
6
+
7
+ from stackformers.result import Err, Ok, Result
8
+
9
+
10
+ class DimensionRoundingConfig(BaseModel, frozen=True):
11
+ """Choose a width multiple and direction; this changes parameter shapes, not padding."""
12
+
13
+ multiple_of: int = Field(gt=0, description="Positive multiple required of the rounded width.")
14
+ rounding_mode: Literal["floor", "ceil"] = "ceil"
15
+
16
+ def round_dimension(self, dimension: int) -> Result[int, ValueError]:
17
+ """Return a rounded positive width, or a failure when rounding produces zero."""
18
+ match self.rounding_mode:
19
+ case "floor":
20
+ rounded = dimension // self.multiple_of * self.multiple_of
21
+ case "ceil":
22
+ rounded = (dimension + self.multiple_of - 1) // self.multiple_of * self.multiple_of
23
+ case _:
24
+ assert_never(self.rounding_mode)
25
+ if rounded <= 0:
26
+ return Err(ValueError("Dimension rounding must produce a positive width"))
27
+ return Ok(rounded)
@@ -37,3 +37,23 @@ result of the first.
37
37
  1. Add a config class to `config.py` (or reuse `FeedForwardConfig` if parameterisation is identical).
38
38
  2. Implement the class satisfying `FeedForward` structurally.
39
39
  3. Add a `case` branch in `factory.py::build_ff`.
40
+
41
+ ## Optional dimension rounding
42
+
43
+ Every variant accepts `dimension_rounding: DimensionRoundingConfig | None`, imported from
44
+ `stackformers`. The default `None` preserves existing widths and warnings. For example:
45
+
46
+ ```python
47
+ from stackformers import DimensionRoundingConfig
48
+
49
+ rounding = DimensionRoundingConfig(multiple_of=64, rounding_mode="ceil")
50
+ ```
51
+
52
+ Pass `dimension_rounding=rounding` to the config to round `inner_dim` after the gated or
53
+ non-gated width formula.
54
+ `"floor"` rounds down; `"ceil"` rounds up and is the default. Exact multiples stay unchanged;
55
+ a result of zero is rejected during config validation. The external model width stays unchanged.
56
+ This selects actual parameter shapes rather than padding tensors, so enabling it can change
57
+ parameter counts and checkpoint compatibility. Rounding does not guarantee faster execution; alignment warnings still
58
+ apply if the effective width is not a multiple of 64. New variants should reuse the shared
59
+ config behavior so factories and modules consume the same effective width.
@@ -8,12 +8,16 @@ from typing import Annotated, Literal
8
8
  from pydantic import BaseModel, Field, model_validator
9
9
  from typing_extensions import override
10
10
 
11
+ from stackformers._result import unwrap_or_raise
12
+ from stackformers.dimension_rounding import DimensionRoundingConfig
13
+
11
14
 
12
15
  class _FFBase(BaseModel):
13
16
  """Provide shared geometry and alignment checks for feed-forward variants."""
14
17
 
15
18
  dim: int = Field(gt=0)
16
19
  mult: float = Field(default=4.0, gt=0.0)
20
+ dimension_rounding: DimensionRoundingConfig | None = None
17
21
  dropout: float = Field(default=0.0, ge=0.0, le=1.0)
18
22
 
19
23
  _ALIGN = 64 # tensor-core alignment for FP16/BF16
@@ -35,6 +39,16 @@ class _FFBase(BaseModel):
35
39
 
36
40
  @property
37
41
  def inner_dim(self) -> int:
42
+ """Return the effective hidden width, applying optional rounding after GLU scaling."""
43
+ dimension = self._unrounded_inner_dim
44
+ match self.dimension_rounding:
45
+ case DimensionRoundingConfig() as rounding:
46
+ return unwrap_or_raise(rounding.round_dimension(dimension))
47
+ case None:
48
+ return dimension
49
+
50
+ @property
51
+ def _unrounded_inner_dim(self) -> int:
38
52
  """Return the parameter-matched hidden width for gated variants."""
39
53
  # Two gate matrices → scale inner dim down to match param count with GELU-4x FFN.
40
54
  return int(self.dim * self.mult * 2 / 3)
@@ -83,7 +97,7 @@ class GELUConfig(_FFBase):
83
97
 
84
98
  @property
85
99
  @override
86
- def inner_dim(self) -> int:
100
+ def _unrounded_inner_dim(self) -> int:
87
101
  """Return the hidden width for the non-gated network."""
88
102
  return int(self.dim * self.mult)
89
103
 
@@ -99,7 +113,7 @@ class ReluSquaredConfig(_FFBase):
99
113
 
100
114
  @property
101
115
  @override
102
- def inner_dim(self) -> int:
116
+ def _unrounded_inner_dim(self) -> int:
103
117
  """Return the hidden width for the non-gated network."""
104
118
  return int(self.dim * self.mult)
105
119