stackformers 6.0.0rc1__tar.gz → 6.0.0rc2__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.0rc1 → stackformers-6.0.0rc2}/CHANGELOG.md +11 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/PKG-INFO +1 -1
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/pyproject.toml +1 -1
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/README.md +23 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/coordinates.py +24 -14
- stackformers-6.0.0rc2/stackformers/attention2d/geometry_precision.py +17 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/query_anchors.py +6 -2
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/encoder2d/README.md +13 -4
- stackformers-6.0.0rc2/stackformers/encoder2d/_callable_stage.py +36 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/encoder2d/encoder.py +10 -4
- stackformers-6.0.0rc2/tests/attention2d/test_coordinates.py +68 -0
- stackformers-6.0.0rc2/tests/attention2d/test_query_anchors.py +75 -0
- stackformers-6.0.0rc2/tests/encoder2d/test_encoder.py +91 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/uv.lock +1 -1
- stackformers-6.0.0rc1/tests/encoder2d/test_encoder.py +0 -42
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/.claudeignore +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/.github/pull_request_template.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/.github/workflows/check.yml +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/.gitignore +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/.python-version +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/.vscode/settings.json +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/AGENTS.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/CITATION.cff +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/CONTRIBUTING.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/Justfile +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/LICENSE +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/PLAN.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/README.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/docs/api-guide.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/docs/assets/social-preview.jpg +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/docs/assets/social-preview.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/docs/compatibility.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/docs/improvement-plan.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/docs/inference.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/docs/research.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/examples/README.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/examples/causal_language_model.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/examples/encoder_decoder_onnxruntime.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/examples/image_encoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/examples/padded_and_packed.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/examples/point_cloud_encoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/examples/spatial_encoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/examples/subclassed_encoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/pyrefly.toml +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/pytest.ini +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/ruff.toml +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/DEVLOG.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/_decoder_equations.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/_projection_packing.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/_result.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/alignment.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/all_valid_decoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/README.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/all_valid.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/bias.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/cache.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/cache_validation.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/cached.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/config.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/cross_attn.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/distance_bias.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/factory.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/layout.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/masking.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/onnx_backend.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/ops.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/packed_cross_attn.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/packed_self_attn.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/protocols.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/self_attn.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention/varlen_backend.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/_geometry_module.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/centroid_queries.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/cross_attn_pooling.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/factory.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/figures/window_cross_attention_2d.svg +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/figures/window_self_attention_2d.svg +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/packed_windows.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/protocols.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/self_attn.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/sequence.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/attention2d/windows.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/config.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/cross_attender.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/decoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/decoder_cache.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/encoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/encoder2d/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/encoder2d/layer.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/encoder2d/protocols.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/encoder2d/tokenwise.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/encoder2d/window_stage.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/DEVLOG.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/README.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/config.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/factory.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/geglu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/gelu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/hardswish_glu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/packed_geglu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/packed_hardswish_glu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/packed_swiglu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/protocols.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/relu_squared.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/feedforward/swiglu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/layers.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/mlm/README.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/mlm/config.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/mlm/head.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/mlm/head_cosine.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/mlm/masking.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/mlm/protocols.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/mlm/wrapper.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/norm/README.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/norm/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/norm/config.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/norm/factory.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/norm/protocols.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/packing.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/positional/README.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/positional/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/positional/config.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/positional/factory.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/positional/learned.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/positional/none.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/positional/protocols.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/positional/rope1d.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/positional/rope2d.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/positional/rope_nd.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/positional/validation.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/preallocated_decoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/presets/README.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/presets/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/presets/cross_attender.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/presets/decoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/presets/encoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/presets/variable_width_encoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/py.typed +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/result/README.md +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/result/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/stackformers/sequence.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/legacy_api_rc1.json +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_all_valid.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_cached.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_config.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_contracts.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_cross_attn.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_cross_attn_cache.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_distance_bias.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_empty_rows.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_factory.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_geometry.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_kernels.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_legacy_api.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_masking.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_onnx_backend.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_ops.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_packed_cross_attn.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_packed_self_attn.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_sdpa_export.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_self_attn.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention/test_varlen_backend.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention2d/conftest.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention2d/test_cross_attn_pooling.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention2d/test_export.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention2d/test_packed_windows.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention2d/test_self_attn.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention2d/test_sequence.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/attention2d/test_windows.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/conftest.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/encoder2d/conftest.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/encoder2d/test_layer.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/encoder2d/test_window_stage.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/export_utils.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/feedforward/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/feedforward/legacy_swiglu_4_6.json +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/feedforward/test_config.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/feedforward/test_factory.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/feedforward/test_geglu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/feedforward/test_gelu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/feedforward/test_hardswish_glu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/feedforward/test_packed_geglu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/feedforward/test_packed_hardswish_glu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/feedforward/test_packed_swiglu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/feedforward/test_relu_squared.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/feedforward/test_swiglu.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/mlm/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/mlm/test_empty_selection.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/mlm/test_head.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/mlm/test_head_cosine.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/mlm/test_masking.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/mlm/test_wrapper.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/norm_topology_helpers.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/positional/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/positional/test_cacheable.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/positional/test_learned_pos.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/positional/test_rope.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/positional/test_rope_nd.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/presets/__init__.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/presets/test_cross_attender.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/presets/test_decoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/presets/test_encoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/presets/test_projection_packing.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/presets/test_variable_width_encoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_alignment.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_all_valid_decoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_core_results.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_cross_attender.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_decoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_decoder_cache.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_decoder_equations.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_encoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_encoder_decoder_example.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_examples.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_export_utils.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_layers.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_norm.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_packing.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_preallocated_decoder.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_projection_packing.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_public_api.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_result.py +0 -0
- {stackformers-6.0.0rc1 → stackformers-6.0.0rc2}/tests/test_sequence.py +0 -0
|
@@ -6,6 +6,17 @@ 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.0rc2]
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
- Resolve `Encoder2d` stages through their registered module slots so replacement
|
|
14
|
+
changes forward execution and checkpoint state together, preserving parameter names.
|
|
15
|
+
- Accumulate pooling centroids in at least float32 while retaining float64 geometry,
|
|
16
|
+
avoiding float16 overflow for finite physical coordinate means.
|
|
17
|
+
- Remove a local coordinate origin before reducing normalization precision so small
|
|
18
|
+
float64 separations survive around large physical offsets.
|
|
19
|
+
|
|
9
20
|
## [6.0.0rc1]
|
|
10
21
|
|
|
11
22
|
### 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.0rc2
|
|
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
|
|
@@ -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.0rc2"
|
|
8
8
|
description = "Composable PyTorch transformers for vision, spatial, and sequence research"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
@@ -90,6 +90,19 @@ column neighbours for the second. Missing neighbours are excluded; an axis with
|
|
|
90
90
|
no pairs or zero mean separation uses scale one. Nonuniform spacing remains
|
|
91
91
|
nonuniform. Packed geometry uses stored tokens without a padded canvas.
|
|
92
92
|
|
|
93
|
+
Coordinate arithmetic promotes float16 and bfloat16 to float32 and retains supplied
|
|
94
|
+
float64 precision. Normalization subtracts a valid local source origin before
|
|
95
|
+
computing its centered offsets; only the final normalized attention coordinates
|
|
96
|
+
are converted to float32. Query transforms reuse that same source origin and frame.
|
|
97
|
+
This preserves small representable separations around a large float64 origin.
|
|
98
|
+
|
|
99
|
+
Spacing estimates depend on valid adjacent pairs. Removing tokens can change the
|
|
100
|
+
estimated scale or select the unit fallback, even for the remaining physical
|
|
101
|
+
positions. Use an explicit physical-coordinate policy and calibrated RoPEND when
|
|
102
|
+
remaining source positions must retain the same coordinate scale after masking.
|
|
103
|
+
This data-dependent normalization policy remains a research choice, not a claim
|
|
104
|
+
of invariance to token removal.
|
|
105
|
+
|
|
93
106
|
This removes overall per-window translation and axis scale from default attention.
|
|
94
107
|
For example, source coordinates `[0, 1, 2, 3]` and pooled coordinates
|
|
95
108
|
`[0.5, 2.5, 4.5, 6.5]` have the same normalized offsets. Successive pooling stages
|
|
@@ -135,6 +148,16 @@ Anchors are computed before attention from geometry alone and remain the output
|
|
|
135
148
|
Coordinates retain their floating point dtype under AMP. The integer output tile
|
|
136
149
|
is row-major, with extents `ceil(H/wh)*oh` by `ceil(W/ww)*ow` and unchanged channels.
|
|
137
150
|
|
|
151
|
+
Centroid sums and counts use at least float32 accumulation, preserving float64 when
|
|
152
|
+
supplied. Physical anchors are cast back to the input coordinate dtype only after
|
|
153
|
+
the mean is computed, avoiding float16 overflow from otherwise finite centroids.
|
|
154
|
+
|
|
155
|
+
Default RoPEND computes rotary phases without coordinate autograd. A trainable
|
|
156
|
+
coordinate or query-position strategy requires an injected positional encoding
|
|
157
|
+
that differentiates through its coordinates to learn from the feature loss.
|
|
158
|
+
Returning differentiable physical output positions alone does not establish that
|
|
159
|
+
attention propagates gradients to geometry.
|
|
160
|
+
|
|
138
161
|
## Independent extension points
|
|
139
162
|
|
|
140
163
|
Both layers accept `attention` and `coordinates`; pooling additionally accepts
|
|
@@ -8,6 +8,7 @@ import torch
|
|
|
8
8
|
from einops import rearrange
|
|
9
9
|
|
|
10
10
|
from stackformers.attention2d._geometry_module import GeometryModule
|
|
11
|
+
from stackformers.attention2d.geometry_precision import accumulation_positions
|
|
11
12
|
from stackformers.attention2d.windows import validate_window
|
|
12
13
|
from stackformers.sequence import PackedTensor, PaddedTensor, materialize_padding_mask
|
|
13
14
|
|
|
@@ -79,11 +80,15 @@ class NormalizedWindowCoordinates(GeometryModule):
|
|
|
79
80
|
"""Normalize dense window geometry without data-dependent token selection."""
|
|
80
81
|
valid = materialize_padding_mask(context)
|
|
81
82
|
with torch.autocast(device_type=context.x.device.type, enabled=False):
|
|
82
|
-
positions = context.abs_positions
|
|
83
|
+
positions = accumulation_positions(context.abs_positions)
|
|
83
84
|
safe = positions.masked_fill(~rearrange(valid, "b s -> b s 1"), 0)
|
|
85
|
+
first = valid.to(torch.int64).argmax(dim=1)
|
|
86
|
+
first_indices = rearrange(first, "b -> b 1 1").expand(-1, 1, 2)
|
|
87
|
+
origin = safe.gather(1, first_indices)
|
|
88
|
+
relative = (safe - origin).masked_fill(~rearrange(valid, "b s -> b s 1"), 0)
|
|
84
89
|
count = valid.sum(dim=1).clamp_min(1)
|
|
85
|
-
center =
|
|
86
|
-
grid = rearrange(
|
|
90
|
+
center = relative.sum(dim=1) / rearrange(count, "b -> b 1")
|
|
91
|
+
grid = rearrange(relative, "b (h w) c -> b h w c", h=self.window[0])
|
|
87
92
|
mask = rearrange(valid, "b (h w) -> b h w", h=self.window[0])
|
|
88
93
|
vertical = mask[:, 1:, :] & mask[:, :-1, :]
|
|
89
94
|
horizontal = mask[:, :, 1:] & mask[:, :, :-1]
|
|
@@ -96,13 +101,14 @@ class NormalizedWindowCoordinates(GeometryModule):
|
|
|
96
101
|
def transform(queries: PaddedTensor) -> PaddedTensor:
|
|
97
102
|
"""Reuse the source frame rather than recalibrating on query geometry."""
|
|
98
103
|
with torch.autocast(device_type=queries.x.device.type, enabled=False):
|
|
99
|
-
positions = queries.abs_positions
|
|
100
|
-
|
|
104
|
+
positions = accumulation_positions(queries.abs_positions)
|
|
105
|
+
relative = positions - origin
|
|
106
|
+
normalized = (relative - rearrange(center, "b c -> b 1 c")) / rearrange(
|
|
101
107
|
scale, "b c -> b 1 c"
|
|
102
108
|
)
|
|
103
109
|
valid = materialize_padding_mask(queries)
|
|
104
110
|
normalized = normalized.masked_fill(~rearrange(valid, "b n -> b n 1"), 0)
|
|
105
|
-
return queries._replace(abs_positions=normalized)
|
|
111
|
+
return queries._replace(abs_positions=normalized.float())
|
|
106
112
|
|
|
107
113
|
return transform(context), transform
|
|
108
114
|
|
|
@@ -113,23 +119,27 @@ class NormalizedWindowCoordinates(GeometryModule):
|
|
|
113
119
|
lengths = context.cu_seqlens.diff()
|
|
114
120
|
owners = _owners(context)
|
|
115
121
|
with torch.autocast(device_type=context.x.device.type, enabled=False):
|
|
116
|
-
positions = context.abs_positions
|
|
117
|
-
|
|
122
|
+
positions = accumulation_positions(context.abs_positions)
|
|
123
|
+
padded_positions = torch.cat((positions, positions.new_zeros((1, 2))))
|
|
124
|
+
origins = padded_positions[context.cu_seqlens[:-1].to(torch.int64)]
|
|
125
|
+
origins = origins.masked_fill(rearrange(lengths == 0, "b -> b 1"), 0)
|
|
126
|
+
relative = positions - origins[owners]
|
|
127
|
+
sums = positions.new_zeros((lengths.shape[0], 2)).index_add(0, owners, relative)
|
|
118
128
|
centers = sums / rearrange(lengths.clamp_min(1), "b -> b 1")
|
|
119
129
|
scales = torch.stack(
|
|
120
|
-
[self._packed_spacing(
|
|
130
|
+
[self._packed_spacing(relative, owners, slots, lengths, axis) for axis in (0, 1)],
|
|
121
131
|
dim=-1,
|
|
122
132
|
)
|
|
123
|
-
normalized_context = (
|
|
133
|
+
normalized_context = ((relative - centers[owners]) / scales[owners]).float()
|
|
124
134
|
|
|
125
135
|
def transform(queries: PackedTensor) -> PackedTensor:
|
|
126
136
|
"""Transform independently sized packed queries in their corresponding source frames."""
|
|
127
137
|
query_owners = _owners(queries)
|
|
128
138
|
with torch.autocast(device_type=queries.x.device.type, enabled=False):
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
]
|
|
132
|
-
return queries._replace(abs_positions=normalized)
|
|
139
|
+
positions = accumulation_positions(queries.abs_positions)
|
|
140
|
+
relative = positions - origins[query_owners]
|
|
141
|
+
normalized = (relative - centers[query_owners]) / scales[query_owners]
|
|
142
|
+
return queries._replace(abs_positions=normalized.float())
|
|
133
143
|
|
|
134
144
|
return context._replace(abs_positions=normalized_context), transform
|
|
135
145
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Choose accumulation precision for physical coordinate arithmetic."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
import torch
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from jaxtyping import Float
|
|
11
|
+
from torch import Tensor
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def accumulation_positions(positions: Float[Tensor, "... c"]) -> Float[Tensor, "... c"]:
|
|
15
|
+
"""Promote half precision while retaining supplied float64 coordinate information."""
|
|
16
|
+
dtype = torch.float64 if positions.dtype == torch.float64 else torch.float32
|
|
17
|
+
return positions.to(dtype=dtype)
|
|
@@ -7,6 +7,7 @@ from typing import TYPE_CHECKING
|
|
|
7
7
|
import torch
|
|
8
8
|
from einops import rearrange, repeat
|
|
9
9
|
|
|
10
|
+
from stackformers.attention2d.geometry_precision import accumulation_positions
|
|
10
11
|
from stackformers.sequence import (
|
|
11
12
|
PackedTensor,
|
|
12
13
|
PaddedTensor,
|
|
@@ -50,13 +51,15 @@ def padded_queries(
|
|
|
50
51
|
"""Build query anchors from valid supplied coordinates before attention."""
|
|
51
52
|
valid = materialize_padding_mask(context)
|
|
52
53
|
with torch.autocast(device_type=context.x.device.type, enabled=False):
|
|
53
|
-
positions = context.abs_positions
|
|
54
|
+
positions = accumulation_positions(context.abs_positions)
|
|
55
|
+
positions = positions.masked_fill(~rearrange(valid, "b s -> b s 1"), 0)
|
|
54
56
|
selected = rearrange(valid, "b s -> b 1 s") & rearrange(regions, "n s -> 1 n s")
|
|
55
57
|
membership = selected.to(positions.dtype)
|
|
56
58
|
counts = membership.sum(dim=-1)
|
|
57
59
|
sums = membership @ positions
|
|
58
60
|
window_counts = valid.sum(dim=-1).to(positions.dtype)
|
|
59
61
|
anchors = _centroids(sums, counts, positions.sum(dim=1), window_counts)
|
|
62
|
+
anchors = anchors.to(dtype=context.abs_positions.dtype)
|
|
60
63
|
query_valid = repeat(valid.any(dim=-1), "b -> b n", n=features.shape[0])
|
|
61
64
|
values = repeat(features, "n d -> b n d", b=context.x.shape[0])
|
|
62
65
|
return PaddedTensor(values, query_valid, anchors)
|
|
@@ -77,7 +80,7 @@ def packed_queries(
|
|
|
77
80
|
)
|
|
78
81
|
batch, queries = lengths.shape[0], features.shape[0]
|
|
79
82
|
with torch.autocast(device_type=context.x.device.type, enabled=False):
|
|
80
|
-
positions = context.abs_positions
|
|
83
|
+
positions = accumulation_positions(context.abs_positions)
|
|
81
84
|
membership = rearrange(regions[:, source_slots], "n nt -> nt n").to(positions.dtype)
|
|
82
85
|
weighted_positions = rearrange(membership, "nt n -> nt n 1") * rearrange(
|
|
83
86
|
positions, "nt c -> nt 1 c"
|
|
@@ -90,6 +93,7 @@ def packed_queries(
|
|
|
90
93
|
0, owners, positions
|
|
91
94
|
)
|
|
92
95
|
anchors = _centroids(sums, counts, window_sums, lengths.to(positions.dtype))
|
|
96
|
+
anchors = anchors.to(dtype=context.abs_positions.dtype)
|
|
93
97
|
valid = repeat(lengths > 0, "b -> b n", n=queries)
|
|
94
98
|
values = repeat(features, "n d -> b n d", b=batch)
|
|
95
99
|
query_lengths = (lengths > 0).to(torch.int64) * queries
|
|
@@ -119,10 +119,14 @@ Existing 1D attention remains responsible for kernel selection and GPU fallbacks
|
|
|
119
119
|
Repeated blocks with fixed non-overlapping windows do not communicate across window
|
|
120
120
|
boundaries until a later stage regroups those windows.
|
|
121
121
|
|
|
122
|
-
The encoder stores a fixed
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
The encoder stores a fixed order of registered stage names, `layer_0`, `layer_1`,
|
|
123
|
+
etc. Its `layers` property resolves the current modules from that registry; it
|
|
124
|
+
does not retain a second set of execution references. Replacing a stage through
|
|
125
|
+
`set_submodule` changes execution, parameter discovery, and checkpoint state
|
|
126
|
+
together. Existing checkpoint parameter names are preserved. Stateless callables
|
|
127
|
+
use a module adapter in the same registered slots; stateful collaborators must
|
|
128
|
+
be `nn.Module` instances. Parameters and buffers participate in optimization,
|
|
129
|
+
device moves, and state dictionaries.
|
|
126
130
|
Construct separate block instances unless intentional parameter sharing is desired.
|
|
127
131
|
Use an identity module when final normalization is unwanted.
|
|
128
132
|
|
|
@@ -136,3 +140,8 @@ model or encode arbitrary custom policy configuration.
|
|
|
136
140
|
This release candidate has static checks only. Compute, gradient, checkpoint, and
|
|
137
141
|
ONNX Runtime tests have not been run for this revision. The padded-record path is
|
|
138
142
|
intended for dynamic spatial export; custom collaborators must also support export.
|
|
143
|
+
|
|
144
|
+
Shared spatial preparation removes per-block partitioning, not all layout work.
|
|
145
|
+
The existing packed attention fallback still pads projected Q/K/V and gathers its
|
|
146
|
+
output on each attention call. Packed and directly padded execution therefore need
|
|
147
|
+
separate target-device measurements; partition reuse does not establish a speedup.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Register stateless spatial callables in the same module tree as ordinary encoder stages."""
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, overload
|
|
4
|
+
|
|
5
|
+
import torch.nn as nn
|
|
6
|
+
from typing_extensions import override
|
|
7
|
+
|
|
8
|
+
from stackformers.attention2d.sequence import PackedTensor2d, PaddedTensor2d
|
|
9
|
+
from stackformers.encoder2d.protocols import SpatialTransform2d
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CallableStage(nn.Module):
|
|
13
|
+
"""Give a structural callable a replaceable registered stage slot."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, operation: SpatialTransform2d) -> None:
|
|
16
|
+
"""Borrow the stateless operation without introducing parameters or model choices."""
|
|
17
|
+
super().__init__()
|
|
18
|
+
self.operation = operation
|
|
19
|
+
|
|
20
|
+
@overload
|
|
21
|
+
def forward(self, input: PaddedTensor2d) -> PaddedTensor2d:
|
|
22
|
+
"""Keep the padded representation through the wrapped operation."""
|
|
23
|
+
...
|
|
24
|
+
|
|
25
|
+
@overload
|
|
26
|
+
def forward(self, input: PackedTensor2d) -> PackedTensor2d:
|
|
27
|
+
"""Keep the packed representation through the wrapped operation."""
|
|
28
|
+
...
|
|
29
|
+
|
|
30
|
+
@override
|
|
31
|
+
def forward(self, input: PaddedTensor2d | PackedTensor2d) -> PaddedTensor2d | PackedTensor2d:
|
|
32
|
+
"""Execute the operation currently registered at this stage slot."""
|
|
33
|
+
return self.operation(input)
|
|
34
|
+
|
|
35
|
+
if TYPE_CHECKING:
|
|
36
|
+
__call__ = forward
|
|
@@ -7,6 +7,7 @@ import torch.nn as nn
|
|
|
7
7
|
from typing_extensions import override
|
|
8
8
|
|
|
9
9
|
from stackformers.attention2d.sequence import PackedTensor2d, PaddedTensor2d
|
|
10
|
+
from stackformers.encoder2d._callable_stage import CallableStage
|
|
10
11
|
from stackformers.encoder2d.protocols import SpatialTransform2d
|
|
11
12
|
from stackformers.encoder2d.tokenwise import apply_tokenwise
|
|
12
13
|
from stackformers.norm.protocols import Norm
|
|
@@ -18,12 +19,17 @@ class Encoder2d(nn.Module):
|
|
|
18
19
|
def __init__(self, layers: Sequence[SpatialTransform2d], final_norm: Norm) -> None:
|
|
19
20
|
"""Register module stages while allowing stateless structural implementations."""
|
|
20
21
|
super().__init__()
|
|
21
|
-
self.
|
|
22
|
-
for
|
|
23
|
-
if isinstance(layer, nn.Module)
|
|
24
|
-
|
|
22
|
+
self._layer_names = tuple(f"layer_{index}" for index in range(len(layers)))
|
|
23
|
+
for name, layer in zip(self._layer_names, layers, strict=True):
|
|
24
|
+
module = layer if isinstance(layer, nn.Module) else CallableStage(layer)
|
|
25
|
+
self.add_module(name, module)
|
|
25
26
|
self.final_norm = final_norm
|
|
26
27
|
|
|
28
|
+
@property
|
|
29
|
+
def layers(self) -> tuple[nn.Module, ...]:
|
|
30
|
+
"""Resolve the current registered stages so module replacement changes execution too."""
|
|
31
|
+
return tuple(self.get_submodule(name) for name in self._layer_names)
|
|
32
|
+
|
|
27
33
|
@overload
|
|
28
34
|
def forward(self, input: PaddedTensor2d) -> PaddedTensor2d:
|
|
29
35
|
"""Return dense features with validity, coordinates, and extents from the final stage."""
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Local coordinate frames preserve small float64 separations at large physical origins."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
import torch
|
|
5
|
+
from einops import rearrange
|
|
6
|
+
|
|
7
|
+
from stackformers.attention2d.coordinates import NormalizedWindowCoordinates
|
|
8
|
+
from stackformers.sequence import PackedTensor, PaddedTensor
|
|
9
|
+
from tests.conftest import atol
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.fixture
|
|
13
|
+
def context(device_dtype: tuple[torch.device, torch.dtype]) -> PaddedTensor:
|
|
14
|
+
"""Surround a nonuniform float64 window with empty windows and NaN invalid coordinates."""
|
|
15
|
+
device, dtype = device_dtype
|
|
16
|
+
values = torch.randn(3, 6, 8, device=device, dtype=dtype)
|
|
17
|
+
valid = torch.zeros(3, 6, device=device, dtype=torch.bool)
|
|
18
|
+
valid[1] = True
|
|
19
|
+
rows, cols = torch.meshgrid(
|
|
20
|
+
torch.tensor([0.0, 1.0], device=device, dtype=torch.float64),
|
|
21
|
+
torch.tensor([0.0, 1.0, 4.0], device=device, dtype=torch.float64),
|
|
22
|
+
indexing="ij",
|
|
23
|
+
)
|
|
24
|
+
positions = torch.full((3, 6, 2), float("nan"), device=device, dtype=torch.float64)
|
|
25
|
+
positions[1] = rearrange(torch.stack((rows, cols), dim=-1), "h w c -> (h w) c") + 1e9
|
|
26
|
+
return PaddedTensor(values, valid, positions)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.mark.parametrize("packed", [False, True])
|
|
30
|
+
def test_source_and_queries_share_precise_frame(context: PaddedTensor, packed: bool) -> None:
|
|
31
|
+
"""Remove the large origin before float32 conversion and bind the same frame for queries."""
|
|
32
|
+
coordinates = NormalizedWindowCoordinates((2, 3))
|
|
33
|
+
device = context.x.device
|
|
34
|
+
query_position = context.abs_positions.new_tensor([[1e9 + 0.25, 1e9 + 2.5]])
|
|
35
|
+
if packed:
|
|
36
|
+
source = PackedTensor(
|
|
37
|
+
context.x[1],
|
|
38
|
+
torch.tensor([0, 0, 6, 6], device=device, dtype=torch.int32),
|
|
39
|
+
6,
|
|
40
|
+
context.abs_positions[1],
|
|
41
|
+
)
|
|
42
|
+
prepared, transform = coordinates.packed(source, torch.arange(6, device=device))
|
|
43
|
+
queries = PackedTensor(
|
|
44
|
+
context.x[1, :1],
|
|
45
|
+
torch.tensor([0, 0, 1, 1], device=device, dtype=torch.int32),
|
|
46
|
+
1,
|
|
47
|
+
query_position,
|
|
48
|
+
)
|
|
49
|
+
actual = prepared.abs_positions
|
|
50
|
+
query_actual = transform(queries).abs_positions[0]
|
|
51
|
+
else:
|
|
52
|
+
prepared, transform = coordinates.padded(context)
|
|
53
|
+
queries = PaddedTensor(
|
|
54
|
+
context.x[:, :1],
|
|
55
|
+
torch.tensor([[False], [True], [False]], device=device),
|
|
56
|
+
query_position[None].expand(3, -1, -1),
|
|
57
|
+
)
|
|
58
|
+
actual = prepared.abs_positions[1]
|
|
59
|
+
query_actual = transform(queries).abs_positions[1, 0]
|
|
60
|
+
assert torch.equal(prepared.abs_positions[0], torch.zeros_like(actual))
|
|
61
|
+
assert torch.equal(prepared.abs_positions[2], torch.zeros_like(actual))
|
|
62
|
+
relative = context.abs_positions[1] - 1e9
|
|
63
|
+
expected = (relative - relative.new_tensor([0.5, 5.0 / 3.0])) / relative.new_tensor([1.0, 2.0])
|
|
64
|
+
tol = atol(torch.float32)
|
|
65
|
+
torch.testing.assert_close(actual, expected.float(), atol=tol, rtol=tol)
|
|
66
|
+
query_expected = actual.new_tensor([-0.25, 5.0 / 12.0])
|
|
67
|
+
torch.testing.assert_close(query_actual, query_expected, atol=tol, rtol=tol)
|
|
68
|
+
assert actual.dtype == torch.float32
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Pooling centroids retain finite physical coordinates across feature and geometry dtypes."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
import torch
|
|
5
|
+
from jaxtyping import Float
|
|
6
|
+
from torch import Tensor
|
|
7
|
+
|
|
8
|
+
from stackformers.attention2d.query_anchors import packed_queries, padded_queries, query_regions
|
|
9
|
+
from stackformers.sequence import PackedTensor, PaddedTensor
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.fixture
|
|
13
|
+
def context(device_dtype: tuple[torch.device, torch.dtype]) -> PaddedTensor:
|
|
14
|
+
"""Eight coordinates per output region have a finite half-precision mean but overflowing sum."""
|
|
15
|
+
device, dtype = device_dtype
|
|
16
|
+
values = torch.randn(1, 16, 8, device=device, dtype=dtype)
|
|
17
|
+
valid = torch.ones(1, 16, device=device, dtype=torch.bool)
|
|
18
|
+
positions = torch.full((1, 16, 2), 10_000.0, device=device, dtype=dtype)
|
|
19
|
+
return PaddedTensor(values, valid, positions)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture
|
|
23
|
+
def features(context: PaddedTensor) -> Float[Tensor, "n d"]:
|
|
24
|
+
"""Use two learned-query feature rows independently of physical coordinate accumulation."""
|
|
25
|
+
return context.x.new_zeros((2, 8))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.mark.parametrize("packed", [False, True])
|
|
29
|
+
def test_large_finite_centroids(
|
|
30
|
+
context: PaddedTensor, features: Float[Tensor, "n d"], packed: bool
|
|
31
|
+
) -> None:
|
|
32
|
+
"""Half-precision coordinates must not overflow while averaging a 4x4 window to 1x2."""
|
|
33
|
+
regions = query_regions((4, 4), (1, 2)).to(context.x.device)
|
|
34
|
+
if packed:
|
|
35
|
+
source = PackedTensor(
|
|
36
|
+
context.x[0],
|
|
37
|
+
torch.tensor([0, 16], dtype=torch.int32, device=context.x.device),
|
|
38
|
+
16,
|
|
39
|
+
context.abs_positions[0],
|
|
40
|
+
)
|
|
41
|
+
slots = torch.arange(16, device=context.x.device)
|
|
42
|
+
result = packed_queries(source, slots, features, regions)
|
|
43
|
+
expected = context.abs_positions[0, :2]
|
|
44
|
+
else:
|
|
45
|
+
result = padded_queries(context, features, regions)
|
|
46
|
+
expected = context.abs_positions[:, :2]
|
|
47
|
+
assert torch.isfinite(result.abs_positions).all()
|
|
48
|
+
assert result.abs_positions.dtype == context.abs_positions.dtype
|
|
49
|
+
torch.testing.assert_close(result.abs_positions, expected)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@pytest.mark.parametrize("packed", [False, True])
|
|
53
|
+
def test_float64_centroid_precision(
|
|
54
|
+
context: PaddedTensor, features: Float[Tensor, "n d"], packed: bool
|
|
55
|
+
) -> None:
|
|
56
|
+
"""Float64 physical offsets survive even when learned features use half precision."""
|
|
57
|
+
positions = torch.arange(16, dtype=torch.float64, device=context.x.device)
|
|
58
|
+
positions = torch.stack((positions, positions + 0.25), dim=-1) + 1e9
|
|
59
|
+
regions = query_regions((4, 4), (1, 1)).to(context.x.device)
|
|
60
|
+
if packed:
|
|
61
|
+
source = PackedTensor(
|
|
62
|
+
context.x[0],
|
|
63
|
+
torch.tensor([0, 16], dtype=torch.int32, device=context.x.device),
|
|
64
|
+
16,
|
|
65
|
+
positions,
|
|
66
|
+
)
|
|
67
|
+
actual = packed_queries(
|
|
68
|
+
source, torch.arange(16, device=context.x.device), features[:1], regions
|
|
69
|
+
).abs_positions[0]
|
|
70
|
+
else:
|
|
71
|
+
source = context._replace(abs_positions=positions[None])
|
|
72
|
+
actual = padded_queries(source, features[:1], regions).abs_positions[0, 0]
|
|
73
|
+
expected = positions.new_tensor([1e9 + 7.5, 1e9 + 7.75])
|
|
74
|
+
assert actual.dtype == torch.float64
|
|
75
|
+
assert torch.equal(actual, expected)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Resolution transitions, module registration, and record-preserving final normalization."""
|
|
2
|
+
|
|
3
|
+
from typing import overload
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
import torch
|
|
7
|
+
from torch import nn
|
|
8
|
+
|
|
9
|
+
from stackformers import Encoder2d, PackedTensor2d, PaddedTensor2d
|
|
10
|
+
from stackformers.attention2d.sequence import materialize_spatial_mask
|
|
11
|
+
from tests.conftest import atol
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_stage_composition(encoder: Encoder2d, source: PaddedTensor2d) -> None:
|
|
15
|
+
"""Pooling between residual stages changes resolution while retaining physical geometry."""
|
|
16
|
+
padded = encoder(source)
|
|
17
|
+
packed = encoder(source.to_packed()).to_padded()
|
|
18
|
+
assert padded.x.shape == (2, 3, 6, 8)
|
|
19
|
+
assert padded.spatial_shapes.tolist() == [[3, 6], [2, 4]]
|
|
20
|
+
tol = atol(source.x.dtype)
|
|
21
|
+
torch.testing.assert_close(padded.x, packed.x, atol=tol, rtol=tol)
|
|
22
|
+
valid = materialize_spatial_mask(padded)
|
|
23
|
+
torch.testing.assert_close(padded.abs_positions[valid], packed.abs_positions[valid])
|
|
24
|
+
assert torch.equal(padded.x[~valid], torch.zeros_like(padded.x[~valid]))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_module_registration(encoder: Encoder2d) -> None:
|
|
28
|
+
"""Registered stage modules expose their parameters and buffers to PyTorch."""
|
|
29
|
+
names = dict(encoder.named_parameters())
|
|
30
|
+
assert any(name.startswith("layer_0.self_attn.") for name in names)
|
|
31
|
+
assert "layer_1.queries" in names
|
|
32
|
+
assert "final_norm.weight" in names
|
|
33
|
+
state = encoder.state_dict()
|
|
34
|
+
assert "layer_1.query_positions._geometry_signature" in state
|
|
35
|
+
encoder.load_state_dict(state)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.mark.parametrize("packed", [False, True])
|
|
39
|
+
def test_stage_replacement_changes_execution(
|
|
40
|
+
encoder: Encoder2d, source: PaddedTensor2d, packed: bool
|
|
41
|
+
) -> None:
|
|
42
|
+
"""Replacing registered pooling must also remove downsampling from the executed model."""
|
|
43
|
+
replacement = nn.Identity()
|
|
44
|
+
encoder.set_submodule("layer_1", replacement)
|
|
45
|
+
assert encoder.layers[1] is replacement
|
|
46
|
+
assert "layer_1.queries" not in dict(encoder.named_parameters())
|
|
47
|
+
input = source.to_packed() if packed else source
|
|
48
|
+
result = encoder(input)
|
|
49
|
+
assert result.x.shape == input.x.shape
|
|
50
|
+
assert result.abs_positions is input.abs_positions
|
|
51
|
+
assert result.spatial_shapes is input.spatial_shapes
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@overload
|
|
55
|
+
def _shift_features(input: PaddedTensor2d) -> PaddedTensor2d:
|
|
56
|
+
"""Shift dense values without changing the spatial representation."""
|
|
57
|
+
...
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@overload
|
|
61
|
+
def _shift_features(input: PackedTensor2d) -> PackedTensor2d:
|
|
62
|
+
"""Shift packed values without changing token order."""
|
|
63
|
+
...
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _shift_features(input: PaddedTensor2d | PackedTensor2d) -> PaddedTensor2d | PackedTensor2d:
|
|
67
|
+
"""Exercise stateless structural stages without introducing an nn.Module subclass."""
|
|
68
|
+
return input._replace(x=input.x + 1)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@pytest.mark.parametrize("packed", [False, True])
|
|
72
|
+
def test_stateless_stage_is_replaceable(source: PaddedTensor2d, packed: bool) -> None:
|
|
73
|
+
"""Stateless callables use the same registered execution path as stateful modules."""
|
|
74
|
+
encoder = Encoder2d([_shift_features], nn.Identity())
|
|
75
|
+
input = source.to_packed() if packed else source
|
|
76
|
+
valid = materialize_spatial_mask(source)
|
|
77
|
+
shifted = encoder(input).to_padded()
|
|
78
|
+
torch.testing.assert_close(shifted.x[valid], source.x[valid] + 1)
|
|
79
|
+
encoder.set_submodule("layer_0", nn.Identity())
|
|
80
|
+
replaced = encoder(input).to_padded()
|
|
81
|
+
torch.testing.assert_close(replaced.x[valid], source.x[valid])
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_checkpoint_geometry_mismatch(encoder: Encoder2d) -> None:
|
|
85
|
+
"""A changed built-in geometry revision must not silently load the same learned weights."""
|
|
86
|
+
state = encoder.state_dict()
|
|
87
|
+
key = "layer_1.query_positions._geometry_signature"
|
|
88
|
+
state[key] = state[key].clone()
|
|
89
|
+
state[key][1] += 1
|
|
90
|
+
with pytest.raises(RuntimeError, match="geometry differs"):
|
|
91
|
+
encoder.load_state_dict(state)
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"""Resolution transitions, module registration, and record-preserving final normalization."""
|
|
2
|
-
|
|
3
|
-
import pytest
|
|
4
|
-
import torch
|
|
5
|
-
|
|
6
|
-
from stackformers import Encoder2d, PaddedTensor2d
|
|
7
|
-
from stackformers.attention2d.sequence import materialize_spatial_mask
|
|
8
|
-
from tests.conftest import atol
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def test_stage_composition(encoder: Encoder2d, source: PaddedTensor2d) -> None:
|
|
12
|
-
"""Pooling between residual stages changes resolution while retaining physical geometry."""
|
|
13
|
-
padded = encoder(source)
|
|
14
|
-
packed = encoder(source.to_packed()).to_padded()
|
|
15
|
-
assert padded.x.shape == (2, 3, 6, 8)
|
|
16
|
-
assert padded.spatial_shapes.tolist() == [[3, 6], [2, 4]]
|
|
17
|
-
tol = atol(source.x.dtype)
|
|
18
|
-
torch.testing.assert_close(padded.x, packed.x, atol=tol, rtol=tol)
|
|
19
|
-
valid = materialize_spatial_mask(padded)
|
|
20
|
-
torch.testing.assert_close(padded.abs_positions[valid], packed.abs_positions[valid])
|
|
21
|
-
assert torch.equal(padded.x[~valid], torch.zeros_like(padded.x[~valid]))
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def test_module_registration(encoder: Encoder2d) -> None:
|
|
25
|
-
"""Tuple-held stage modules still expose their parameters and buffers to PyTorch."""
|
|
26
|
-
names = dict(encoder.named_parameters())
|
|
27
|
-
assert any(name.startswith("layer_0.self_attn.") for name in names)
|
|
28
|
-
assert "layer_1.queries" in names
|
|
29
|
-
assert "final_norm.weight" in names
|
|
30
|
-
state = encoder.state_dict()
|
|
31
|
-
assert "layer_1.query_positions._geometry_signature" in state
|
|
32
|
-
encoder.load_state_dict(state)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def test_checkpoint_geometry_mismatch(encoder: Encoder2d) -> None:
|
|
36
|
-
"""A changed built-in geometry revision must not silently load the same learned weights."""
|
|
37
|
-
state = encoder.state_dict()
|
|
38
|
-
key = "layer_1.query_positions._geometry_signature"
|
|
39
|
-
state[key] = state[key].clone()
|
|
40
|
-
state[key][1] += 1
|
|
41
|
-
with pytest.raises(RuntimeError, match="geometry differs"):
|
|
42
|
-
encoder.load_state_dict(state)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|