Skip to content

perf(kumo-pytorch): vectorize event-time-delta owner indices - #382

Merged
Vedaant-J merged 1 commit into
mainfrom
perf/event-time-delta-owners
Nov 18, 2026
Merged

Vedaant-J merged 1 commit into
mainfrom
perf/event-time-delta-owners

Conversation

@Vedaant-J

@Vedaant-J Vedaant-J commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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.

Change map

File-by-file rationale.

Checklist

  • I listed all the breaking changes introduced by the PR (none)
  • I made sure to update examples and documentation with my changes (if necessary) (not needed)
  • I have added and modified unit tests required to cover changes made by this PR (existing coverage)

🤖 Generated with Claude Code

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]>
@Vedaant-J

Copy link
Copy Markdown
Contributor Author

Change map

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.

File Function / scope What changed Why
packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/diskgraph.py DiskGraphSource._model_field (EventTimeDelta branch) Build the owner index with np.repeat over offset differences instead of a per-event comprehension. Same int64 index without a Python loop per event; _model_field drops from about 4.1–4.4 ms to 0.95 ms in the microbenchmark.

@copy-pr-bot

copy-pr-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@Vedaant-J
Vedaant-J temporarily deployed to gha-kumo-workflow-tests November 17, 2026 23:33 — with GitHub Actions Inactive
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

_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: Passed 3

Check name Status Explanation
Change Map Design Review Passed 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 Passed 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 Passed 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 &lt;!-- kumo-pr-change-map --&gt; 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

@Vedaant-J
Vedaant-J marked this pull request as ready for review November 18, 2026 00:59

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick comments: 1

packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/diskgraph.py: 1

1774-1774: Trivial · Maintainability & Code Quality · Quick win

Add multi-anchor owner coverage.

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.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9637e9c and 26daf0f.

Files selected for processing: 1

  • packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/diskgraph.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 9 remain after this review.

@Victsm Victsm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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.

@Vedaant-J
Vedaant-J merged commit cce65ce into main Nov 18, 2026
121 checks passed
@Vedaant-J
Vedaant-J deleted the perf/event-time-delta-owners branch November 18, 2026 19:08

This branch was previously deployed

1 inactive deployment
gha-kumo-workflow-tests — 26daf0f2 Deployed Nov 17, 2026 by Vedaant-J via import #2538
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants