[claude] Normalized Vector refinement (extension) type#7566
Closed
connortsui20 wants to merge 1 commit intodevelopfrom
Closed
[claude] Normalized Vector refinement (extension) type#7566connortsui20 wants to merge 1 commit intodevelopfrom
connortsui20 wants to merge 1 commit intodevelopfrom
Conversation
Merging this PR will degrade performance by 11.81%
Performance Changes
Comparing Footnotes
|
Lift the "rows are unit-norm" invariant out of L2Denorm runtime
validation and into a refinement of Vector. NormalizedVector shares the
same FixedSizeList(float, dim) storage but carries a distinct ExtId so
downstream operators can dispatch on the type-system claim.
Changes:
- Add `vortex-tensor/src/normalized_vector/{mod,vtable,matcher}.rs`
with `NormalizedVector::try_new` (validates rows) and
`NormalizedVector::new_unchecked` (lossy callers).
- Extract a shared `validate_vector_storage_dtype` helper from
`Vector::validate_dtype`; reuse it from `NormalizedVector`.
- Extend `AnyVector` to match both `Vector` and `NormalizedVector`,
surfacing an `is_normalized` field. Add `AnyNormalizedVector`.
- Tighten `L2Denorm::return_dtype` to require an `AnyNormalizedVector`
first child, output a sibling plain `Vector`. Replace
`try_new_array`/`new_array_unchecked` with safe `try_new_array`
(zero-row cross-check only) plus `new_array` (no cross-check, used
by lossy callers).
- Refactor `DenormOrientation` into a per-operand `NormalForm`
classifier and use it from `CosineSimilarity`/`InnerProduct`/
`L2Norm`. Naked `NormalizedVector` operands now hit the fast path:
`L2Norm` returns constant `1.0`; `CosineSimilarity` collapses to a
dot product; `InnerProduct` falls through to the regular dot.
- Propagate the `is_normalized` marker through `SorfTransform`
(orthogonal transforms preserve L2 norms).
- Update `turboquant_encode` to wrap the quantized FSL via
`NormalizedVector::new_unchecked` and call the safe `L2Denorm`
constructor; remove the L2Denorm `unsafe`.
- Drop FixedShapeTensor + L2Denorm support and migrate the affected
tests; FST remains usable in the other operators.
- Add tests for the new matcher, dtype validation, and naked
`NormalizedVector` fast paths.
The remaining `unsafe` blocks in this crate are the documented lossy
`NormalizedVector::new_unchecked` call sites and pre-existing
low-level buffer ops unrelated to the invariant.
Verification:
- cargo build -p vortex-tensor
- cargo test -p vortex-tensor (289 passed)
- cargo build -p vector-search-bench
- cargo +nightly fmt --all
- ./scripts/public-api.sh
- cargo clippy -p vortex-tensor --all-targets --all-features
Signed-off-by: Claude <noreply@anthropic.com>
a1e9907 to
68261b5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Signed-off-by: Connor Tsui connor.tsui20@gmail.com