Repository navigation
D-TRACT-SHAPE-1: cold shape folding and ON × WHEN × DO admission of the shape ops - #1853
Merged
Merged
Conversation
… registrations Classify every value by what it depends on (constant, known input shape, symbolic shape, data) and fold, at resolution, every node whose result is invariant under the source and the resolved input facts, through the node's own registered WHEN and DO. Symbolic and data-dependent nodes stay dynamic; a run whose inputs differ from the resolved facts is refused. A Tract fact is admitted for a source value only from the outlet that is the value's source producer and only if one outlet carries the label; a matching label alone is no longer authority. Tract's TDim (its type for shape values) is read as int64. A Tract panic during analyse or typing is a frontend refusal instead of a crash. Registry v2 adds Shape, Gather (int64 data), Unsqueeze, Concat, Reshape, Cast i64->i64 and Erf (ndarray vserf); scalar-Y Where uses blend_i32_scalar. Attribute rules can admit an integer parameter (an axis) without fixing its value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMjKnig6MXTd41Lf2v
…y skip is not a guard Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMjKnig6MXTd41Lf2v
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMjKnig6MXTd41Lf2v
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
AdaWorldAPI
marked this pull request as ready for review
October 30, 2026 10:12
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Same data (verified equal after parsing); the file drops from about 13,000 lines to 680. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMMjKnig6MXTd41Lf2v
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.
Lab probe follow-up to #1850–#1852 in
crates/tract-harvest-probe. Plan:.claude/plans/d-tract-harvest-0-native-algebra-bridge-v1.md§0.2.What changes
Classification.
fold::classifyputs every value in one of four classes:Const(depends only on source constants),Shape(constants plus fully known input shapes),Symbolic(a shape with a symbolic dimension) orData. On Jina pinned to[1,10], the five requested ops break down as follows.Unpinned, Tract's
analysefails at/Flatten, so the Symbolic class is tested on theshape_symfixture instead.Folding. At resolution, a node runs once only if it is Const or Shape and either all its inputs are known constants, or it is
Shapeover a fully known shape. It runs through its own registration: WHEN must be TRUE, then the same DO a run would call. Folded outputs become plan constants that later guards read. A run whose inputs differ from the resolved facts is refused before any step runs. Symbolic and data-dependent nodes stay dynamic.Fact identity (
FactSources::merged). A Tract fact is now accepted for a source value only when exactly one outlet carries that value's label and that outlet is the value's source producer under Tract's naming rule (dr3::admit,dr3::source_producers). A matching label alone is no longer enough.Two smaller frontend changes:
TDim(what Tract'sShapeemits) is read as int64, the ONNX type.Gatherindex makes Tract index out of bounds incore/src/ops/array/gather.rs:75.Registry v2 (lab classids only; no production ClassId minted). All registrations keep the positional arguments and the ON/DO relations.
selectndarray::concatenatendarray::hpc::vml::vserf(Bounded, ≤ 2 ULP)Scalar-Y
Wherenow callsndarray::simd::blend_i32_scalarwith no new kernel.AttrRule.value: Nonelets an integer attribute (an axis) be a DO parameter.Coverage census (Jina, pinned [1,10])
[WHEN-true, WHEN-not-true, unregistered]:
4,440 nodes fold in 7.3 ms (facts take 221 ms). 1,972 folded values are still read by nodes that don't fold (about 20 KB).
Per op:
Every registered shape-class node that doesn't fold is blocked upstream, never by its own WHEN. The unregistered shape-class nodes are int64 arithmetic: Mul 115, ConstantOfShape 59, Equal 58, Where 58, Div 56, Range 4, Expand 2 and a few singletons.
Measured
ORT 1.29.0,
ORT_DISABLE_ALL, frozen infixtures/tiny/ort.json; AVX-512 host,target-cpu=native.shape_foldmatches ORT bit for bit. Erf is within 2 ULP of ORT inside the graph. On the 4,115-point Erf sweep (dense [-6,6] plus signed zeros, infinities, NaN and subnormals) it is at most 2 ULP from both f64erfrounded to f32 and ORT; the special values are exact. The earlier fixtures are unchanged.shape_foldtile+fold+resolve 12.4 µs (2 steps, 4 folded). Jina slice 20 µs (9 steps, 4 folded Constants).shape_fold: 1.7 µs, 37 allocations.vserfalone takes 7.9 µs.Tests and disable runs
40 tests pass with
--include-ignored(Jina fixtures present). Each disable run below turns its named test red:endignoredOne check is not load-bearing and the code says so: the fold's dependency-class skip, because a Symbolic or Data node never has all its inputs known. Re-pinned:
full_graph_facts_and_coverage, the RMSNorm slice (now 9 steps + 4 folded), andunregistered_op_is_refused(nowAcosh).Decisions needed
vserfis about 4× slower than Tract'serfon this host, which is worth raising with the ndarray session.ConstantOfShapeandExpandmap onto ndarrayfrom_elem/broadcastand are not registered here.Multi-tile orchestration and full Jina MatMul execution remain separate gates.
Generated by Claude Code