Make L2Denorm an array encoding instead of a scalar function - #9138
Draft
connortsui20 wants to merge 1 commit into
Draft
Make L2Denorm an array encoding instead of a scalar function#9138connortsui20 wants to merge 1 commit into
connortsui20 wants to merge 1 commit into
Conversation
This was referenced Aug 2, 2026
`L2Denorm` was registered as a `ScalarFnVTable`, but it never behaved like one. Its constructor took an `ExecutionCtx` and scanned both children to enforce a unit-norm invariant, `L2Norm` read its stored norms instead of recomputing, `CosineSimilarity` and `InnerProduct` reached into its physical children, and the compressor scheme named it as a produced encoding. Those are all properties of a physical decomposition, not of an operation over arbitrary well-typed values. Moves it to `vortex-tensor/src/encodings/l2_denorm/` as a real `VTable` with two slots (`normalized`, `norms`). Structural validation runs on construction and on deserialization, `try_new` additionally scans for the exact unit-norm invariant, and `try_new_trusted` skips that scan for lossy normalized children whose stored norms stay authoritative. Neither constructor is `unsafe`, since violating the contract produces wrong answers rather than undefined behavior. The encoding keeps the `vortex.tensor.l2_denorm` array ID and the same two-field metadata message, so the wire format is unchanged. Slice and filter now push down into both children through `reduce_parent`. The generic `ScalarFnArray` filter rule only fired when at most one child was non-constant, which for this encoding was almost never. Also makes `L2DenormScheme` cascade its two children like `TemporalScheme` does, which lets both `HACK TO SUPPORT L2 DENORMALIZATION` special cases come out of `CascadingCompressor`. The scheme now competes on measured size like every other scheme. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XEo4wnqKfAf1QLJbdrz76j Signed-off-by: Claude <noreply@anthropic.com>
connortsui20
force-pushed
the
ct/l2-denorm-encoding
branch
from
August 2, 2026 18:03
80daa53 to
63e459b
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.
Rationale for this change
(semi-related) Tracking Issue: #9129
I would like to propose a rule we hold going forward: a scalar function never verifies its inputs, an encoding may. A scalar function takes anything well-typed and checks nothing past dtypes, which is all
return_dtypecan see anyway. An encoding owns a physical layout, so it getsVTable::validateand its own constructors, and it can hold invariants between its children. The corollary is the useful half: if you want to scan the data at construction time, you want an encoding.Note that the rule only runs one way. FoR is the edge case I can think of, since
encoded + referenceis an ordinary scalar function over any integer column and itsvalidateis purely structural. Nothing checks that the encoded values really are offsets from the minimum, because that is a compression heuristic and not a correctness requirement. So needing verification forces an encoding, but not needing it does not force a scalar function.L2Denormbroke the rule in the direction that matters: its constructor took anExecutionCtxand scanned both children for the unit-norm invariant, whichScalarFnFactoryExthas nowhere to put. Everything else follows from that.L2Normreads its stored norms instead of recomputing,CosineSimilarityandInnerProductreach into its physical children,L2DenormSchemealready listed it inproduced_encodings, and persisting it needed aScalarFnArrayPluginbehind an env var. The operation itself (normalized * norm) is valid for any tensor and any float column, so the invariant only ever existed to justify encoding-specific optimizations.What changes are included in this PR?
L2Denormbecomes aVTableinvortex-tensor/src/encodings/l2_denorm/with two slots (normalized,norms).try_newscans for the exact invariants,try_new_trustedskips the scan for lossy normalized children whose stored norms stay authoritative. Neither isunsafe, since breaking the contract gives wrong answers rather than undefined behavior.ScalarFnArrayrule only fires when at most one child is non-constant.L2DenormSchemecascades its children likeTemporalScheme, so bothHACK TO SUPPORT L2 DENORMALIZATIONcases come out ofCascadingCompressor. They existed because a scheme producing aScalarFnArrayhad no compressible children to be sized against.What APIs are changed? Are there any user-facing changes?
scalar_fns::l2_denorm::*encodings::l2_denorm::*L2Denorm::try_new_array(n, s, ctx)L2Denorm::try_new(n, s, ctx)unsafe L2Denorm::new_array_unchecked(n, s)L2Denorm::try_new_trusted(n, s)L2Denorm::new()session.scalar_fns().register(L2Denorm)session.arrays().register(L2Denorm), unconditionalScalarFnArrayPlugin::new(L2Denorm)VX_SCALAR_FN_ARRAY_TENSOR_PLUGINno longer gatesL2Denorm, since the compressor can emit it and readers have to be able to open those files. It still gates the other three tensor plugins. The array ID and theL2DenormMetadatamessage are unchanged, so the on-disk bytes match what the plugin wrote.L2DenormSchemestays out ofALL_SCHEMES, because wiring it in changes default compression for every tensor column and wants its own numbers.