Skip to content

Add UnitVector tensor refinement - #9515

Draft
connortsui20 wants to merge 4 commits into
ct/norm-compute-modefrom
ct/unit-vector-refinement
Draft

Add UnitVector tensor refinement#9515
connortsui20 wants to merge 4 commits into
ct/norm-compute-modefrom
ct/unit-vector-refinement

Conversation

@connortsui20

Copy link
Copy Markdown
Member

Rationale for this change

Adds a logical refinement for unit-normalized vectors on top of #9513. NormMode::AssumeNormalized can trust the approximate refinement for faster norm and cosine operations, while exact mode continues to measure the physical values.

What changes are included in this PR?

Adds the checked UnitVector dtype, mixed vector operation support, and an L2Normalize scalar function. Zero vectors normalize to null because they do not have a direction.

What APIs are changed? Are there any user-facing changes?

Adds UnitVector and L2Normalize, and permits Vector and UnitVector inputs in the same inner-product and cosine operation. The existing Normalized physical encoding and metadata stay unchanged.

@connortsui20 connortsui20 added the changelog/feature A new feature label Aug 20, 2026
@codspeed-hq

codspeed-hq Bot commented Aug 20, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 15.74%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 2 improved benchmarks
✅ 1536 untouched benchmarks
⏩ 872 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation take[duplicates/repeated/primitive/nonnull/chunks=16/indices=1000] 270.2 µs 228.9 µs +18.07%
WallTime words_gather_scalar[65536] 9.4 µs 8.3 µs +13.46%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ct/unit-vector-refinement (b1fb0a4) with ct/norm-compute-mode (4c3a203)2

Open in CodSpeed

Footnotes

  1. 872 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.

  2. No successful run was found on ct/norm-compute-mode (76656f1) during the generation of this report, so 1d57c92 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
@connortsui20
connortsui20 force-pushed the ct/unit-vector-refinement branch from 1ea7761 to b1fb0a4 Compare August 20, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant