stackformers 5.0.0rc14__tar.gz → 5.0.0rc17__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.0rc17/:memory:.ses +2 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/CHANGELOG.md +34 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/PKG-INFO +42 -53
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/README.md +41 -52
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/pyproject.toml +1 -1
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/DEVLOG.md +30 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/__init__.py +28 -1
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/README.md +18 -2
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/cache_validation.py +3 -2
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/cached.py +56 -20
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/cross_attn.py +7 -3
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/ops.py +14 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/packed_cross_attn.py +7 -3
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/packed_self_attn.py +7 -3
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/self_attn.py +7 -3
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/decoder_cache.py +24 -14
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/packing.py +2 -6
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/presets/README.md +3 -1
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_cross_attn_cache.py +28 -9
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_ops.py +37 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_packed_cross_attn.py +58 -16
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_packed_self_attn.py +51 -15
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_self_attn.py +19 -3
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/feedforward/test_packed_geglu.py +32 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/feedforward/test_packed_hardswish_glu.py +32 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/feedforward/test_packed_swiglu.py +32 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/presets/test_variable_width_encoder.py +7 -3
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_core_results.py +5 -2
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_decoder_cache.py +122 -20
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_packing.py +19 -10
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_public_api.py +64 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/uv.lock +33 -33
- stackformers-5.0.0rc14/run-remote-tests.sh +0 -24
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/.claudeignore +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/.gitignore +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/.python-version +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/.vscode/settings.json +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/AGENTS.md +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/Justfile +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/LICENSE +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/PLAN.md +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/examples/README.md +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/examples/causal_language_model.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/examples/encoder_decoder_onnxruntime.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/examples/image_encoder.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/examples/padded_and_packed.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/examples/point_cloud_encoder.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/examples/subclassed_encoder.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/pyrefly.toml +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/pytest.ini +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/ruff.toml +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/_projection_packing.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/_result.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/__init__.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/bias.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/cache.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/config.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/distance_bias.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/factory.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/layout.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/masking.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/protocols.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/varlen_backend.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/config.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/cross_attender.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/decoder.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/encoder.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/DEVLOG.md +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/README.md +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/__init__.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/config.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/factory.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/geglu.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/gelu.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/hardswish_glu.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/packed_geglu.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/packed_hardswish_glu.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/packed_swiglu.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/protocols.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/relu_squared.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/feedforward/swiglu.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/layers.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/mlm/README.md +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/mlm/config.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/mlm/head.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/mlm/head_cosine.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/mlm/masking.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/mlm/protocols.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/mlm/wrapper.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/norm/README.md +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/norm/__init__.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/norm/config.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/norm/factory.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/norm/protocols.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/positional/README.md +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/positional/__init__.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/positional/config.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/positional/factory.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/positional/learned.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/positional/none.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/positional/protocols.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/positional/rope1d.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/positional/rope2d.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/positional/rope_nd.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/positional/validation.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/presets/__init__.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/presets/cross_attender.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/presets/decoder.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/presets/encoder.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/presets/variable_width_encoder.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/py.typed +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/result/README.md +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/result/__init__.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/sequence.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/__init__.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/__init__.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/legacy_api_rc1.json +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_contracts.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_cross_attn.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_distance_bias.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_empty_rows.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_factory.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_geometry.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_kernels.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_legacy_api.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_masking.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_sdpa_export.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/attention/test_varlen_backend.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/conftest.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/export_utils.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/feedforward/__init__.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/feedforward/legacy_swiglu_4_6.json +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/feedforward/test_factory.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/feedforward/test_geglu.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/feedforward/test_gelu.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/feedforward/test_hardswish_glu.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/feedforward/test_relu_squared.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/feedforward/test_swiglu.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/mlm/__init__.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/mlm/test_empty_selection.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/mlm/test_head.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/mlm/test_head_cosine.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/mlm/test_masking.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/mlm/test_wrapper.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/norm_topology_helpers.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/positional/__init__.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/positional/test_cacheable.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/positional/test_learned_pos.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/positional/test_rope.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/positional/test_rope_nd.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/presets/__init__.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/presets/test_cross_attender.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/presets/test_decoder.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/presets/test_encoder.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/presets/test_projection_packing.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_cross_attender.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_decoder.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_encoder.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_encoder_decoder_example.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_examples.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_layers.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_norm.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_projection_packing.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_result.py +0 -0
- {stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/tests/test_sequence.py +0 -0
|
@@ -6,6 +6,40 @@ 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.0.0rc17]
|
|
10
|
+
|
|
11
|
+
### New Features
|
|
12
|
+
|
|
13
|
+
- Support packed self- and cross-attention in existing KV-cache wrappers and cached decoder
|
|
14
|
+
ONNX export without changing wrapper calls, cache records, or cache tensor layouts.
|
|
15
|
+
- Allow `to_packed()` on existing cache executors. Converting a containing module preserves
|
|
16
|
+
shared attention references between the original model and its registered cache wrappers;
|
|
17
|
+
`to_unpacked()` restores the separate projection layout.
|
|
18
|
+
|
|
19
|
+
## [5.0.0rc16]
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
- Fix dynamic GQA export on PyTorch 2.11 for ordinary and packed self-/cross-attention.
|
|
24
|
+
Repeat KV heads in token-major layout to avoid symbolic reshape stride guards while
|
|
25
|
+
preserving head order, projection weights, and checkpoint layouts.
|
|
26
|
+
|
|
27
|
+
### Developers
|
|
28
|
+
|
|
29
|
+
- Require ONNX opsets 20–25 execution parity for ordinary and packed MHA/GQA/MQA attention,
|
|
30
|
+
packed SwiGLU/GEGLU/HardSwishGLU, and packed variable-width encoders. Cover static and
|
|
31
|
+
dynamic inputs, including singleton attention queries and feed-forward token axes.
|
|
32
|
+
- Remove the expected-failure exemption for packed attention dynamic export.
|
|
33
|
+
|
|
34
|
+
## [5.0.0rc15]
|
|
35
|
+
|
|
36
|
+
### Improvements
|
|
37
|
+
|
|
38
|
+
- Complete the `import stackformers as sf` API with sequence conversion helpers,
|
|
39
|
+
preset base classes, and cached decoder layer classes. Existing module imports remain valid.
|
|
40
|
+
- Use the `sf` namespace throughout the README examples and construct normalization through
|
|
41
|
+
`sf.build_norm()` instead of the unavailable `RMSNorm` import.
|
|
42
|
+
|
|
9
43
|
## [5.0.0rc14]
|
|
10
44
|
|
|
11
45
|
### New Features
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: stackformers
|
|
3
|
-
Version: 5.0.
|
|
3
|
+
Version: 5.0.0rc17
|
|
4
4
|
Summary: Typed, composable, SOLID transformer library for PyTorch
|
|
5
5
|
Project-URL: Homepage, https://github.com/Red-Eyed/stackformers
|
|
6
6
|
Project-URL: Repository, https://github.com/Red-Eyed/stackformers
|
|
@@ -78,51 +78,50 @@ stackformers takes a different approach:
|
|
|
78
78
|
|
|
79
79
|
## Quick start
|
|
80
80
|
|
|
81
|
+
Import the public API with `import stackformers as sf`. Configs, models, protocols,
|
|
82
|
+
base classes, factories, sequence helpers, and projection conversions are available
|
|
83
|
+
directly through `sf`.
|
|
84
|
+
|
|
81
85
|
### Zero boilerplate
|
|
82
86
|
|
|
83
87
|
```python
|
|
84
88
|
import torch
|
|
85
|
-
|
|
89
|
+
import stackformers as sf
|
|
86
90
|
|
|
87
|
-
model = TransformerEncoder(plain_encoder_config(dim=512, heads=8, num_layers=6))
|
|
91
|
+
model = sf.TransformerEncoder(sf.plain_encoder_config(dim=512, heads=8, num_layers=6))
|
|
88
92
|
|
|
89
93
|
x = torch.randn(2, 128, 512)
|
|
90
94
|
mask = torch.ones(2, 128, dtype=torch.bool)
|
|
91
|
-
out = model(make_padded_input(x, mask)) # (2, 128, 512)
|
|
95
|
+
out = model(sf.make_padded_input(x, mask)) # (2, 128, 512)
|
|
92
96
|
```
|
|
93
97
|
|
|
94
98
|
Switch to packed (variable-length, no padding waste) — same weights:
|
|
95
99
|
|
|
96
100
|
```python
|
|
97
|
-
from stackformers import make_packed_input
|
|
98
|
-
|
|
99
101
|
cu = torch.tensor([0, 64, 128], dtype=torch.int32)
|
|
100
|
-
out = model(make_packed_input(x_flat, cu, max_seqlen=64)) # (128, 512)
|
|
102
|
+
out = model(sf.make_packed_input(x_flat, cu, max_seqlen=64)) # (128, 512)
|
|
101
103
|
```
|
|
102
104
|
|
|
103
105
|
Causal LM backbone:
|
|
104
106
|
|
|
105
107
|
```python
|
|
106
|
-
plain_encoder_config(dim=768, heads=12, num_layers=12, causal=True)
|
|
108
|
+
sf.plain_encoder_config(dim=768, heads=12, num_layers=12, causal=True)
|
|
107
109
|
```
|
|
108
110
|
|
|
109
111
|
Sliding-window local attention (O(n · w)):
|
|
110
112
|
|
|
111
113
|
```python
|
|
112
|
-
|
|
113
|
-
windowed_encoder_config(dim=512, heads=8, num_layers=6, window_size=128)
|
|
114
|
+
sf.windowed_encoder_config(dim=512, heads=8, num_layers=6, window_size=128)
|
|
114
115
|
```
|
|
115
116
|
|
|
116
117
|
Variable-width encoder — one model and head dimension per Transformer block:
|
|
117
118
|
|
|
118
119
|
```python
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
config = variable_width_encoder_config(
|
|
120
|
+
config = sf.variable_width_encoder_config(
|
|
122
121
|
d_models=[512, 512, 768, 768, 1024],
|
|
123
122
|
dim_heads=[64, 64, 64, 64, 128],
|
|
124
123
|
)
|
|
125
|
-
model = VariableWidthTransformerEncoder(config)
|
|
124
|
+
model = sf.VariableWidthTransformerEncoder(config)
|
|
126
125
|
```
|
|
127
126
|
|
|
128
127
|
Omitting `heads` derives each block's head count as `d_model // dim_head`. Set `heads=12` or
|
|
@@ -143,10 +142,8 @@ a learned linear projection, so it is a related experimental variant rather than
|
|
|
143
142
|
Encoder–decoder:
|
|
144
143
|
|
|
145
144
|
```python
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
model = TransformerDecoder(plain_decoder_config(dim=512, heads=8, num_layers=6))
|
|
149
|
-
out = model(make_padded_input(x, mask), make_padded_input(context, ctx_mask))
|
|
145
|
+
model = sf.TransformerDecoder(sf.plain_decoder_config(dim=512, heads=8, num_layers=6))
|
|
146
|
+
out = model(sf.make_padded_input(x, mask), sf.make_padded_input(context, ctx_mask))
|
|
150
147
|
```
|
|
151
148
|
|
|
152
149
|
For autoregressive export, build cross K/V once and pass both required cache tensors to every
|
|
@@ -155,14 +152,11 @@ one-token decoder invocation:
|
|
|
155
152
|
```python
|
|
156
153
|
import torch
|
|
157
154
|
|
|
158
|
-
|
|
159
|
-
CachedDecoderWrapper,
|
|
160
|
-
DecoderCrossAttentionCacheBuilder,
|
|
161
|
-
)
|
|
155
|
+
import stackformers as sf
|
|
162
156
|
|
|
163
157
|
model.eval()
|
|
164
|
-
cache_builder = DecoderCrossAttentionCacheBuilder(model).eval()
|
|
165
|
-
cached_decoder = CachedDecoderWrapper(model).eval()
|
|
158
|
+
cache_builder = sf.DecoderCrossAttentionCacheBuilder(model).eval()
|
|
159
|
+
cached_decoder = sf.CachedDecoderWrapper(model).eval()
|
|
166
160
|
|
|
167
161
|
cross_cache = cache_builder(context_input)
|
|
168
162
|
self_kv_cache = torch.empty(num_layers, 2, batch, kv_heads, 0, dim_head)
|
|
@@ -191,23 +185,19 @@ See the complete eager, ONNX export, and raw ONNX Runtime demonstration in
|
|
|
191
185
|
Full control with JSON round-trip via `kind` discriminators:
|
|
192
186
|
|
|
193
187
|
```python
|
|
194
|
-
|
|
195
|
-
TransformerEncoderConfig, TransformerEncoder,
|
|
196
|
-
SelfAttentionConfig, SwiGLUConfig, RMSNormConfig, RoPE1DConfig,
|
|
197
|
-
make_padded_input,
|
|
198
|
-
)
|
|
188
|
+
import stackformers as sf
|
|
199
189
|
|
|
200
|
-
cfg = TransformerEncoderConfig(
|
|
201
|
-
attn=SelfAttentionConfig(dim=512, heads=8, dim_head=64, causal=False),
|
|
202
|
-
ff=SwiGLUConfig(dim=512, mult=4.0),
|
|
203
|
-
norm=RMSNormConfig(dim=512),
|
|
204
|
-
pos_encoding=RoPE1DConfig(dim_head=64),
|
|
190
|
+
cfg = sf.TransformerEncoderConfig(
|
|
191
|
+
attn=sf.SelfAttentionConfig(dim=512, heads=8, dim_head=64, causal=False),
|
|
192
|
+
ff=sf.SwiGLUConfig(dim=512, mult=4.0),
|
|
193
|
+
norm=sf.RMSNormConfig(dim=512),
|
|
194
|
+
pos_encoding=sf.RoPE1DConfig(dim_head=64),
|
|
205
195
|
num_layers=6,
|
|
206
196
|
)
|
|
207
|
-
model = TransformerEncoder(cfg)
|
|
197
|
+
model = sf.TransformerEncoder(cfg)
|
|
208
198
|
|
|
209
199
|
# Serialise / restore
|
|
210
|
-
cfg2 = TransformerEncoderConfig.model_validate(cfg.model_dump())
|
|
200
|
+
cfg2 = sf.TransformerEncoderConfig.model_validate(cfg.model_dump())
|
|
211
201
|
```
|
|
212
202
|
|
|
213
203
|
`norm_placement` is available on `TransformerEncoderConfig`, `TransformerDecoderConfig`, and
|
|
@@ -233,25 +223,21 @@ target/query residual stream; the context sequence is not normalized or mutated
|
|
|
233
223
|
Wire layers yourself when presets aren't enough:
|
|
234
224
|
|
|
235
225
|
```python
|
|
236
|
-
|
|
237
|
-
SelfAttention, SwiGLU, TransformerLayer, Encoder, RMSNorm,
|
|
238
|
-
RotaryEmbedding1D,
|
|
239
|
-
SelfAttentionConfig, SwiGLUConfig, RMSNormConfig, RoPE1DConfig,
|
|
240
|
-
)
|
|
226
|
+
import stackformers as sf
|
|
241
227
|
|
|
242
|
-
pos = RotaryEmbedding1D(RoPE1DConfig(dim_head=64))
|
|
243
|
-
attn = SelfAttention(SelfAttentionConfig(dim=512, heads=8, dim_head=64), pos_encoding=pos)
|
|
228
|
+
pos = sf.RotaryEmbedding1D(sf.RoPE1DConfig(dim_head=64))
|
|
229
|
+
attn = sf.SelfAttention(sf.SelfAttentionConfig(dim=512, heads=8, dim_head=64), pos_encoding=pos)
|
|
244
230
|
|
|
245
231
|
layers = [
|
|
246
|
-
TransformerLayer(
|
|
232
|
+
sf.TransformerLayer(
|
|
247
233
|
self_attn=attn,
|
|
248
|
-
ff=SwiGLU(SwiGLUConfig(dim=512)),
|
|
249
|
-
norm_attn=
|
|
250
|
-
norm_ff=
|
|
234
|
+
ff=sf.SwiGLU(sf.SwiGLUConfig(dim=512)),
|
|
235
|
+
norm_attn=sf.build_norm(sf.RMSNormConfig(dim=512)),
|
|
236
|
+
norm_ff=sf.build_norm(sf.RMSNormConfig(dim=512)),
|
|
251
237
|
)
|
|
252
238
|
for _ in range(6)
|
|
253
239
|
]
|
|
254
|
-
encoder = Encoder(layers=layers, final_norm=
|
|
240
|
+
encoder = sf.Encoder(layers=layers, final_norm=sf.build_norm(sf.RMSNormConfig(dim=512)))
|
|
255
241
|
```
|
|
256
242
|
|
|
257
243
|
---
|
|
@@ -262,12 +248,12 @@ Load an ordinary checkpoint, then recursively pack supported self-attention, cro
|
|
|
262
248
|
SwiGLU, GEGLU, and HardSwishGLU layers:
|
|
263
249
|
|
|
264
250
|
```python
|
|
265
|
-
|
|
251
|
+
import stackformers as sf
|
|
266
252
|
|
|
267
253
|
model.load_state_dict(checkpoint)
|
|
268
|
-
model = to_packed(model)
|
|
254
|
+
model = sf.to_packed(model)
|
|
269
255
|
# Run or save the packed model.
|
|
270
|
-
model = to_unpacked(model)
|
|
256
|
+
model = sf.to_unpacked(model)
|
|
271
257
|
```
|
|
272
258
|
|
|
273
259
|
These helpers replace registered children in place and return the root, which may itself be
|
|
@@ -280,8 +266,11 @@ and metadata; supported children are still visited.
|
|
|
280
266
|
Weights round-trip exactly; outputs match within dtype tolerance because matrix multiplication
|
|
281
267
|
rounding can change. Convert before constructing an optimizer: replaced projection parameters
|
|
282
268
|
do not migrate optimizer state, existing gradients, hooks, or cross-layer parameter aliases.
|
|
283
|
-
Groups with mixed `requires_grad` fail before mutation.
|
|
284
|
-
attention
|
|
269
|
+
Groups with mixed `requires_grad` fail before mutation. Cache wrappers support both ordinary and
|
|
270
|
+
packed attention with the same calls and cache tensor layouts. Pack the model before constructing
|
|
271
|
+
cache wrappers, or convert a containing module that registers the model and its existing wrappers
|
|
272
|
+
together so their attention references remain shared. Packing a wrapper alone converts only its
|
|
273
|
+
registered children; references outside that tree still point to the original attention modules.
|
|
285
274
|
Projection packing is independent of the `PackedInput` sequence layout.
|
|
286
275
|
|
|
287
276
|
## What's included
|
|
@@ -29,51 +29,50 @@ stackformers takes a different approach:
|
|
|
29
29
|
|
|
30
30
|
## Quick start
|
|
31
31
|
|
|
32
|
+
Import the public API with `import stackformers as sf`. Configs, models, protocols,
|
|
33
|
+
base classes, factories, sequence helpers, and projection conversions are available
|
|
34
|
+
directly through `sf`.
|
|
35
|
+
|
|
32
36
|
### Zero boilerplate
|
|
33
37
|
|
|
34
38
|
```python
|
|
35
39
|
import torch
|
|
36
|
-
|
|
40
|
+
import stackformers as sf
|
|
37
41
|
|
|
38
|
-
model = TransformerEncoder(plain_encoder_config(dim=512, heads=8, num_layers=6))
|
|
42
|
+
model = sf.TransformerEncoder(sf.plain_encoder_config(dim=512, heads=8, num_layers=6))
|
|
39
43
|
|
|
40
44
|
x = torch.randn(2, 128, 512)
|
|
41
45
|
mask = torch.ones(2, 128, dtype=torch.bool)
|
|
42
|
-
out = model(make_padded_input(x, mask)) # (2, 128, 512)
|
|
46
|
+
out = model(sf.make_padded_input(x, mask)) # (2, 128, 512)
|
|
43
47
|
```
|
|
44
48
|
|
|
45
49
|
Switch to packed (variable-length, no padding waste) — same weights:
|
|
46
50
|
|
|
47
51
|
```python
|
|
48
|
-
from stackformers import make_packed_input
|
|
49
|
-
|
|
50
52
|
cu = torch.tensor([0, 64, 128], dtype=torch.int32)
|
|
51
|
-
out = model(make_packed_input(x_flat, cu, max_seqlen=64)) # (128, 512)
|
|
53
|
+
out = model(sf.make_packed_input(x_flat, cu, max_seqlen=64)) # (128, 512)
|
|
52
54
|
```
|
|
53
55
|
|
|
54
56
|
Causal LM backbone:
|
|
55
57
|
|
|
56
58
|
```python
|
|
57
|
-
plain_encoder_config(dim=768, heads=12, num_layers=12, causal=True)
|
|
59
|
+
sf.plain_encoder_config(dim=768, heads=12, num_layers=12, causal=True)
|
|
58
60
|
```
|
|
59
61
|
|
|
60
62
|
Sliding-window local attention (O(n · w)):
|
|
61
63
|
|
|
62
64
|
```python
|
|
63
|
-
|
|
64
|
-
windowed_encoder_config(dim=512, heads=8, num_layers=6, window_size=128)
|
|
65
|
+
sf.windowed_encoder_config(dim=512, heads=8, num_layers=6, window_size=128)
|
|
65
66
|
```
|
|
66
67
|
|
|
67
68
|
Variable-width encoder — one model and head dimension per Transformer block:
|
|
68
69
|
|
|
69
70
|
```python
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
config = variable_width_encoder_config(
|
|
71
|
+
config = sf.variable_width_encoder_config(
|
|
73
72
|
d_models=[512, 512, 768, 768, 1024],
|
|
74
73
|
dim_heads=[64, 64, 64, 64, 128],
|
|
75
74
|
)
|
|
76
|
-
model = VariableWidthTransformerEncoder(config)
|
|
75
|
+
model = sf.VariableWidthTransformerEncoder(config)
|
|
77
76
|
```
|
|
78
77
|
|
|
79
78
|
Omitting `heads` derives each block's head count as `d_model // dim_head`. Set `heads=12` or
|
|
@@ -94,10 +93,8 @@ a learned linear projection, so it is a related experimental variant rather than
|
|
|
94
93
|
Encoder–decoder:
|
|
95
94
|
|
|
96
95
|
```python
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
model = TransformerDecoder(plain_decoder_config(dim=512, heads=8, num_layers=6))
|
|
100
|
-
out = model(make_padded_input(x, mask), make_padded_input(context, ctx_mask))
|
|
96
|
+
model = sf.TransformerDecoder(sf.plain_decoder_config(dim=512, heads=8, num_layers=6))
|
|
97
|
+
out = model(sf.make_padded_input(x, mask), sf.make_padded_input(context, ctx_mask))
|
|
101
98
|
```
|
|
102
99
|
|
|
103
100
|
For autoregressive export, build cross K/V once and pass both required cache tensors to every
|
|
@@ -106,14 +103,11 @@ one-token decoder invocation:
|
|
|
106
103
|
```python
|
|
107
104
|
import torch
|
|
108
105
|
|
|
109
|
-
|
|
110
|
-
CachedDecoderWrapper,
|
|
111
|
-
DecoderCrossAttentionCacheBuilder,
|
|
112
|
-
)
|
|
106
|
+
import stackformers as sf
|
|
113
107
|
|
|
114
108
|
model.eval()
|
|
115
|
-
cache_builder = DecoderCrossAttentionCacheBuilder(model).eval()
|
|
116
|
-
cached_decoder = CachedDecoderWrapper(model).eval()
|
|
109
|
+
cache_builder = sf.DecoderCrossAttentionCacheBuilder(model).eval()
|
|
110
|
+
cached_decoder = sf.CachedDecoderWrapper(model).eval()
|
|
117
111
|
|
|
118
112
|
cross_cache = cache_builder(context_input)
|
|
119
113
|
self_kv_cache = torch.empty(num_layers, 2, batch, kv_heads, 0, dim_head)
|
|
@@ -142,23 +136,19 @@ See the complete eager, ONNX export, and raw ONNX Runtime demonstration in
|
|
|
142
136
|
Full control with JSON round-trip via `kind` discriminators:
|
|
143
137
|
|
|
144
138
|
```python
|
|
145
|
-
|
|
146
|
-
TransformerEncoderConfig, TransformerEncoder,
|
|
147
|
-
SelfAttentionConfig, SwiGLUConfig, RMSNormConfig, RoPE1DConfig,
|
|
148
|
-
make_padded_input,
|
|
149
|
-
)
|
|
139
|
+
import stackformers as sf
|
|
150
140
|
|
|
151
|
-
cfg = TransformerEncoderConfig(
|
|
152
|
-
attn=SelfAttentionConfig(dim=512, heads=8, dim_head=64, causal=False),
|
|
153
|
-
ff=SwiGLUConfig(dim=512, mult=4.0),
|
|
154
|
-
norm=RMSNormConfig(dim=512),
|
|
155
|
-
pos_encoding=RoPE1DConfig(dim_head=64),
|
|
141
|
+
cfg = sf.TransformerEncoderConfig(
|
|
142
|
+
attn=sf.SelfAttentionConfig(dim=512, heads=8, dim_head=64, causal=False),
|
|
143
|
+
ff=sf.SwiGLUConfig(dim=512, mult=4.0),
|
|
144
|
+
norm=sf.RMSNormConfig(dim=512),
|
|
145
|
+
pos_encoding=sf.RoPE1DConfig(dim_head=64),
|
|
156
146
|
num_layers=6,
|
|
157
147
|
)
|
|
158
|
-
model = TransformerEncoder(cfg)
|
|
148
|
+
model = sf.TransformerEncoder(cfg)
|
|
159
149
|
|
|
160
150
|
# Serialise / restore
|
|
161
|
-
cfg2 = TransformerEncoderConfig.model_validate(cfg.model_dump())
|
|
151
|
+
cfg2 = sf.TransformerEncoderConfig.model_validate(cfg.model_dump())
|
|
162
152
|
```
|
|
163
153
|
|
|
164
154
|
`norm_placement` is available on `TransformerEncoderConfig`, `TransformerDecoderConfig`, and
|
|
@@ -184,25 +174,21 @@ target/query residual stream; the context sequence is not normalized or mutated
|
|
|
184
174
|
Wire layers yourself when presets aren't enough:
|
|
185
175
|
|
|
186
176
|
```python
|
|
187
|
-
|
|
188
|
-
SelfAttention, SwiGLU, TransformerLayer, Encoder, RMSNorm,
|
|
189
|
-
RotaryEmbedding1D,
|
|
190
|
-
SelfAttentionConfig, SwiGLUConfig, RMSNormConfig, RoPE1DConfig,
|
|
191
|
-
)
|
|
177
|
+
import stackformers as sf
|
|
192
178
|
|
|
193
|
-
pos = RotaryEmbedding1D(RoPE1DConfig(dim_head=64))
|
|
194
|
-
attn = SelfAttention(SelfAttentionConfig(dim=512, heads=8, dim_head=64), pos_encoding=pos)
|
|
179
|
+
pos = sf.RotaryEmbedding1D(sf.RoPE1DConfig(dim_head=64))
|
|
180
|
+
attn = sf.SelfAttention(sf.SelfAttentionConfig(dim=512, heads=8, dim_head=64), pos_encoding=pos)
|
|
195
181
|
|
|
196
182
|
layers = [
|
|
197
|
-
TransformerLayer(
|
|
183
|
+
sf.TransformerLayer(
|
|
198
184
|
self_attn=attn,
|
|
199
|
-
ff=SwiGLU(SwiGLUConfig(dim=512)),
|
|
200
|
-
norm_attn=
|
|
201
|
-
norm_ff=
|
|
185
|
+
ff=sf.SwiGLU(sf.SwiGLUConfig(dim=512)),
|
|
186
|
+
norm_attn=sf.build_norm(sf.RMSNormConfig(dim=512)),
|
|
187
|
+
norm_ff=sf.build_norm(sf.RMSNormConfig(dim=512)),
|
|
202
188
|
)
|
|
203
189
|
for _ in range(6)
|
|
204
190
|
]
|
|
205
|
-
encoder = Encoder(layers=layers, final_norm=
|
|
191
|
+
encoder = sf.Encoder(layers=layers, final_norm=sf.build_norm(sf.RMSNormConfig(dim=512)))
|
|
206
192
|
```
|
|
207
193
|
|
|
208
194
|
---
|
|
@@ -213,12 +199,12 @@ Load an ordinary checkpoint, then recursively pack supported self-attention, cro
|
|
|
213
199
|
SwiGLU, GEGLU, and HardSwishGLU layers:
|
|
214
200
|
|
|
215
201
|
```python
|
|
216
|
-
|
|
202
|
+
import stackformers as sf
|
|
217
203
|
|
|
218
204
|
model.load_state_dict(checkpoint)
|
|
219
|
-
model = to_packed(model)
|
|
205
|
+
model = sf.to_packed(model)
|
|
220
206
|
# Run or save the packed model.
|
|
221
|
-
model = to_unpacked(model)
|
|
207
|
+
model = sf.to_unpacked(model)
|
|
222
208
|
```
|
|
223
209
|
|
|
224
210
|
These helpers replace registered children in place and return the root, which may itself be
|
|
@@ -231,8 +217,11 @@ and metadata; supported children are still visited.
|
|
|
231
217
|
Weights round-trip exactly; outputs match within dtype tolerance because matrix multiplication
|
|
232
218
|
rounding can change. Convert before constructing an optimizer: replaced projection parameters
|
|
233
219
|
do not migrate optimizer state, existing gradients, hooks, or cross-layer parameter aliases.
|
|
234
|
-
Groups with mixed `requires_grad` fail before mutation.
|
|
235
|
-
attention
|
|
220
|
+
Groups with mixed `requires_grad` fail before mutation. Cache wrappers support both ordinary and
|
|
221
|
+
packed attention with the same calls and cache tensor layouts. Pack the model before constructing
|
|
222
|
+
cache wrappers, or convert a containing module that registers the model and its existing wrappers
|
|
223
|
+
together so their attention references remain shared. Packing a wrapper alone converts only its
|
|
224
|
+
registered children; references outside that tree still point to the original attention modules.
|
|
236
225
|
Projection packing is independent of the `PackedInput` sequence layout.
|
|
237
226
|
|
|
238
227
|
## What's included
|
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Transformer model development log
|
|
2
2
|
|
|
3
|
+
## 2026-10-20 — Packed attention in KV-cache executors (5.0.0rc17)
|
|
4
|
+
|
|
5
|
+
### Observation and decision
|
|
6
|
+
|
|
7
|
+
Cached decoding accessed separate Q/K/V projections and rejected packed attention, preventing
|
|
8
|
+
packed models from using the existing ONNX deployment interface. Accept closed unions of
|
|
9
|
+
ordinary and packed attention classes. Exhaustive pattern matching selects only the projection
|
|
10
|
+
operation; normalization, positional encoding, attention, and cache updates remain shared.
|
|
11
|
+
Use one packed QKV projection per decoded token and one packed KV projection per context-cache
|
|
12
|
+
construction without copying or unpacking parameters. Retain wrapper calls, cache records,
|
|
13
|
+
tensor layouts, and global causal/no-bias/single-token admission restrictions.
|
|
14
|
+
|
|
15
|
+
Allow recursive conversion through existing wrappers. Convert the complete containing module
|
|
16
|
+
when the model and multiple executors share attention children, so every registered reference
|
|
17
|
+
reconnects to the same replacement. References outside that tree are not rewritten. Reuse the
|
|
18
|
+
export-compatible token-major KV-head repetition helper for dynamic GQA/MQA cache attention.
|
|
19
|
+
|
|
20
|
+
### Verified result and limits
|
|
21
|
+
|
|
22
|
+
Focused eager checks pass for packed MHA/GQA/MQA, RoPE, Q/K normalization, masked cross contexts,
|
|
23
|
+
all four decoder normalization topologies, and context-free decoding. Tests verify packed
|
|
24
|
+
projection call counts, shared parameter ownership, unchanged cache records and head widths,
|
|
25
|
+
and continued use of live cache tensors across packing and unpacking an integrated model.
|
|
26
|
+
All 192 required static/dynamic ONNX Runtime cases pass across opsets 18–25 for ordinary MHA
|
|
27
|
+
and packed MHA/GQA/MQA cache construction and decoding, with and without context. Dynamic
|
|
28
|
+
runtime inputs change batch/context lengths and exercise an empty self cache. Checks use
|
|
29
|
+
PyTorch 2.11 on CPU; GPU providers, target-device latency, and quantization remain unverified.
|
|
30
|
+
`just check` passes formatting, lint, types, and the full suite: 2,936 passed, 21 skipped,
|
|
31
|
+
252 expected failures, and 111 optional-case unexpected passes.
|
|
32
|
+
|
|
3
33
|
## 2026-10-18 — Recursive projection conversion (5.0.0rc14)
|
|
4
34
|
|
|
5
35
|
### Observation and decision
|
|
@@ -50,7 +50,15 @@ from stackformers.decoder import (
|
|
|
50
50
|
ReorderedNormDecoderLayer,
|
|
51
51
|
SandwichNormDecoderLayer,
|
|
52
52
|
)
|
|
53
|
-
from stackformers.decoder_cache import
|
|
53
|
+
from stackformers.decoder_cache import (
|
|
54
|
+
CachedDecoderLayer,
|
|
55
|
+
CachedDecoderLayerBase,
|
|
56
|
+
CachedDecoderWrapper,
|
|
57
|
+
CachedPostNormDecoderLayer,
|
|
58
|
+
CachedReorderedNormDecoderLayer,
|
|
59
|
+
CachedSandwichNormDecoderLayer,
|
|
60
|
+
DecoderCrossAttentionCacheBuilder,
|
|
61
|
+
)
|
|
54
62
|
from stackformers.encoder import Encoder
|
|
55
63
|
from stackformers.feedforward import (
|
|
56
64
|
GEGLU,
|
|
@@ -108,16 +116,19 @@ from stackformers.positional import (
|
|
|
108
116
|
)
|
|
109
117
|
from stackformers.presets.cross_attender import (
|
|
110
118
|
CrossAttender,
|
|
119
|
+
CrossAttenderBase,
|
|
111
120
|
CrossAttenderConfig,
|
|
112
121
|
plain_cross_attender_config,
|
|
113
122
|
)
|
|
114
123
|
from stackformers.presets.decoder import (
|
|
115
124
|
TransformerDecoder,
|
|
125
|
+
TransformerDecoderBase,
|
|
116
126
|
TransformerDecoderConfig,
|
|
117
127
|
plain_decoder_config,
|
|
118
128
|
)
|
|
119
129
|
from stackformers.presets.encoder import (
|
|
120
130
|
TransformerEncoder,
|
|
131
|
+
TransformerEncoderBase,
|
|
121
132
|
TransformerEncoderConfig,
|
|
122
133
|
node_encoder_config,
|
|
123
134
|
plain_encoder_config,
|
|
@@ -142,6 +153,10 @@ from stackformers.sequence import (
|
|
|
142
153
|
make_packed_input,
|
|
143
154
|
make_padded,
|
|
144
155
|
make_padded_input,
|
|
156
|
+
packed_batch_size,
|
|
157
|
+
packed_to_padded,
|
|
158
|
+
padded_to_key_padding_mask,
|
|
159
|
+
padded_to_packed,
|
|
145
160
|
position_ids_from_packed,
|
|
146
161
|
to_seq_info,
|
|
147
162
|
)
|
|
@@ -169,6 +184,10 @@ __all__ = [
|
|
|
169
184
|
"to_seq_info",
|
|
170
185
|
"lengths_to_cu_seqlens",
|
|
171
186
|
"position_ids_from_packed",
|
|
187
|
+
"packed_batch_size",
|
|
188
|
+
"packed_to_padded",
|
|
189
|
+
"padded_to_key_padding_mask",
|
|
190
|
+
"padded_to_packed",
|
|
172
191
|
# protocols
|
|
173
192
|
"PosEncoding",
|
|
174
193
|
"SelfAttn",
|
|
@@ -264,6 +283,11 @@ __all__ = [
|
|
|
264
283
|
"Decoder",
|
|
265
284
|
"DecoderCrossAttentionCacheBuilder",
|
|
266
285
|
"CachedDecoderWrapper",
|
|
286
|
+
"CachedDecoderLayerBase",
|
|
287
|
+
"CachedDecoderLayer",
|
|
288
|
+
"CachedPostNormDecoderLayer",
|
|
289
|
+
"CachedSandwichNormDecoderLayer",
|
|
290
|
+
"CachedReorderedNormDecoderLayer",
|
|
267
291
|
"CrossAttenderLayerBase",
|
|
268
292
|
"CrossAttenderLayer",
|
|
269
293
|
"PostNormCrossAttenderLayer",
|
|
@@ -271,6 +295,9 @@ __all__ = [
|
|
|
271
295
|
"ReorderedNormCrossAttenderLayer",
|
|
272
296
|
"CrossAttenderStack",
|
|
273
297
|
# presets
|
|
298
|
+
"TransformerEncoderBase",
|
|
299
|
+
"TransformerDecoderBase",
|
|
300
|
+
"CrossAttenderBase",
|
|
274
301
|
"TransformerEncoderConfig",
|
|
275
302
|
"TransformerEncoder",
|
|
276
303
|
"plain_encoder_config",
|
|
@@ -33,7 +33,13 @@ allocating a dense pair mask on the packed fast path.
|
|
|
33
33
|
|
|
34
34
|
**`torch.export` and `torch.compile` compatibility.** All scatter/gather helpers in `ops.py` (`_cu_to_indices`, `_packed_heads_to_padded`, `_padded_heads_to_packed`) are fully export-compatible. The key design constraint is that per-document length iteration must never use Python-side loops over data-dependent values (i.e., no `.tolist()` followed by a list comprehension). Instead, `_cu_to_indices` uses `torch.repeat_interleave` to produce `batch_idx` and derives `pos_idx` via the identity `arange(nt) - cu[batch_idx]`. This keeps the computation graph purely symbolic even when `nt` (total tokens) is a data-dependent unbacked symbol.
|
|
35
35
|
|
|
36
|
-
**GQA / MQA.** Set `kv_heads < heads` in either config. Key and value heads are repeated via
|
|
36
|
+
**GQA / MQA.** Set `kv_heads < heads` in either config. Key and value heads are repeated via
|
|
37
|
+
`einops.repeat` before the dot-product. For padded inputs, repeat in token-major layout before
|
|
38
|
+
returning to head-major attention layout. This keeps symbolic sequence strides out of the
|
|
39
|
+
head-flattening reshape and allows dynamic export on PyTorch 2.11, including singleton inputs.
|
|
40
|
+
Ordinary and packed projections use the same helper in `ops.py` for this layout rule.
|
|
41
|
+
Mandatory ONNX Runtime tests cover
|
|
42
|
+
opsets 20–25 with static and dynamic padded inputs for MHA, GQA, and MQA.
|
|
37
43
|
|
|
38
44
|
**Exportable decoder K/V caches.** `CachedCrossAttentionWrapper` composes an existing cross-attention
|
|
39
45
|
module and projects one fixed padded context at the configured `kv_heads` width.
|
|
@@ -44,6 +50,12 @@ position. `DecoderCrossAttentionCacheBuilder` stacks every decoder layer into on
|
|
|
44
50
|
`CachedDecoderWrapper` mirrors each normalization topology for the one-token graph. The wrappers position
|
|
45
51
|
K before storage and Q on each step through the existing joint positional API. Ordinary attention,
|
|
46
52
|
decoder, preset, and positional classes contain no cache-specific methods.
|
|
53
|
+
The wrappers accept a closed union of ordinary and packed attention classes. Exhaustive projection
|
|
54
|
+
dispatch reuses separate Q/K/V matrices or a single packed QKV/KV matrix without copying weights.
|
|
55
|
+
Cache records, head widths, and wrapper calls are independent of projection layout. Cached
|
|
56
|
+
self-attention still requires global causal attention, `NoAttnBias`, and one token per call.
|
|
57
|
+
Add a supported projection variant to the union, admission checks, and projection dispatch together;
|
|
58
|
+
keep the shared normalization, positioning, and cache update equation outside that dispatch.
|
|
47
59
|
|
|
48
60
|
**Geometry a rotary encoding cannot carry.** `RelativeDistanceBias` adds a learned function of the Euclidean distance between node positions to the logits, making attention invariant to any global translation or rotation of the input. It lives here rather than in `positional/` because it *cannot* live there: RoPE rotates by `ω·p`, which is linear in position by construction — and that linearity is exactly what makes the query and key rotations cancel into a relative offset. Distance is not linear in position, so no rotary encoding, axial or otherwise, can express it; a bias is the only route. Pair it with `NoPosEncoding` — a rotary encoding alongside it would reintroduce the preferred frame it exists to remove. Use it when node coordinates have no meaningful axes; when up and right *do* mean something, RoPE-2D keeps direction and stays varlen-compatible.
|
|
49
61
|
|
|
@@ -77,7 +89,11 @@ packed projections directly through `build_self_attn` or `build_cross_attn`. Eac
|
|
|
77
89
|
accepts its own concrete config; only factory inputs use the discriminated variant union.
|
|
78
90
|
The `kind` field survives JSON serialization so presets reconstruct the checkpoint layout.
|
|
79
91
|
Legacy attention JSON without `kind` selects ordinary attention. Conversion also changes the
|
|
80
|
-
module's config to the destination variant.
|
|
92
|
+
module's config to the destination variant. Both layouts work with the existing cache wrappers.
|
|
93
|
+
Recursive conversion can visit an already-wrapped attention module. Convert the complete registered
|
|
94
|
+
tree when the model and multiple cache executors share attention children; external references are
|
|
95
|
+
not rewritten. Packed self-attention projects QKV once per token; packed cross-attention projects KV
|
|
96
|
+
once when building the context cache and reuses it on subsequent calls.
|
|
81
97
|
|
|
82
98
|
Keep another experimental projection layout in its own module, with explicit conversion
|
|
83
99
|
and parity tests against ordinary attention. Measure complete blocks before selecting a
|
{stackformers-5.0.0rc14 → stackformers-5.0.0rc17}/stackformers/attention/cache_validation.py
RENAMED
|
@@ -8,12 +8,13 @@ from stackformers.attention.bias import NoAttnBias
|
|
|
8
8
|
from stackformers.result import Err, Ok, Result
|
|
9
9
|
|
|
10
10
|
if TYPE_CHECKING:
|
|
11
|
+
from stackformers.attention.packed_self_attn import PackedSelfAttention
|
|
11
12
|
from stackformers.attention.self_attn import SelfAttention
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
def supported_self_attention(
|
|
15
|
-
attention: SelfAttention,
|
|
16
|
-
) -> Result[SelfAttention, NotImplementedError]:
|
|
16
|
+
attention: SelfAttention | PackedSelfAttention,
|
|
17
|
+
) -> Result[SelfAttention | PackedSelfAttention, NotImplementedError]:
|
|
17
18
|
"""Return the supported cached equation or explain its unsupported features."""
|
|
18
19
|
if not attention.config.causal or attention.config.window_size is not None:
|
|
19
20
|
return Err(
|