stackformers 5.0.0rc22__tar.gz → 5.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/CHANGELOG.md +70 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/PKG-INFO +37 -25
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/README.md +35 -23
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/docs/improvement-plan.md +2 -2
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/docs/research.md +5 -3
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/pyproject.toml +2 -2
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/DEVLOG.md +44 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/__init__.py +2 -0
- stackformers-5.1.1/stackformers/alignment.py +27 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/README.md +20 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/config.py +34 -1
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/README.md +20 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/config.py +16 -2
- stackformers-5.1.1/tests/attention/test_config.py +122 -0
- stackformers-5.1.1/tests/feedforward/test_config.py +112 -0
- stackformers-5.1.1/tests/test_alignment.py +34 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/uv.lock +1 -1
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/.claudeignore +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/.github/pull_request_template.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/.github/workflows/check.yml +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/.gitignore +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/.python-version +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/.vscode/settings.json +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/AGENTS.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/CITATION.cff +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/CONTRIBUTING.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/Justfile +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/LICENSE +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/PLAN.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/docs/api-guide.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/docs/assets/social-preview.jpg +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/docs/assets/social-preview.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/docs/compatibility.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/docs/inference.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/examples/README.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/examples/causal_language_model.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/examples/encoder_decoder_onnxruntime.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/examples/image_encoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/examples/padded_and_packed.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/examples/point_cloud_encoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/examples/subclassed_encoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/pyrefly.toml +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/pytest.ini +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/ruff.toml +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/_decoder_equations.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/_projection_packing.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/_result.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/all_valid_decoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/__init__.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/all_valid.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/bias.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/cache.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/cache_validation.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/cached.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/cross_attn.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/distance_bias.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/factory.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/layout.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/masking.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/onnx_backend.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/ops.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/packed_cross_attn.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/packed_self_attn.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/protocols.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/self_attn.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/attention/varlen_backend.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/config.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/cross_attender.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/decoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/decoder_cache.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/encoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/DEVLOG.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/__init__.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/factory.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/geglu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/gelu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/hardswish_glu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/packed_geglu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/packed_hardswish_glu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/packed_swiglu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/protocols.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/relu_squared.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/feedforward/swiglu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/layers.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/mlm/README.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/mlm/config.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/mlm/head.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/mlm/head_cosine.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/mlm/masking.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/mlm/protocols.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/mlm/wrapper.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/norm/README.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/norm/__init__.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/norm/config.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/norm/factory.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/norm/protocols.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/packing.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/positional/README.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/positional/__init__.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/positional/config.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/positional/factory.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/positional/learned.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/positional/none.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/positional/protocols.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/positional/rope1d.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/positional/rope2d.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/positional/rope_nd.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/positional/validation.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/preallocated_decoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/presets/README.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/presets/__init__.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/presets/cross_attender.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/presets/decoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/presets/encoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/presets/variable_width_encoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/py.typed +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/result/README.md +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/result/__init__.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/stackformers/sequence.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/__init__.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/__init__.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/legacy_api_rc1.json +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_all_valid.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_cached.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_contracts.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_cross_attn.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_cross_attn_cache.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_distance_bias.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_empty_rows.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_factory.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_geometry.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_kernels.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_legacy_api.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_masking.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_onnx_backend.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_ops.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_packed_cross_attn.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_packed_self_attn.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_sdpa_export.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_self_attn.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/attention/test_varlen_backend.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/conftest.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/export_utils.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/feedforward/__init__.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/feedforward/legacy_swiglu_4_6.json +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/feedforward/test_factory.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/feedforward/test_geglu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/feedforward/test_gelu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/feedforward/test_hardswish_glu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/feedforward/test_packed_geglu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/feedforward/test_packed_hardswish_glu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/feedforward/test_packed_swiglu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/feedforward/test_relu_squared.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/feedforward/test_swiglu.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/mlm/__init__.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/mlm/test_empty_selection.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/mlm/test_head.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/mlm/test_head_cosine.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/mlm/test_masking.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/mlm/test_wrapper.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/norm_topology_helpers.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/positional/__init__.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/positional/test_cacheable.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/positional/test_learned_pos.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/positional/test_rope.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/positional/test_rope_nd.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/presets/__init__.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/presets/test_cross_attender.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/presets/test_decoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/presets/test_encoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/presets/test_projection_packing.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/presets/test_variable_width_encoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_all_valid_decoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_core_results.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_cross_attender.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_decoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_decoder_cache.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_decoder_equations.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_encoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_encoder_decoder_example.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_examples.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_export_utils.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_layers.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_norm.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_packing.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_preallocated_decoder.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_projection_packing.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_public_api.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_result.py +0 -0
- {stackformers-5.0.0rc22 → stackformers-5.1.1}/tests/test_sequence.py +0 -0
|
@@ -6,6 +6,76 @@ 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.1]
|
|
10
|
+
|
|
11
|
+
### Improvements
|
|
12
|
+
|
|
13
|
+
- Rename `DimensionRoundingConfig` to `AlignmentConfig` and the attention/feed-forward
|
|
14
|
+
config field `dimension_rounding` to `alignment`. Import the shared type from
|
|
15
|
+
`stackformers` or `stackformers.alignment`; update existing configuration payloads to
|
|
16
|
+
use `alignment`. Rounding behavior and defaults are unchanged.
|
|
17
|
+
|
|
18
|
+
## [5.1.0]
|
|
19
|
+
|
|
20
|
+
### New Features
|
|
21
|
+
|
|
22
|
+
- Add optional `DimensionRoundingConfig(multiple_of=..., rounding_mode="floor" | "ceil")`
|
|
23
|
+
to all attention and feed-forward variants through `dimension_rounding`. Round attention
|
|
24
|
+
head widths and feed-forward hidden widths without changing the external model dimension.
|
|
25
|
+
Defaults preserve existing geometry; opting in may change parameter counts and checkpoint
|
|
26
|
+
shapes. Zero-width rounding results fail config validation.
|
|
27
|
+
|
|
28
|
+
## [5.0.0]
|
|
29
|
+
|
|
30
|
+
### Highlights
|
|
31
|
+
|
|
32
|
+
- Release the 5.0 candidate series as stable, with canonical tensor batches, composable
|
|
33
|
+
architecture variants, and cached deployment adapters. Library runtime behavior is unchanged
|
|
34
|
+
from `5.0.0rc22`; the sections below summarize migration from 4.x and earlier candidates.
|
|
35
|
+
|
|
36
|
+
### Backwards Incompatible Changes
|
|
37
|
+
|
|
38
|
+
- Attention configurations are immutable. Construct a new configuration and model instead of
|
|
39
|
+
assigning architecture fields on an existing `SelfAttentionConfig` or `CrossAttentionConfig`.
|
|
40
|
+
- Cross-attention requires matching padded/packed query and context layouts. Convert both inputs
|
|
41
|
+
to the same layout before calling it; mixed layouts raise `ValueError`.
|
|
42
|
+
- Custom reconstruction heads must return a differentiable zero loss when no tokens are selected.
|
|
43
|
+
For an empty prediction tensor, return `prediction.sum()`.
|
|
44
|
+
- Custom layers and attention implementations must accept and forward the runtime visibility
|
|
45
|
+
keywords they support (`self_attn_mask` and `cross_attn_mask`).
|
|
46
|
+
- Consumers of core outcomes from early candidates must replace the external `returns` API with
|
|
47
|
+
`stackformers.result.Ok` / `Err` keyword matching. Earlier `AllValidInput` callers must use
|
|
48
|
+
`PaddedTensor(x, AllValid(), positions)`.
|
|
49
|
+
|
|
50
|
+
### Deprecations
|
|
51
|
+
|
|
52
|
+
- Prefer `PaddedTensor` and `PackedTensor` to the retained `PaddedInput` and `PackedInput` aliases.
|
|
53
|
+
Use their constructors and conversion methods instead of deprecated sequence helpers. No
|
|
54
|
+
removal version is assigned; see `5.0.0rc21` for the full compatibility list.
|
|
55
|
+
|
|
56
|
+
### New Features
|
|
57
|
+
|
|
58
|
+
- Add list/nested-tensor adapters and padded/packed conversions preserving valid tokens,
|
|
59
|
+
gradients, and custom coordinates where documented.
|
|
60
|
+
- Add variable-width encoders, per-call attention visibility, and the HardSwishGLU variant.
|
|
61
|
+
- Add opt-in projection packing and unpacking for attention and gated feed-forward modules.
|
|
62
|
+
Convert before constructing an optimizer and save the resulting configuration with weights.
|
|
63
|
+
- Add cached encoder-decoder deployment adapters, including separate all-valid and preallocated
|
|
64
|
+
cache strategies. Their supported classes, opsets, and ownership contracts are documented in
|
|
65
|
+
`docs/inference.md`; custom forwards require their own deployment integration.
|
|
66
|
+
|
|
67
|
+
### Bug Fixes
|
|
68
|
+
|
|
69
|
+
- Return finite zero losses for empty built-in MLM selections and zero attention contributions
|
|
70
|
+
when every key is excluded.
|
|
71
|
+
- Fix attention-mask and dynamic GQA export paths covered by the PyTorch/ONNX Runtime tests.
|
|
72
|
+
|
|
73
|
+
### Documentation
|
|
74
|
+
|
|
75
|
+
- Lead installation with PyPI commands for pip and uv. Document opt-in prerelease upgrades with
|
|
76
|
+
`--pre` or `--prerelease allow`; keep repository cloning in contributor instructions.
|
|
77
|
+
- Add research reproducibility, compatibility, and citation guidance alongside runnable examples.
|
|
78
|
+
|
|
9
79
|
## [5.0.0rc22]
|
|
10
80
|
|
|
11
81
|
### Documentation
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: stackformers
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.1.1
|
|
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 ::
|
|
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
|
[](https://github.com/Red-Eyed/stackformers/actions/workflows/check.yml)
|
|
55
|
-
[](https://pypi.org/project/stackformers/)
|
|
56
56
|
[](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
|
-
##
|
|
71
|
+
## Install
|
|
72
72
|
|
|
73
|
-
|
|
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
|
-
|
|
78
|
-
cd stackformers
|
|
79
|
-
uv run examples/padded_and_packed.py
|
|
76
|
+
pip install --upgrade stackformers
|
|
80
77
|
```
|
|
81
78
|
|
|
82
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
##
|
|
126
|
+
## Explore examples
|
|
116
127
|
|
|
117
|
-
|
|
118
|
-
`uv run` prepares the project environment automatically.
|
|
128
|
+
Browse complete examples for common tasks:
|
|
119
129
|
|
|
120
|
-
| Your task |
|
|
121
|
-
| --- | --- |
|
|
122
|
-
| Image patches and 2-D positions | [Image encoder](examples/image_encoder.py) |
|
|
123
|
-
| Continuous spatial coordinates | [Point-cloud encoder](examples/point_cloud_encoder.py) |
|
|
124
|
-
| Unequal sequence lengths | [Padded and packed](examples/padded_and_packed.py) |
|
|
125
|
-
| Replace a model component | [Custom encoders](examples/subclassed_encoder.py) |
|
|
126
|
-
| Autoregressive token modeling | [Causal language model](examples/causal_language_model.py) |
|
|
127
|
-
| Export an encoder–decoder | [ONNX Runtime guide](examples/README.md#encoderdecoder-onnx-runtime) |
|
|
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
|
[](https://github.com/Red-Eyed/stackformers/actions/workflows/check.yml)
|
|
4
|
-
[](https://pypi.org/project/stackformers/)
|
|
5
5
|
[](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
|
-
##
|
|
20
|
+
## Install
|
|
21
21
|
|
|
22
|
-
|
|
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
|
-
|
|
27
|
-
cd stackformers
|
|
28
|
-
uv run examples/padded_and_packed.py
|
|
25
|
+
pip install --upgrade stackformers
|
|
29
26
|
```
|
|
30
27
|
|
|
31
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
##
|
|
75
|
+
## Explore examples
|
|
65
76
|
|
|
66
|
-
|
|
67
|
-
`uv run` prepares the project environment automatically.
|
|
77
|
+
Browse complete examples for common tasks:
|
|
68
78
|
|
|
69
|
-
| Your task |
|
|
70
|
-
| --- | --- |
|
|
71
|
-
| Image patches and 2-D positions | [Image encoder](examples/image_encoder.py) |
|
|
72
|
-
| Continuous spatial coordinates | [Point-cloud encoder](examples/point_cloud_encoder.py) |
|
|
73
|
-
| Unequal sequence lengths | [Padded and packed](examples/padded_and_packed.py) |
|
|
74
|
-
| Replace a model component | [Custom encoders](examples/subclassed_encoder.py) |
|
|
75
|
-
| Autoregressive token modeling | [Causal language model](examples/causal_language_model.py) |
|
|
76
|
-
| Export an encoder–decoder | [ONNX Runtime guide](examples/README.md#encoderdecoder-onnx-runtime) |
|
|
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.
|
|
42
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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.
|
|
7
|
+
version = "5.1.1"
|
|
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 ::
|
|
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,47 @@ 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.
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
## Alignment configuration naming
|
|
828
|
+
|
|
829
|
+
Rename the shared policy to `AlignmentConfig` in `alignment.py` and its config field to
|
|
830
|
+
`alignment`, reflecting the hardware goal while retaining `rounding_mode` for the mechanism.
|
|
831
|
+
Update imports, config payloads, tests, and module documentation together. The floor/ceil
|
|
832
|
+
behavior, zero-width rejection, and disabled defaults remain unchanged. This is the requested
|
|
833
|
+
5.1.1 patch naming correction; callers using the previous names must update them.
|
|
834
|
+
|
|
835
|
+
Validation: repository formatting, lint, and type checks pass; 264 focused alignment,
|
|
836
|
+
attention/feed-forward config, factory, and projection-packing tests pass. Runtime version
|
|
837
|
+
reports 5.1.1.
|
|
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING
|
|
|
5
5
|
|
|
6
6
|
__version__ = version("stackformers")
|
|
7
7
|
|
|
8
|
+
from stackformers.alignment import AlignmentConfig
|
|
8
9
|
from stackformers.all_valid_decoder import (
|
|
9
10
|
AllValidCachedDecoderWrapper,
|
|
10
11
|
AllValidCrossAttentionCacheBuilder,
|
|
@@ -175,6 +176,7 @@ from stackformers.sequence import (
|
|
|
175
176
|
)
|
|
176
177
|
|
|
177
178
|
__all__ = [
|
|
179
|
+
"AlignmentConfig",
|
|
178
180
|
"AllValid",
|
|
179
181
|
"materialize_padding_mask",
|
|
180
182
|
"AllValidCachedDecoderWrapper",
|
|
@@ -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 AlignmentConfig(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)
|
|
@@ -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 `alignment: AlignmentConfig | None`, imported from
|
|
152
|
+
`stackformers`. The default `None` preserves existing widths and warnings. For example:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from stackformers import AlignmentConfig
|
|
156
|
+
|
|
157
|
+
rounding = AlignmentConfig(multiple_of=64, rounding_mode="ceil")
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Pass `alignment=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
|
|
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.alignment import AlignmentConfig
|
|
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
|
+
alignment: AlignmentConfig | 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("alignment"):
|
|
113
|
+
case AlignmentConfig() 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
|
+
alignment: AlignmentConfig | 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("alignment"):
|
|
250
|
+
case AlignmentConfig() 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."""
|
|
@@ -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 `alignment: AlignmentConfig | None`, imported from
|
|
44
|
+
`stackformers`. The default `None` preserves existing widths and warnings. For example:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from stackformers import AlignmentConfig
|
|
48
|
+
|
|
49
|
+
rounding = AlignmentConfig(multiple_of=64, rounding_mode="ceil")
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Pass `alignment=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.alignment import AlignmentConfig
|
|
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
|
+
alignment: AlignmentConfig | 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.alignment:
|
|
45
|
+
case AlignmentConfig() 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
|
|
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
|
|
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
|
|