Add UnitVector tensor refinement - #9421
Conversation
Merging this PR will regress 2 benchmarks
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | WallTime | words_gather_scalar[65536] |
8.3 µs | 9.4 µs | -12.02% |
| ❌ | Simulation | take[small_m/shuffled/primitive/nonnull/chunks=16384/indices=16] |
1.1 ms | 1.2 ms | -11.37% |
| ⚡ | Simulation | encode_nullable[256] |
333.5 µs | 231.5 µs | +44.08% |
| ⚡ | Simulation | encode_nullable[2] |
1,109.2 µs | 770.4 µs | +43.98% |
| ⚡ | Simulation | encode_nullable[32] |
368.5 µs | 259.4 µs | +42.08% |
| ⚡ | Simulation | encode_non_nullable[2] |
866.5 µs | 686.6 µs | +26.21% |
| ⚡ | Simulation | encode_non_nullable[256] |
256.5 µs | 209.3 µs | +22.56% |
| ⚡ | Simulation | encode_non_nullable[32] |
304.8 µs | 252.9 µs | +20.51% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing ct/unit-vector (7a41686) with ct/extension-coerce-to (ec1dddb)
Footnotes
-
89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
41b939c to
f7e4f38
Compare
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
f7e4f38 to
7a41686
Compare
Depends on #9418.
Rationale for this change
Normalizedcurrently stores normalizedVectorvalues with the same dtype as arbitrary vectors, so the unit-norm invariant is not represented in the type.What changes are included in this PR?
Adds the
UnitVectorextension dtype for vectors whose rows have norm1.0within tolerance or are exactly zero. Adds theL2Normalizescalar function and uses it in theNormalizedencoding, where vector directions becomeUnitVectorwhile fixed-shape tensor directions retain their dtype.What APIs are changed? Are there any user-facing changes?
Adds the public
UnitVectordtype andL2Normalizescalar function.InnerProductandCosineSimilarityaccept compatibleVectorandUnitVectorpairs.