You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(kumo-pytorch): vectorize event-time-delta owner indices - #382
DiskGraphSource._model_field built the owning-anchor index for EventTimeDelta fields with a Python comprehension over every event. It now uses np.repeat over the offset differences. The index, and so the field output, is identical.
Microbenchmark: 128 anchors × 128 events, _model_field called for 4 event components per iteration, median of 50 runs after warmup. Python 3.12 on a CPU-only Linux dev host.
Measured
Before
After
_model_field (4 components)
4.1–4.4 ms
0.95 ms
Owner index construction
0.83 ms
0.012 ms
This is a focused microbenchmark, not an end-to-end throughput claim.
Testing Done
From packages/experimental/kumo-pytorch, with DiskGraph built from this tree: pytest tests/test_time_delta.py tests/test_field_outputs.py tests/test_diskgraph_backend.py — 59 passed, 1 skipped (needs optional torch_geometric).
The benchmark script also asserts equal owner arrays for the old and new code on edge cases (no anchors, empty anchors, nonzero first offset) with int32/int64/uint64 offsets, plus 200 random offset vectors.
ruff check and ruff format --check pass on the changed file.
No new test: the output is unchanged and existing time-delta and field-output tests cover it. Not tested: GPU and end-to-end training. No API, dependency or Rust changes.
EventTimeDelta fields built the per-event anchor index with a Python
comprehension over every event. Build it with np.repeat over the offset
differences instead; the output is identical.
Co-Authored-By: Claude <[email protected]>
Observed issue: building the per-event owning-anchor index in Python dominated _model_field for EventTimeDelta fields (about 0.83 ms of each call in a 128 × 128 event microbenchmark). Existing behavior: one Python loop iteration per event. Smallest sufficient change: build the same index with np.repeat(np.arange(anchors), np.diff(offsets)); the cutoff lookup and delta arithmetic are unchanged. Focused check: existing time-delta, field-output and DiskGraph backend tests, plus an old-versus-new equality check over edge-case and random offsets. Stop point: this one expression; other per-field Python work is out of scope.
_model_field now uses NumPy’s repeat to construct event-owner indices from sequence boundary differences. This replaces the previous per-anchor list comprehension.
Merge Risk: Minimal · up to 26daf
This is an internal performance optimization with equivalent output and no public API change. The existing tests are reported to pass, and no merge-blocking risk was identified. Adding a multi-anchor test would be a worthwhile follow-up.
Security architecture risk: Minimal · up to 26daf
This is a local performance optimization. The inspected change establishes no introduced or worsened risk to security, failure containment, rollback, or ownership guarantees.
Pre-merge checks: 3
Check name
Status
Explanation
Change Map Design Review
Summary: The change map design holds up. The single change is necessary for the measured hot path, sits at the right layer, and preserves behavior for valid inputs. I found no proven defect and no…
Pr Size
The PR size check counts files changed in this pull request. The review-scoped range is authoritative: base refs/coderabbit/pre-merge-check/base (9637e9c) to head refs/coderabbit/pre-merge-check/head…
Public Resource Access
The check applies only to external resource references (URLs, repository locations, package source locations) that this PR adds or modifies. The reviewed range changes one file, `packages/experimental…
Full details: Change Map Design Review
Explanation
Summary: The change map design holds up. The single change is necessary for the measured hot path, sits at the right layer, and preserves behavior for valid inputs. I found no proven defect and no misleading claim that changes the design verdict. Evidence limit: The <!-- kumo-pr-change-map --> comment text was not in the supplied context. I assessed it from the supplied "Comments summary" and the PR description. That summary says the map targets owner-index construction and reports the same benchmark. It also states that cutoff lookup and delta arithmetic are unchanged and that other per-field Python work is out of scope. Code check (diskgraph.py, _model_field, lines 1771–1777): - The diff replaces the per-event list comprehension with np.repeat(np.arange(len(boundaries) - 1), np.diff(boundaries).astype(np.int64)). - For monotonic Arrow list offsets, the old and new owner arrays are equal. Each anchor a repeats b[a+1]-b[a] times in both versions. The first offset does not matter in either version. - Empty offsets gives arange(-1), which is empty. The old range(-1) is also empty, so the two versions agree there. - The explicit int64 cast keeps the pa.array(..., type=int64) output type unchanged. - The change is limited to this expression. The cutoff take, the subtraction, and the division are unchanged. Design assessment: - Necessity: The description gives a measured before-and-after microbenchmark. It also states that the result is not an end-to-end claim, so the observed cost is stated accurately. - Layer: The fix is local to the owner-index expression. It needs no API, schema, or Rust change. - Smallest change: One expression changes. Nothing else in the file is touched. Misleading or omitted behavior (minor, not a defect): - For invalid, non-monotonic offsets, the old code silently produced fewer owners. np.repeat raises ValueError on negative counts. Valid Arrow list offsets are non-decreasing, so this does not affect the normal path. The map does not mention this difference. - np.diff on an unsigned offset array wraps before the int64 cast. This matches the old int(...) behavior, so it is not a regression. Optional refinements (separate from the verdict): - EventTimeDelta fields that share a sequence rebuild the same owner array. Building it once per sequence would remove the repeated work. The map treats this as out of scope, which is a valid choice. Verification: The description reports 59 passing tests, one skipped, plus an old-versus-new array comparison. I did not run these. They are author-reported.
Full details: Pr Size
Explanation
The PR size check counts files changed in this pull request. The review-scoped range is authoritative: base refs/coderabbit/pre-merge-check/base (9637e9c) to head refs/coderabbit/pre-merge-check/head (26daf0f). git diff --name-status over that range lists 1 file, all Modified: packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/diskgraph.py. --shortstat reports 1 file changed, 1 insertion, 5 deletions. The range holds 1 commit, which matches the single commit listed in the PR metadata. The count of 1 does not exceed 40, so the check passes. Line counts are ignored, as the check requires. Prior failure refuted: The prior FAIL counted 141 files by diffing against origin/main at 9c9cba5 and HEAD 26daf0f, which included 13 extra commits. The review-selected base is 9637e9c. Over the authoritative range refs/coderabbit/pre-merge-check/base..head there is 1 commit and 1 changed file (diskgraph.py, 1 insertion, 5 deletions). The prior claim that the PR changes 141 files does not hold for the review range.
Full details: Public Resource Access
Explanation
The check applies only to external resource references (URLs, repository locations, package source locations) that this PR adds or modifies. The reviewed range changes one file, packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/diskgraph.py. The patch is a single hunk (+1/-5) that replaces the owner-index list comprehension in DiskGraphSource._model_field with np.repeat(np.arange(...), np.diff(boundaries).astype(np.int64)). A search of all added lines for http(s)://, git+, github.com, git@, pypi, and file:// found no matches, so the diff adds no external resource reference. The only URL tied to this PR is the change-map link in the PR description (a GitHub PR comment). It is supplementary commentary, not a repository or package location needed to understand, build, test, or use the changed code, and it is not part of the reviewed patch. The changed code is self-contained. No access test was needed, so the result is PASS.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
The supplied end-to-end test uses one anchor, so it cannot detect a row assigned to the wrong anchor. Add a case with different cutoffs and an empty anchor between two anchors with events. Assert the delta for each row.
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Equivalent vectorized owner mapping. Independently verified multiple anchors with different cutoffs and an empty middle history across int32/int64/uint64 offsets; focused suite passed. No correctness blockers found.
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
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.
Summary
DiskGraphSource._model_fieldbuilt the owning-anchor index forEventTimeDeltafields with a Python comprehension over every event. It now usesnp.repeatover the offset differences. The index, and so the field output, is identical.Microbenchmark: 128 anchors × 128 events,
_model_fieldcalled for 4 event components per iteration, median of 50 runs after warmup. Python 3.12 on a CPU-only Linux dev host._model_field(4 components)This is a focused microbenchmark, not an end-to-end throughput claim.
Testing Done
packages/experimental/kumo-pytorch, with DiskGraph built from this tree:pytest tests/test_time_delta.py tests/test_field_outputs.py tests/test_diskgraph_backend.py— 59 passed, 1 skipped (needs optionaltorch_geometric).ruff checkandruff format --checkpass on the changed file.No new test: the output is unchanged and existing time-delta and field-output tests cover it. Not tested: GPU and end-to-end training. No API, dependency or Rust changes.
Change map
File-by-file rationale.
Checklist
🤖 Generated with Claude Code