stackformers 6.0.0rc8__tar.gz → 6.0.0rc9__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-6.0.0rc8 → stackformers-6.0.0rc9}/CHANGELOG.md +18 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/PKG-INFO +1 -1
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/docs/api-guide.md +8 -14
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/docs/inference.md +5 -5
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/examples/README.md +3 -2
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/examples/encoder_decoder_onnxruntime.py +3 -2
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/pyproject.toml +1 -1
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/DEVLOG.md +35 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/__init__.py +0 -41
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/README.md +5 -5
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/cache.py +3 -3
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/cached.py +2 -2
- stackformers-6.0.0rc9/stackformers/attention/onnx_backend.py +140 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/ops.py +5 -3
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/packed_self_attn.py +1 -2
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/self_attn.py +1 -2
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/varlen_backend.py +5 -5
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention2d/README.md +11 -6
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/decoder_cache.py +11 -11
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/encoder2d/README.md +3 -3
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/mlm/README.md +5 -2
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/sequence.py +3 -130
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_all_valid.py +11 -11
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_config.py +2 -1
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_contracts.py +10 -12
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_cross_attn.py +5 -5
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_cross_attn_cache.py +13 -16
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_distance_bias.py +10 -10
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_empty_rows.py +2 -2
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_geometry.py +8 -7
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_kernels.py +17 -12
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_legacy_api.py +10 -9
- stackformers-6.0.0rc9/tests/attention/test_onnx_backend.py +115 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_ops.py +61 -5
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_packed_cross_attn.py +8 -8
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_packed_self_attn.py +4 -3
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_self_attn.py +18 -24
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_varlen_backend.py +9 -4
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention2d/test_export.py +3 -3
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/mlm/test_empty_selection.py +3 -2
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/mlm/test_masking.py +1 -1
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/mlm/test_wrapper.py +9 -10
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/norm_topology_helpers.py +7 -2
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/positional/test_cacheable.py +4 -4
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/presets/test_cross_attender.py +6 -5
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/presets/test_decoder.py +6 -5
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/presets/test_encoder.py +14 -13
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/presets/test_projection_packing.py +5 -4
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/presets/test_variable_width_encoder.py +12 -15
- stackformers-6.0.0rc9/tests/sequence_helpers.py +37 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_all_valid_decoder.py +25 -25
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_core_results.py +7 -6
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_cross_attender.py +9 -4
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_decoder.py +17 -17
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_decoder_cache.py +32 -35
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_decoder_equations.py +8 -6
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_encoder.py +5 -4
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_encoder_decoder_example.py +4 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_layers.py +9 -5
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_packing.py +9 -13
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_preallocated_decoder.py +7 -7
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_public_api.py +1 -16
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_sequence.py +46 -51
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/uv.lock +1 -1
- stackformers-6.0.0rc8/stackformers/attention/onnx_backend.py +0 -54
- stackformers-6.0.0rc8/tests/attention/test_onnx_backend.py +0 -42
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/.claudeignore +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/.github/pull_request_template.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/.github/workflows/check.yml +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/.gitignore +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/.python-version +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/.vscode/settings.json +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/AGENTS.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/CITATION.cff +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/CONTRIBUTING.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/Justfile +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/LICENSE +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/PLAN.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/README.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/docs/assets/social-preview.jpg +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/docs/assets/social-preview.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/docs/compatibility.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/docs/improvement-plan.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/docs/research.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/examples/causal_language_model.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/examples/image_encoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/examples/padded_and_packed.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/examples/point_cloud_encoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/examples/spatial_encoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/examples/subclassed_encoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/pyrefly.toml +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/pytest.ini +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/ruff.toml +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/_decoder_equations.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/_projection_packing.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/_result.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/alignment.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/all_valid_decoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/all_valid.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/bias.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/cache_validation.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/config.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/cross_attn.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/distance_bias.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/factory.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/layout.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/masking.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/packed_cross_attn.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention/protocols.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention2d/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention2d/coordinates.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention2d/cross_attn_pooling.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention2d/factory.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention2d/figures/window_cross_attention_2d.svg +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention2d/figures/window_self_attention_2d.svg +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention2d/protocols.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention2d/query_anchors.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention2d/self_attn.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention2d/sequence.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/attention2d/windows.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/config.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/cross_attender.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/decoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/encoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/encoder2d/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/encoder2d/_callable_stage.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/encoder2d/encoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/encoder2d/layer.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/encoder2d/protocols.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/encoder2d/tokenwise.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/encoder2d/window_stage.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/DEVLOG.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/README.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/config.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/factory.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/geglu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/gelu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/hardswish_glu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/packed_geglu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/packed_hardswish_glu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/packed_swiglu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/protocols.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/relu_squared.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/feedforward/swiglu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/layers.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/mlm/config.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/mlm/head.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/mlm/head_cosine.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/mlm/masking.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/mlm/protocols.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/mlm/wrapper.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/norm/README.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/norm/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/norm/config.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/norm/factory.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/norm/protocols.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/packing.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/positional/README.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/positional/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/positional/config.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/positional/factory.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/positional/learned.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/positional/none.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/positional/protocols.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/positional/rope1d.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/positional/rope2d.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/positional/rope_nd.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/positional/validation.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/preallocated_decoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/presets/README.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/presets/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/presets/cross_attender.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/presets/decoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/presets/encoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/presets/variable_width_encoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/py.typed +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/result/README.md +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/stackformers/result/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/legacy_api_rc1.json +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_cached.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_factory.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_masking.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention/test_sdpa_export.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention2d/conftest.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention2d/test_coordinates.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention2d/test_cross_attn_pooling.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention2d/test_factory.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention2d/test_query_anchors.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention2d/test_self_attn.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention2d/test_sequence.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/attention2d/test_windows.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/conftest.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/encoder2d/conftest.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/encoder2d/test_encoder.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/encoder2d/test_layer.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/encoder2d/test_window_stage.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/export_utils.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/feedforward/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/feedforward/legacy_swiglu_4_6.json +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/feedforward/test_config.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/feedforward/test_factory.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/feedforward/test_geglu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/feedforward/test_gelu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/feedforward/test_hardswish_glu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/feedforward/test_packed_geglu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/feedforward/test_packed_hardswish_glu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/feedforward/test_packed_swiglu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/feedforward/test_relu_squared.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/feedforward/test_swiglu.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/mlm/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/mlm/test_head.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/mlm/test_head_cosine.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/positional/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/positional/test_learned_pos.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/positional/test_rope.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/positional/test_rope_nd.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/presets/__init__.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_alignment.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_examples.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_export_utils.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_norm.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_projection_packing.py +0 -0
- {stackformers-6.0.0rc8 → stackformers-6.0.0rc9}/tests/test_result.py +0 -0
|
@@ -6,6 +6,24 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
|
|
6
6
|
adheres to [Semantic Versioning](https://semver.org/): MAJOR for breaking public API changes,
|
|
7
7
|
MINOR for backwards-compatible features, PATCH for bug fixes and internal changes.
|
|
8
8
|
|
|
9
|
+
## [6.0.0rc9]
|
|
10
|
+
|
|
11
|
+
### Backwards Incompatible Changes
|
|
12
|
+
|
|
13
|
+
- Remove deprecated sequence metadata records, input aliases, and compatibility
|
|
14
|
+
helpers. Use `PaddedTensor` and `PackedTensor`, their factory and conversion
|
|
15
|
+
methods, and their stored validity, boundaries, and positions instead.
|
|
16
|
+
- Carry the original context tensor record in decoder cross-attention caches
|
|
17
|
+
instead of separate legacy sequence metadata.
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
- Enable optimized direct spatial ONNX export by emitting a standard ONNX subgraph
|
|
22
|
+
for packed token indices, avoiding the exporter's invalid `repeat_interleave`
|
|
23
|
+
rewrite. Native PyTorch execution is unchanged. Export tensor adapters directly;
|
|
24
|
+
conversion of pre-captured `ExportedProgram` graphs bypasses this lowering and
|
|
25
|
+
can still encounter the upstream optimizer failure.
|
|
26
|
+
|
|
9
27
|
## [6.0.0rc8]
|
|
10
28
|
|
|
11
29
|
### Backwards Incompatible Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: stackformers
|
|
3
|
-
Version: 6.0.
|
|
3
|
+
Version: 6.0.0rc9
|
|
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
|
|
@@ -44,20 +44,14 @@ compile/export with dynamic output shapes. Same-layout conversions return the or
|
|
|
44
44
|
record. Packed list slices and jagged output share value storage; callers must avoid
|
|
45
45
|
mutating shared buffers. Nested adapters require PyTorch's jagged tensor API.
|
|
46
46
|
|
|
47
|
-
###
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
`
|
|
52
|
-
`
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
as deprecated compatibility APIs. Metadata records and helper functions use static
|
|
56
|
-
PEP 702 deprecation markers without runtime warning wrappers, keeping old graph paths
|
|
57
|
-
traceable. Use tensor constructors, conversion methods, `materialize_padding_mask`, and
|
|
58
|
-
`tensor.cu_seqlens.shape[0] - 1` instead. Existing decoder cache outputs retain their
|
|
59
|
-
mask-only metadata structure; cached calls also accept `PaddedTensor` directly.
|
|
60
|
-
No removal version is assigned.
|
|
47
|
+
### Sequence API migration
|
|
48
|
+
|
|
49
|
+
The deprecated input aliases, metadata-only sequence records, and construction/conversion
|
|
50
|
+
helpers have been removed. Use `PackedTensor` and `PaddedTensor` with explicit positions,
|
|
51
|
+
or their `from_list` constructors to generate sequential positions. Convert layouts with
|
|
52
|
+
`tensor.to_packed()` and `tensor.to_padded()`. Use `materialize_padding_mask(tensor)` at
|
|
53
|
+
boundaries requiring a boolean mask, and `tensor.cu_seqlens.shape[0] - 1` for packed batch
|
|
54
|
+
size. Cached calls and cache builder outputs now carry the full `PaddedTensor` context.
|
|
61
55
|
|
|
62
56
|
## Composition
|
|
63
57
|
|
|
@@ -7,7 +7,7 @@ selected automatically from tensor values, a batch size of one, or evaluation mo
|
|
|
7
7
|
|
|
8
8
|
Load an ordinary checkpoint into the ordinary model, then call `sf.to_packed(model)` before
|
|
9
9
|
building wrappers. Alternatively, construct with packed attention/feed-forward configs and
|
|
10
|
-
load a matching packed checkpoint. `
|
|
10
|
+
load a matching packed checkpoint. `PackedTensor` describes a sequence layout; it does not
|
|
11
11
|
select packed projections. Default presets still construct ordinary projections.
|
|
12
12
|
|
|
13
13
|
Packing retains parameter values, normalization, RoPE, output projections, dtype/device,
|
|
@@ -23,7 +23,7 @@ project only Q. Graph structure is verified separately from eager numerical pari
|
|
|
23
23
|
|
|
24
24
|
## Explicit validity
|
|
25
25
|
|
|
26
|
-
Use `sf.
|
|
26
|
+
Use `sf.PaddedTensor(x, sf.AllValid(), abs_positions)` only when every token is valid. The
|
|
27
27
|
mask field is required and accepts either a boolean tensor or the explicit `AllValid()`
|
|
28
28
|
marker. There is no `None` mode or omitted-mask default. `SequenceInput` retains just its
|
|
29
29
|
padded and packed layouts. This replaces the prerelease `AllValidInput` record.
|
|
@@ -37,7 +37,7 @@ cases. Cross-attention query and context masks are handled independently.
|
|
|
37
37
|
`AllValid` is stateless and registered as a zero-leaf pytree, so it contributes no graph input.
|
|
38
38
|
`sf.materialize_padding_mask(input)` adapts to consumers requiring a boolean tensor: existing
|
|
39
39
|
tensors retain identity, and only the marker allocates an all-true mask. Attention does not
|
|
40
|
-
call this adapter on its all-valid path.
|
|
40
|
+
call this adapter on its all-valid path.
|
|
41
41
|
|
|
42
42
|
`sf.AllValidCachedDecoderWrapper` requires exactly one token and batch size one. Its self
|
|
43
43
|
cache includes only valid past tokens, and the new token is appended before attention.
|
|
@@ -53,9 +53,9 @@ builder = sf.AllValidCrossAttentionCacheBuilder(decoder)
|
|
|
53
53
|
cached = sf.AllValidCachedDecoderWrapper(decoder)
|
|
54
54
|
|
|
55
55
|
with torch.no_grad():
|
|
56
|
-
cross = builder(sf.
|
|
56
|
+
cross = builder(sf.PaddedTensor(memory_x, sf.AllValid(), memory_positions))
|
|
57
57
|
past = cached.empty_cache(dtype=torch.float32)
|
|
58
|
-
result = cached(sf.
|
|
58
|
+
result = cached(sf.PaddedTensor(token_x, sf.AllValid(), token_positions), cross, past)
|
|
59
59
|
past = result.self_kv_cache
|
|
60
60
|
```
|
|
61
61
|
|
|
@@ -34,7 +34,7 @@ boundaries suitable for separate C++ ONNX Runtime sessions:
|
|
|
34
34
|
1. Eager PyTorch calls `model(source, target)` with the existing Stackformers API.
|
|
35
35
|
2. `encoder.onnx` runs once and returns encoder memory.
|
|
36
36
|
3. `decoder_cross_cache.onnx` consumes that memory once and returns one dense cross-attention K/V
|
|
37
|
-
cache plus the context mask.
|
|
37
|
+
cache plus the context values, mask, and positions.
|
|
38
38
|
4. `cached_decoder.onnx` consumes one target token, the cross cache, a required growing self cache,
|
|
39
39
|
and `step_i`; it returns the decoder output and the self cache for the next call.
|
|
40
40
|
|
|
@@ -48,7 +48,8 @@ The ONNX tensors have explicit names suitable for equivalent C++ `Ort::Value` ma
|
|
|
48
48
|
|
|
49
49
|
- Encoder inputs: `source_x`, `source_mask`, `source_positions`.
|
|
50
50
|
- Encoder outputs and cache-builder inputs: `memory_x`, `memory_mask`, `memory_positions`.
|
|
51
|
-
- Cache outputs and cached-decoder inputs: `cross_kv_cache`, `context_mask
|
|
51
|
+
- Cache outputs and cached-decoder inputs: `cross_kv_cache`, `context_x`, `context_mask`,
|
|
52
|
+
`context_positions`.
|
|
52
53
|
- Other cached-decoder inputs: `target_x`, `target_mask`, `target_positions`, `self_kv_cache`,
|
|
53
54
|
`step_i`.
|
|
54
55
|
- Cached-decoder outputs: `decoder_output`, `self_kv_cache_out`.
|
|
@@ -35,7 +35,7 @@ LAYERS = 2
|
|
|
35
35
|
EXAMPLE_BATCH = 2
|
|
36
36
|
MAX_SOURCE_TOKENS = 6
|
|
37
37
|
MAX_TARGET_TOKENS = 4
|
|
38
|
-
CROSS_CACHE_NAMES = ("cross_kv_cache", "context_mask")
|
|
38
|
+
CROSS_CACHE_NAMES = ("cross_kv_cache", "context_x", "context_mask", "context_positions")
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
class ExampleResult(NamedTuple):
|
|
@@ -125,7 +125,8 @@ def _cached_decoder_dynamic_shapes(
|
|
|
125
125
|
for tensor in target_input:
|
|
126
126
|
shapes[tensor] = {0: batch}
|
|
127
127
|
shapes[cross_cache.kv] = {2: batch, 4: source_tokens}
|
|
128
|
-
|
|
128
|
+
for tensor in cross_cache.context:
|
|
129
|
+
shapes[tensor] = {0: batch, 1: source_tokens}
|
|
129
130
|
shapes[self_kv_cache] = {2: batch, 4: past_tokens}
|
|
130
131
|
dynamic_shapes: dict[str, object] = shapes.dynamic_shapes(
|
|
131
132
|
module,
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "stackformers"
|
|
7
|
-
version = "6.0.
|
|
7
|
+
version = "6.0.0rc9"
|
|
8
8
|
description = "Composable PyTorch transformers for vision, spatial, and sequence research"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
@@ -1029,3 +1029,38 @@ four spatial compositions, and opsets 18–25. On the indexed two-sample example
|
|
|
1029
1029
|
feature and position tensor identity is preserved, and partition profiling contains
|
|
1030
1030
|
only arange, empty, and resize_ for boundary allocation. The local proof is saved in
|
|
1031
1031
|
work_dir/rc7_partition_proof.json. These checks do not establish GPU throughput.
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
## Optimized packed spatial ONNX exports
|
|
1035
|
+
|
|
1036
|
+
Enabling exporter optimization reproduced an invalid dynamic spatial graph: ONNX
|
|
1037
|
+
Script's ReshapeReshape rewrite left dangling shape inputs inside the
|
|
1038
|
+
repeat_interleave lowering. Disabling the exporter optimizer avoided the failure
|
|
1039
|
+
but also disabled useful exporter fusions.
|
|
1040
|
+
|
|
1041
|
+
An internal onnx_lowering decorator keeps the original repeat_interleave native
|
|
1042
|
+
implementation and emits a standard ONNX subgraph only during direct ONNX capture.
|
|
1043
|
+
Exported packed indices come from label changes scattered at nonempty sequence
|
|
1044
|
+
starts and cumulatively summed across token positions. Nonempty starts are unique,
|
|
1045
|
+
and label jumps preserve batch numbering across leading, interior, and trailing
|
|
1046
|
+
empty sequences. A sentinel slot handles entirely empty inputs. This avoids both
|
|
1047
|
+
the broken lowering and scatter reductions that prevent legacy opset conversion.
|
|
1048
|
+
Existing einops layout transformations, native eager/compiled/torch.export
|
|
1049
|
+
execution, attention equations, and kernel routing remain unchanged. No installed
|
|
1050
|
+
dependencies are patched, and callers need no translation tables or registration.
|
|
1051
|
+
|
|
1052
|
+
Spatial export tests and examples now use direct torch.onnx.export with
|
|
1053
|
+
optimize=True. A pre-captured ExportedProgram cannot reselect Python branches and
|
|
1054
|
+
can still hit the upstream optimizer bug; this workaround applies to direct export.
|
|
1055
|
+
Regression coverage checks empty sequences with int32/int64 boundaries, full-graph
|
|
1056
|
+
compilation with dynamic-output capture, and optimized dynamic ONNX execution.
|
|
1057
|
+
These changes address export correctness; target-device latency and CUDA execution
|
|
1058
|
+
remain unmeasured.
|
|
1059
|
+
|
|
1060
|
+
Validation includes all 256 static/dynamic spatial exports at opsets 18–25 with
|
|
1061
|
+
optimize=True, required module coverage, and 1,622 isolated root-level integration
|
|
1062
|
+
tests. Formatting, lint, and Pyrefly pass. Optional coverage has 107 passes and 252
|
|
1063
|
+
expected failures. Four opset-15 RoPE2D/RoPEND conversion failures reproduce on the
|
|
1064
|
+
untouched committed baseline; they remain outside this fix. The lowered packed
|
|
1065
|
+
index graph passes the ONNX checker, contains only standard ai.onnx operators, and
|
|
1066
|
+
preserves runtime indices when empty-sequence placement changes.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"""stackformers public API."""
|
|
2
2
|
|
|
3
3
|
from importlib.metadata import version
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
5
4
|
|
|
6
5
|
__version__ = version("stackformers")
|
|
7
6
|
|
|
@@ -173,24 +172,12 @@ from stackformers.presets.variable_width_encoder import (
|
|
|
173
172
|
from stackformers.result import Err, Ok, Result
|
|
174
173
|
from stackformers.sequence import (
|
|
175
174
|
AllValid,
|
|
176
|
-
PackedSequence,
|
|
177
175
|
PackedTensor,
|
|
178
|
-
PaddedSequence,
|
|
179
176
|
PaddedTensor,
|
|
180
|
-
SequenceInfo,
|
|
181
177
|
SequenceInput,
|
|
182
178
|
lengths_to_cu_seqlens,
|
|
183
|
-
make_packed,
|
|
184
|
-
make_packed_input,
|
|
185
|
-
make_padded,
|
|
186
|
-
make_padded_input,
|
|
187
179
|
materialize_padding_mask,
|
|
188
|
-
packed_batch_size,
|
|
189
|
-
packed_to_padded,
|
|
190
|
-
padded_to_key_padding_mask,
|
|
191
|
-
padded_to_packed,
|
|
192
180
|
position_ids_from_packed,
|
|
193
|
-
to_seq_info,
|
|
194
181
|
)
|
|
195
182
|
|
|
196
183
|
__all__ = [
|
|
@@ -226,25 +213,11 @@ __all__ = [
|
|
|
226
213
|
"Ok",
|
|
227
214
|
"Err",
|
|
228
215
|
# sequences
|
|
229
|
-
"PaddedSequence",
|
|
230
|
-
"PackedSequence",
|
|
231
|
-
"SequenceInfo",
|
|
232
216
|
"PaddedTensor",
|
|
233
217
|
"PackedTensor",
|
|
234
|
-
"PaddedInput",
|
|
235
|
-
"PackedInput",
|
|
236
218
|
"SequenceInput",
|
|
237
|
-
"make_padded",
|
|
238
|
-
"make_packed",
|
|
239
|
-
"make_padded_input",
|
|
240
|
-
"make_packed_input",
|
|
241
|
-
"to_seq_info",
|
|
242
219
|
"lengths_to_cu_seqlens",
|
|
243
220
|
"position_ids_from_packed",
|
|
244
|
-
"packed_batch_size",
|
|
245
|
-
"packed_to_padded",
|
|
246
|
-
"padded_to_key_padding_mask",
|
|
247
|
-
"padded_to_packed",
|
|
248
221
|
# protocols
|
|
249
222
|
"PosEncoding",
|
|
250
223
|
"SelfAttn",
|
|
@@ -378,17 +351,3 @@ __all__ = [
|
|
|
378
351
|
"MLMWrapper",
|
|
379
352
|
"MLMOutput",
|
|
380
353
|
]
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
if TYPE_CHECKING:
|
|
384
|
-
PackedInput = PackedTensor
|
|
385
|
-
PaddedInput = PaddedTensor
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
def __getattr__(name: str) -> type[PackedTensor] | type[PaddedTensor]:
|
|
389
|
-
"""Resolve legacy input aliases with the sequence module's deprecation guidance."""
|
|
390
|
-
from stackformers import sequence
|
|
391
|
-
|
|
392
|
-
if name in ("PackedInput", "PaddedInput"):
|
|
393
|
-
return sequence.__getattr__(name)
|
|
394
|
-
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -53,7 +53,7 @@ allocating a dense pair mask on the packed fast path.
|
|
|
53
53
|
|
|
54
54
|
**Packed attention with automatic fallback.** `PackedTensor` normally routes to `varlen_attn`, which requires CUDA and `float16`/`bfloat16`. `packed_attn_or_fallback` calls `try_varlen_attn`; a `None` result means take the padded path — scatter q/k/v to padded layout, run `F.scaled_dot_product_attention`, and gather the result back to packed (same weights, same output shape `(nt, h, d)`). The fallback runs **silently** for the expected CPU/float32/`torch.export` route, and **with a `UserWarning` explaining why** when the kernel was eligible but unusable: it failed to import, an attention bias is present (no bias slot), or the call raised a runtime/signature error (unsupported GPU or a changed experimental API). Dropout works on the fallback path; it is silently skipped only when `varlen_attn` is used (which does not accept a dropout argument).
|
|
55
55
|
|
|
56
|
-
**`torch.export` and `torch.compile` compatibility.** All scatter/gather helpers in `ops.py` (`_cu_to_indices`, `_packed_heads_to_padded`, `_padded_heads_to_packed`)
|
|
56
|
+
**`torch.export` and `torch.compile` compatibility.** All scatter/gather helpers in `ops.py` (`_cu_to_indices`, `_packed_heads_to_padded`, `_padded_heads_to_packed`) avoid Python-side iteration over data-dependent lengths. Native execution uses `repeat_interleave` to recover token batch indices and `arange(nt) - cu[batch_idx]` for positions. During direct ONNX capture, the `onnx_lowering` decorator selects an explicit standard-ONNX subgraph from `onnx_backend.py`. It scatters label changes at nonempty sequence starts and cumulatively sums them; unique starts and label jumps preserve numbering across empty sequences. This avoids the installed ONNX Script optimizer's invalid `ReshapeReshape` rewrite without changing native eager, compiled, or `torch.export` behavior. Callers use ordinary `torch.onnx.export(model, args, ...)` without custom operators or registration. Converting an already captured `ExportedProgram` bypasses Python dispatch, so use direct ONNX export for this workaround.
|
|
57
57
|
|
|
58
58
|
**GQA / MQA.** Set `kv_heads < heads` in either config. Key and value heads are repeated via
|
|
59
59
|
`einops.repeat` before the dot-product. For padded inputs, repeat in token-major layout before
|
|
@@ -141,10 +141,10 @@ updated protocol.
|
|
|
141
141
|
To add a new attention bias, write an `nn.Module` satisfying `AttnBias` (take `PaddedTensor`, return a broadcastable `(b, h, n, s)` tensor or `None`), give it a config with a `kind` discriminator, join it to the `AttnBiasConfig` union, and add one `match` arm to `build_attn_bias`.
|
|
142
142
|
|
|
143
143
|
Packed execution takes `PackedTensor` directly, including at the varlen/fallback boundary;
|
|
144
|
-
callers do not construct a second metadata record.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
callers do not construct a second metadata record. Cached cross-attention accepts a
|
|
145
|
+
`PaddedTensor` as context validity. Cache builders return that original context record
|
|
146
|
+
alongside projected keys and values, preserving values, validity, and coordinates without
|
|
147
|
+
constructing separate metadata records.
|
|
148
148
|
|
|
149
149
|
## Optional dimension rounding
|
|
150
150
|
|
|
@@ -8,7 +8,7 @@ if TYPE_CHECKING:
|
|
|
8
8
|
from jaxtyping import Float
|
|
9
9
|
from torch import Tensor
|
|
10
10
|
|
|
11
|
-
from stackformers.sequence import
|
|
11
|
+
from stackformers.sequence import PaddedTensor
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class CrossAttentionKVCache(NamedTuple):
|
|
@@ -23,14 +23,14 @@ class CrossAttentionKVCache(NamedTuple):
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
class DecoderCrossAttentionCache(NamedTuple):
|
|
26
|
-
"""Dense context cache and
|
|
26
|
+
"""Dense context cache and tensor record shared by every decoder step.
|
|
27
27
|
|
|
28
28
|
The leading dimensions of ``kv`` are layer and K/V selector. Keeping every layer in one
|
|
29
29
|
tensor gives ONNX Runtime C++ one required ``Ort::Value`` instead of a variable-length list.
|
|
30
30
|
"""
|
|
31
31
|
|
|
32
32
|
kv: Float[Tensor, "layers two b kv_h s dh"]
|
|
33
|
-
context:
|
|
33
|
+
context: PaddedTensor
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
class DecoderStepOutput(NamedTuple):
|
|
@@ -27,7 +27,7 @@ if TYPE_CHECKING:
|
|
|
27
27
|
from jaxtyping import Float
|
|
28
28
|
|
|
29
29
|
from stackformers.positional.protocols import PosEncoding
|
|
30
|
-
from stackformers.sequence import
|
|
30
|
+
from stackformers.sequence import PaddedTensor
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
def _project_qkv(
|
|
@@ -220,7 +220,7 @@ class CachedCrossAttentionWrapper(nn.Module):
|
|
|
220
220
|
self,
|
|
221
221
|
input: PaddedTensor,
|
|
222
222
|
cache: CrossAttentionKVCache,
|
|
223
|
-
context: PaddedTensor
|
|
223
|
+
context: PaddedTensor,
|
|
224
224
|
) -> Tensor:
|
|
225
225
|
"""Attend one padded target input to a preprojected fixed context."""
|
|
226
226
|
attention = self.attention
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"""Export-specific attention lowerings with native PyTorch equivalents."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Sequence
|
|
6
|
+
from functools import wraps
|
|
7
|
+
from typing import TYPE_CHECKING, ParamSpec, TypeVar, cast
|
|
8
|
+
|
|
9
|
+
import torch
|
|
10
|
+
import torch.nn.functional as F
|
|
11
|
+
from einops import rearrange
|
|
12
|
+
from torch import Tensor
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from collections.abc import Callable
|
|
16
|
+
|
|
17
|
+
from jaxtyping import Float, Int
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
_P = ParamSpec("_P")
|
|
21
|
+
_R = TypeVar("_R")
|
|
22
|
+
_OnnxAttribute = (
|
|
23
|
+
int | float | str | bool | Sequence[int] | Sequence[float] | Sequence[str] | Sequence[bool]
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def onnx_lowering(lowering: Callable[_P, _R]) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]:
|
|
28
|
+
"""Select a symbolic ONNX subgraph during direct ONNX capture.
|
|
29
|
+
|
|
30
|
+
Native eager, compiled, and torch.export calls retain the decorated function.
|
|
31
|
+
Converting an already captured ExportedProgram cannot reselect Python branches.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def decorate(native: Callable[_P, _R]) -> Callable[_P, _R]:
|
|
35
|
+
"""Bind the equivalent implementations without changing their call contract."""
|
|
36
|
+
|
|
37
|
+
@wraps(native)
|
|
38
|
+
def dispatch(*args: _P.args, **kwargs: _P.kwargs) -> _R:
|
|
39
|
+
"""Emit symbolic nodes only while the ONNX exporter captures the model."""
|
|
40
|
+
if torch.onnx.is_in_onnx_export():
|
|
41
|
+
return lowering(*args, **kwargs)
|
|
42
|
+
return native(*args, **kwargs)
|
|
43
|
+
|
|
44
|
+
return dispatch
|
|
45
|
+
|
|
46
|
+
return decorate
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _int64_node(
|
|
50
|
+
op_type: str,
|
|
51
|
+
inputs: tuple[Tensor, ...],
|
|
52
|
+
shape: tuple[int | torch.SymInt, ...],
|
|
53
|
+
**attributes: _OnnxAttribute,
|
|
54
|
+
) -> Tensor:
|
|
55
|
+
"""Emit one standard ONNX node with an explicit integer output shape."""
|
|
56
|
+
return torch.onnx.ops.symbolic(
|
|
57
|
+
f"::{op_type}", inputs, attributes, dtype=torch.long, shape=shape, version=18
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def packed_token_indices(cu: Int[Tensor, "bp1"], b: int) -> tuple[Tensor, Tensor]:
|
|
62
|
+
"""Emit a standard ONNX subgraph for packed labels without repeat_interleave."""
|
|
63
|
+
# Data-dependent extents describe symbolic output shapes, not eager computations.
|
|
64
|
+
nt = cast("int", cu[-1].item())
|
|
65
|
+
active = cast("int", torch.count_nonzero(cu[1:] - cu[:-1]).item())
|
|
66
|
+
torch._check_is_size(nt)
|
|
67
|
+
torch._check_is_size(active)
|
|
68
|
+
|
|
69
|
+
zero = _int64_node("Constant", (), (), value_int=0)
|
|
70
|
+
one = _int64_node("Constant", (), (), value_int=1)
|
|
71
|
+
zero_vector = _int64_node("Constant", (), (1,), value_ints=[0])
|
|
72
|
+
minus_vector = _int64_node("Constant", (), (1,), value_ints=[-1])
|
|
73
|
+
one_vector = _int64_node("Constant", (), (1,), value_ints=[1])
|
|
74
|
+
end_vector = _int64_node("Constant", (), (1,), value_ints=[torch.iinfo(torch.int64).max])
|
|
75
|
+
boundaries = _int64_node("Cast", (cu,), cu.shape, to=7)
|
|
76
|
+
left = _int64_node("Slice", (boundaries, zero_vector, minus_vector), (b,))
|
|
77
|
+
right = _int64_node("Slice", (boundaries, one_vector, end_vector), (b,))
|
|
78
|
+
counts = _int64_node("Sub", (right, left), (b,))
|
|
79
|
+
ends = _int64_node("CumSum", (counts, zero), (b,))
|
|
80
|
+
starts = _int64_node("Concat", (zero_vector, ends), (b + 1,), axis=0)
|
|
81
|
+
nonempty = _int64_node("NonZero", (counts,), (1, active))
|
|
82
|
+
nonempty = _int64_node("Squeeze", (nonempty, zero_vector), (active,))
|
|
83
|
+
previous = _int64_node("Concat", (minus_vector, nonempty), (active + 1,), axis=0)
|
|
84
|
+
previous = _int64_node("Slice", (previous, zero_vector, minus_vector), (active,))
|
|
85
|
+
jumps = _int64_node("Sub", (nonempty, previous), (active,))
|
|
86
|
+
total = _int64_node("ReduceSum", (counts,), (), keepdims=0)
|
|
87
|
+
capacity = _int64_node("Add", (total, one), ())
|
|
88
|
+
capacity = _int64_node("Unsqueeze", (capacity, zero_vector), (1,))
|
|
89
|
+
zeroes = _int64_node("Expand", (zero, capacity), (nt + 1,))
|
|
90
|
+
destinations = _int64_node("Gather", (starts, nonempty), (active,))
|
|
91
|
+
# Nonempty starts are unique; label jumps preserve gaps from empty sequences.
|
|
92
|
+
changes = _int64_node("ScatterElements", (zeroes, destinations, jumps), (nt + 1,), axis=0)
|
|
93
|
+
labels = _int64_node("CumSum", (changes, zero), (nt + 1,))
|
|
94
|
+
labels = _int64_node("Sub", (labels, one), (nt + 1,))
|
|
95
|
+
labels = _int64_node("Slice", (labels, zero_vector, minus_vector), (nt,))
|
|
96
|
+
tokens = _int64_node("Range", (zero, total, one), (nt,))
|
|
97
|
+
offsets = _int64_node("Gather", (boundaries, labels), (nt,))
|
|
98
|
+
positions = _int64_node("Sub", (tokens, offsets), (nt,))
|
|
99
|
+
return labels, positions
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def update_buffer(
|
|
103
|
+
cache: Float[Tensor, "b h capacity dh"],
|
|
104
|
+
update: Float[Tensor, "b h n dh"],
|
|
105
|
+
index: Int[Tensor, "b"],
|
|
106
|
+
) -> Tensor:
|
|
107
|
+
"""Expose TensorScatter to ONNX; eager execution writes into the owned buffer."""
|
|
108
|
+
if torch.onnx.is_in_onnx_export():
|
|
109
|
+
return torch.onnx.ops.symbolic(
|
|
110
|
+
"::TensorScatter",
|
|
111
|
+
(cache, update, index),
|
|
112
|
+
{"axis": 2},
|
|
113
|
+
dtype=cache.dtype,
|
|
114
|
+
shape=cache.shape,
|
|
115
|
+
version=24,
|
|
116
|
+
)
|
|
117
|
+
return cache.index_copy_(2, index, update)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def valid_length_attention(
|
|
121
|
+
q: Float[Tensor, "b h n dh"],
|
|
122
|
+
k: Float[Tensor, "b kv_h capacity dh"],
|
|
123
|
+
v: Float[Tensor, "b kv_h capacity dh"],
|
|
124
|
+
valid_length: Int[Tensor, "b"],
|
|
125
|
+
) -> Tensor:
|
|
126
|
+
"""Exclude unused capacity using Attention-24's valid-length input during export."""
|
|
127
|
+
if torch.onnx.is_in_onnx_export():
|
|
128
|
+
return torch.onnx.ops.symbolic(
|
|
129
|
+
"::Attention",
|
|
130
|
+
(q, k, v, None, None, None, valid_length),
|
|
131
|
+
{"is_causal": 0},
|
|
132
|
+
dtype=q.dtype,
|
|
133
|
+
shape=q.shape,
|
|
134
|
+
version=24,
|
|
135
|
+
)
|
|
136
|
+
positions = torch.arange(k.shape[2], device=k.device)
|
|
137
|
+
valid = rearrange(positions < valid_length, "s -> 1 s")
|
|
138
|
+
return F.scaled_dot_product_attention(
|
|
139
|
+
q, k, v, attn_mask=valid, is_causal=False, enable_gqa=q.shape[1] != k.shape[1]
|
|
140
|
+
)
|
|
@@ -9,13 +9,14 @@ import torch.nn.functional as F
|
|
|
9
9
|
from einops import rearrange, repeat
|
|
10
10
|
from torch import Tensor
|
|
11
11
|
|
|
12
|
+
from stackformers.attention.onnx_backend import onnx_lowering, packed_token_indices
|
|
12
13
|
from stackformers.attention.varlen_backend import try_varlen_attn
|
|
13
14
|
from stackformers.sequence import AllValid, PaddedTensor
|
|
14
15
|
|
|
15
16
|
if TYPE_CHECKING:
|
|
16
17
|
from jaxtyping import Float
|
|
17
18
|
|
|
18
|
-
from stackformers.sequence import
|
|
19
|
+
from stackformers.sequence import PackedTensor
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
def _repeat_padded_kv_heads(
|
|
@@ -105,6 +106,7 @@ def _sdpa_with_empty_rows(q: Tensor, k: Tensor, v: Tensor, attn_mask: Tensor) ->
|
|
|
105
106
|
return out.masked_fill(empty_rows, 0.0)
|
|
106
107
|
|
|
107
108
|
|
|
109
|
+
@onnx_lowering(packed_token_indices)
|
|
108
110
|
def _cu_to_indices(cu: Tensor, b: int) -> tuple[Tensor, Tensor]:
|
|
109
111
|
"""Return ``(batch_idx, pos_idx)``, each shape ``(nt,)``, from ``cu_seqlens``.
|
|
110
112
|
|
|
@@ -146,8 +148,8 @@ def packed_attn_or_fallback(
|
|
|
146
148
|
q: Tensor,
|
|
147
149
|
k: Tensor,
|
|
148
150
|
v: Tensor,
|
|
149
|
-
q_seq: PackedTensor
|
|
150
|
-
k_seq: PackedTensor
|
|
151
|
+
q_seq: PackedTensor,
|
|
152
|
+
k_seq: PackedTensor,
|
|
151
153
|
causal: bool,
|
|
152
154
|
window_size: int | None,
|
|
153
155
|
bias: Tensor | None,
|
|
@@ -27,7 +27,6 @@ from stackformers.sequence import (
|
|
|
27
27
|
PackedTensor,
|
|
28
28
|
PaddedTensor,
|
|
29
29
|
SequenceInput,
|
|
30
|
-
packed_to_padded,
|
|
31
30
|
)
|
|
32
31
|
|
|
33
32
|
if TYPE_CHECKING:
|
|
@@ -147,7 +146,7 @@ class PackedSelfAttention(nn.Module):
|
|
|
147
146
|
case NoAttnBias():
|
|
148
147
|
bias = None
|
|
149
148
|
case _:
|
|
150
|
-
bias = self.attn_bias(
|
|
149
|
+
bias = self.attn_bias(input.to_padded())
|
|
151
150
|
causal, window, allowed = unwrap_or_raise(
|
|
152
151
|
resolve_self_mask(
|
|
153
152
|
self_attn_mask, cfg.causal, cfg.window_size, input.max_seqlen, input.x.device
|
|
@@ -22,7 +22,6 @@ from stackformers.sequence import (
|
|
|
22
22
|
PackedTensor,
|
|
23
23
|
PaddedTensor,
|
|
24
24
|
SequenceInput,
|
|
25
|
-
packed_to_padded,
|
|
26
25
|
)
|
|
27
26
|
|
|
28
27
|
if TYPE_CHECKING:
|
|
@@ -106,7 +105,7 @@ class SelfAttention(nn.Module):
|
|
|
106
105
|
case NoAttnBias():
|
|
107
106
|
bias = None
|
|
108
107
|
case _:
|
|
109
|
-
bias = self.attn_bias(
|
|
108
|
+
bias = self.attn_bias(input.to_padded())
|
|
110
109
|
causal, window, allowed = unwrap_or_raise(
|
|
111
110
|
resolve_self_mask(
|
|
112
111
|
self_attn_mask, cfg.causal, cfg.window_size, input.max_seqlen, input.x.device
|
|
@@ -20,7 +20,7 @@ from stackformers.result import Err, Ok, Result
|
|
|
20
20
|
if TYPE_CHECKING:
|
|
21
21
|
from collections.abc import Callable
|
|
22
22
|
|
|
23
|
-
from stackformers.sequence import
|
|
23
|
+
from stackformers.sequence import PackedTensor
|
|
24
24
|
|
|
25
25
|
_FALLBACK_NOTE = " Falling back to padded SDPA; performance may be lower."
|
|
26
26
|
_P = ParamSpec("_P")
|
|
@@ -109,8 +109,8 @@ def attempt_varlen_attn(
|
|
|
109
109
|
q: Tensor,
|
|
110
110
|
k: Tensor,
|
|
111
111
|
v: Tensor,
|
|
112
|
-
q_seq: PackedTensor
|
|
113
|
-
k_seq: PackedTensor
|
|
112
|
+
q_seq: PackedTensor,
|
|
113
|
+
k_seq: PackedTensor,
|
|
114
114
|
causal: bool,
|
|
115
115
|
window_size: int | None,
|
|
116
116
|
bias: Tensor | None,
|
|
@@ -165,8 +165,8 @@ def try_varlen_attn(
|
|
|
165
165
|
q: Tensor,
|
|
166
166
|
k: Tensor,
|
|
167
167
|
v: Tensor,
|
|
168
|
-
q_seq: PackedTensor
|
|
169
|
-
k_seq: PackedTensor
|
|
168
|
+
q_seq: PackedTensor,
|
|
169
|
+
k_seq: PackedTensor,
|
|
170
170
|
causal: bool,
|
|
171
171
|
window_size: int | None,
|
|
172
172
|
bias: Tensor | None,
|
|
@@ -124,18 +124,23 @@ exporter. See the complete adapter and regression cases in
|
|
|
124
124
|
For dynamic spatial dimensions, export with the tested settings:
|
|
125
125
|
|
|
126
126
|
```python
|
|
127
|
-
|
|
127
|
+
program = torch.onnx.export(
|
|
128
128
|
adapter,
|
|
129
129
|
(data, abs_positions),
|
|
130
130
|
dynamic_shapes=dynamic_shapes,
|
|
131
|
-
|
|
131
|
+
opset_version=18,
|
|
132
|
+
optimize=True,
|
|
132
133
|
)
|
|
133
|
-
program = torch.onnx.export(exported, opset_version=18, optimize=False)
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
Exporter optimization remains enabled alongside ONNX Runtime's own graph
|
|
137
|
+
optimizations. During direct ONNX capture, an internal decorator selects a standard
|
|
138
|
+
ONNX subgraph for packed token indices, avoiding the broken `repeat_interleave`
|
|
139
|
+
lowering. No custom operators or export registration are required. Eager execution,
|
|
140
|
+
`torch.compile`, and ordinary `torch.export` keep the native PyTorch implementation.
|
|
141
|
+
Export the adapter directly: converting an already captured `ExportedProgram`
|
|
142
|
+
bypasses this Python dispatch and can still hit the upstream optimizer bug.
|
|
143
|
+
The number of packed grids remains static per exported graph;
|
|
139
144
|
spatial dimensions and supplied positions can vary. Real GPU throughput and model
|
|
140
145
|
quality require target-workload measurement.
|
|
141
146
|
|