Skip to content

Support inclusive/exclusive temporal graph sampling - #400

Open
nittin-murthi wants to merge 2 commits into
mainfrom
codex/graph-cutoff-policy
Open

nittin-murthi wants to merge 2 commits into
mainfrom
codex/graph-cutoff-policy

Conversation

@nittin-murthi

@nittin-murthi nittin-murthi commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #335

Summary

Add GraphSample(..., cutoff="exclusive") and the matching build.Hop option. The default remains inclusive. Each traversal filters candidates before fanout using the unchanged request timestamp.

DiskGraph reuses its existing binary search and sampling loop through temporal_most_recent_exclusive; no Python filtering or timestamp adjustment is added. Existing native modes and their serialized variant numbers remain unchanged.

Change map

File-by-file rationale

Testing Done

  • Rebuilt the native extension and ingest binary from this branch (Apple M5 Pro, macOS arm64, Rust 1.99.1, Python 3.12, PyArrow 24).
  • 173 graph tests passed, including 49 new cases covering both engines, default/inclusive/exclusive and mixed policies, fanout 1/10, two hops, multiple requests, unchanged cutoffs and native s/ms/us/ns precision.
  • 75 existing contract, authoring, temporal and API-reference tests passed.
  • Ruff and repository documentation checks passed.
  • Regenerated the H&M saved contract (two inclusive defaults); its notebook drift test passed (pytest tests/test_notebooks.py -m notebook -k hm-recommendation).
  • Four native Rust temporal tests passed (cargo test --release -p diskgraph-engine --lib temporal).
  • Inclusive/exclusive benchmarks completed; results below.

Benchmark

CPU, warm index: 1,082,368 synthetic tree nodes (degree 32), 1,024 requests, nanosecond clocks, and equal sampled-node counts for both policies. Compared main cce65cec with PR 35c1bbf8 using separately built native binaries and the same index. Five fresh processes per variant/thread count, rotating variant order; each process uses two warmups, 20 native calls and five full model-batch iterations. Values are medians of process medians in milliseconds per 1,024 requests. Each cell is native sampling / full model batches (batch size 256, one raw numeric node feature). Preparation, ingestion and validation are excluded. Apple M5 Pro, macOS arm64, Rust 1.99.1, Python 3.12, PyArrow 24; PyTorch uses one thread.

Native threads Hops Fanout Main inclusive PR inclusive PR exclusive
1 1 1 0.268 / 5.060 0.261 / 4.882 0.266 / 4.913
1 1 10 0.649 / 6.998 0.634 / 6.754 0.652 / 7.343
1 2 1 0.437 / 5.459 0.448 / 5.394 0.446 / 5.437
1 2 10 6.476 / 40.546 6.416 / 41.095 6.490 / 41.361
4 1 1 0.227 / 5.139 0.214 / 4.973 0.216 / 5.325
4 1 10 0.552 / 7.159 0.549 / 6.815 0.553 / 7.189
4 2 1 0.354 / 5.359 0.360 / 5.543 0.346 / 5.633
4 2 10 4.588 / 33.562 4.465 / 34.636 4.716 / 34.066

Inclusive graph outputs match main exactly in every trial. Exclusive outputs pass boundary, fanout, edge-count and unchanged-timestamp checks. These are sampling/batch-generation measurements, not training or cold-storage benchmarks.

For two hops/fanout 10 with four threads, process-median model-batch ranges were main-inclusive: 32.11–33.83 ms; pr-inclusive: 30.66–36.16 ms; pr-exclusive: 33.09–35.53 ms. The small median differences overlap these run-to-run ranges.

@copy-pr-bot

copy-pr-bot Bot commented Nov 18, 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.

@nittin-murthi
nittin-murthi temporarily deployed to gha-kumo-workflow-tests November 18, 2026 22:17 — with GitHub Actions Inactive
@nittin-murthi

nittin-murthi commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Change map

Issue #335 requests strictly earlier graph history; existing sampling includes events exactly at the request timestamp. This adds one traversal option and reuses DiskGraph's range seek before fanout. Scope stops at graph sampling; request timestamps, row windows and workloads are unchanged. Validation: 249 Python tests (including the H&M notebook) and four Rust temporal tests passed. Inclusive/exclusive benchmark results are in the PR description.

File Function / scope What changed Why
packages/experimental/kumo-pytorch/src/kumo/pytorch/contract/sample.py GraphSample Add and validate cutoff, defaulting to inclusive. Express strict history per traversal.
packages/experimental/kumo-pytorch/src/kumo/pytorch/build.py Hop.lower Forward the same option. Keep the authoring API consistent.
packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/diskgraph.py _sampling_plan Select the exclusive native mode when requested. Keep filtering in DiskGraph.
packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/in_memory/graph.py _neighbors Choose < or <= before fanout. Match the reference engine's candidate selection.
packages/diskgraph/diskgraph-core/src/sampling.rs SamplingMode Append TemporalMostRecentExclusive. Preserve existing modes and serialized variant numbers.
packages/diskgraph/diskgraph-engine/src/engine.rs sample_segment_edges Share the existing seek/scan with an exclusive boundary predicate. Exclude equal-time neighbors before they consume fanout, without shifting timestamps.
packages/diskgraph/diskgraph-engine/src/tests_unit.rs test_temporal_most_recent_matches_linear_scan Exercise both modes, equal-time anchors and zero fanout. Check indexed selection against a linear oracle.
packages/experimental/kumo-pytorch/tests/test_graph_cutoff.py Cutoff regression cases Check both engines, hops, request ownership, fanout, serialization and native timestamp units. Verify the issue's acceptance criteria.
packages/diskgraph/diskgraph-pybind/README.md Sampling usage Document the native mode. Make strict sampling available to direct DiskGraph callers.
packages/experimental/kumo-pytorch/docs/02-contracts.md Graph neighborhoods Explain the public option. Show users how to select strict history.
packages/experimental/kumo-pytorch/conformance/spec/guarantees/G-GRAPH-001/guarantee.md Fanout/time rule State both boundary policies. Keep the semantic contract accurate.
packages/experimental/kumo-pytorch/docs/api/authoring.md, packages/experimental/kumo-pytorch/docs/api/samples.md Generated API reference Regenerate from signatures/docstrings. Document the new option without manual generated edits.
packages/experimental/kumo-pytorch/examples/hm-recommendation/contract.json Generated H&M example contract Regenerate the two inclusive defaults from the notebook. Keep the saved contract consistent with the API without changing example behavior.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Temporal graph sampling now supports inclusive and exclusive cutoffs. Inclusive remains the default; exclusive admits only events earlier than the request timestamp. Both engines apply the cutoff before fanout and retain the request timestamp across hops. The GraphSample contract rejects unsupported cutoff values. Tests cover both engines and cutoff boundaries.

Sequence Diagram(s)

sequenceDiagram
  participant GraphSample
  participant DiskGraphSource
  participant DiskGraphEngine
  participant InMemoryGraphSampler
  GraphSample->>DiskGraphSource: provide cutoff
  DiskGraphSource->>DiskGraphEngine: select temporal sampling mode
  DiskGraphEngine->>DiskGraphEngine: filter eligible edges before fanout
  GraphSample->>InMemoryGraphSampler: provide cutoff
  InMemoryGraphSampler->>InMemoryGraphSampler: filter eligible neighbors before fanout
Loading
Merge Risk: Low · up to c1f9b

Exclusive cutoffs need the updated DiskGraph native code. The version declaration does not require it, so a stale external install could fail only when exclusive sampling is used. Default inclusive behavior is unchanged. Bump the DiskGraph version and raise the floor before releasing.

Architecture risk: Low · up to c1f9b

The change affects 2 systems.

Changed systems: packages/experimental, packages/diskgraph

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/experimental (library) was modified; 10 changed files map to changed impact.
  • observed — packages/diskgraph (library) was modified; 4 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/diskgraph/diskgraph-core/src/sampling.rs: TemporalMostRecent is now specified as inclusive of the seed timestamp, and TemporalMostRecentExclusive is added for strictly earlier edges, filtered before fanout.
  • observed — Modified behavior in packages/diskgraph/diskgraph-engine/src/engine.rs: The zero-fanout early return now also covers TemporalMostRecentExclusive. The temporal sampling branch handles both most-recent modes and treats an edge as too new when its timestamp is greater than the anchor, or equal when the mode is exclusive.
  • observed — Modified behavior in packages/diskgraph/diskgraph-engine/src/engine.rs: The sorted-edge prefix advance now skips timestamps equal to the anchor in exclusive mode; inclusive mode continues to skip only timestamps greater than the anchor.
  • observed — Modified behavior in packages/diskgraph/diskgraph-engine/src/engine.rs: The per-edge temporal check now uses the shared mode-dependent boundary rule, excluding anchor-equal edges only for TemporalMostRecentExclusive.
Pre-merge checks: Passed 2 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Change Map Design Review Inconclusive The check assesses the PR conversation comment that starts with <!-- kumo-pr-change-map -->. That comment was not supplied to this run. The review-thread context states that no CodeRabbit review thr… Provide the body of the PR conversation comment that starts with <!-- kumo-pr-change-map --> (the comment linked as "File-by-file rationale", issuecomment-6993239949). Then rerun this check. The review must test that comment's Change ma…
Passed Passed checks: 2 passed

Check name Status Explanation
Pr Size Passed The PR size check counts changed files and fails only above 40. I ran git diff --name-status over the review-scoped range (base cce65cec, head c1f9b5d3). It lists 14 changed files: 13 modified (…
Public Resource Access Passed The check covers only external resource references (URLs, repository locations, package source locations) that this PR adds or modifies. Evidence: - The PR range (refs/coderabbit/pre-merge-check/base.…
Full details: Pr Size

Explanation

The PR size check counts changed files and fails only above 40. I ran git diff --name-status over the review-scoped range (base cce65cec, head c1f9b5d3). It lists 14 changed files: 13 modified (M) and 1 added (A, packages/experimental/kumo-pytorch/tests/test_graph_cutoff.py). No renames or deletions appear. 14 is at or below the threshold of 40, so the check passes. Line counts were ignored, as the check requires.

Full details: Public Resource Access

Explanation

The check covers only external resource references (URLs, repository locations, package source locations) that this PR adds or modifies. Evidence: - The PR range (refs/coderabbit/pre-merge-check/base..head) changes 14 files: 13 modified and 1 added (packages/experimental/kumo-pytorch/tests/test_graph_cutoff.py). The diff is 264 lines. - I searched every added line in that diff for URL schemes (http/https), www., Markdown link syntax, HTML href, domain-style hosts, git+/git@ sources, package-index options (pip install, cargo, index-url), and absolute or home-relative local paths. No match was found. - The README and docs additions contain only prose and code examples (mode="temporal_most_recent_exclusive", cutoff="exclusive", signature snippets). They add no links. - The added test file and contract.json contain no external references. - The PR description's links and the Fixes #335 reference are outside the repository diff. They are not changed reference text in the PR's files, so they fall outside the check's scope. Because the PR adds or changes no external resource reference, the check passes. No public-access verification was needed.

Full details: Change Map Design Review

Explanation

The check assesses the PR conversation comment that starts with &lt;!-- kumo-pr-change-map --&gt;. That comment was not supplied to this run. The review-thread context states that no CodeRabbit review threads were returned. The PR description links to a rationale comment (#issuecomment-6993239949), but its body is not in the prepared context. A search of the checkout and review-scoped refs found the marker only in docs/development/review.md, which describes the required comment. The search found no copy of the comment itself. The git diff shows the expected 15 changed files. This confirms file coverage only, and the check rules say file coverage does not establish necessity or correctness. I did not assess the change map's necessity, abstraction layer, stopping condition, or verification claims, because its text is unavailable. I made no finding of a design defect. Code evidence from the PR description and objectives is context only. The author reports that inclusive outputs match main and that exclusive mode filters before fanout. I did not verify those claims in this run.

Resolution

Provide the body of the PR conversation comment that starts with &lt;!-- kumo-pr-change-map --&gt; (the comment linked as "File-by-file rationale", issuecomment-6993239949). Then rerun this check. The review must test that comment's Change map against: - the observed failure or requested release requirement (linked issue #335); - the existing behavior in engine.rs, sampling.rs, in_memory/graph.py, and engines/diskgraph.py; - the smallest sufficient change, including whether the new TemporalMostRecentExclusive native variant is needed or could reuse the existing mode with a parameter; - the focused verification and stopping condition. The map must also cover the material behavior that the summary and PR description do not state. Examples are the Hop and GraphSample default, the DiskGraph serialized variant numbering, and whether the inclusive path in in_memory/graph.py still uses &lt;= for all temporal candidates.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 35c1bbf and c1f9b5d.

Files selected for processing: 1

  • packages/experimental/kumo-pytorch/examples/hm-recommendation/contract.json

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

@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.

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

Other comments: 1

packages/experimental/kumo-pytorch/src/kumo/pytorch/contract/sample.py: 1

721-721: Minor · Data Integrity & Integration · Quick win

Raise the diskgraph floor to a release that contains cutoff="exclusive".

packages/experimental/kumo-pytorch/pyproject.toml:31 allows diskgraph>=0.2.0. This PR adds the TemporalMostRecentExclusive sampling mode to DiskGraph, but it keeps the package version at 0.2.0. A 0.2.0 build from the base revision does not define that mode. With cutoff="exclusive", the adapter sends "temporal_most_recent_exclusive" (engines/diskgraph.py:2060-2064). The derived Deserialize on SamplingMode rejects a value that matches no variant, so such an install can fail when the exclusive option runs. The default cutoff="inclusive" path is not affected.

Bump the DiskGraph package version in this change. Raise the lower bound at pyproject.toml:31 to that version, so that installs without the exclusive mode are excluded.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between cce65ce and 35c1bbf.

Files selected for processing: 13

  • packages/diskgraph/diskgraph-core/src/sampling.rs
  • packages/diskgraph/diskgraph-engine/src/engine.rs
  • packages/diskgraph/diskgraph-engine/src/tests_unit.rs
  • packages/diskgraph/diskgraph-pybind/README.md
  • packages/experimental/kumo-pytorch/conformance/spec/guarantees/G-GRAPH-001/guarantee.md
  • packages/experimental/kumo-pytorch/docs/02-contracts.md
  • packages/experimental/kumo-pytorch/docs/api/authoring.md
  • packages/experimental/kumo-pytorch/docs/api/samples.md
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/build.py
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/contract/sample.py
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/diskgraph.py
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/in_memory/graph.py
  • packages/experimental/kumo-pytorch/tests/test_graph_cutoff.py

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

@Vedaant-J

Copy link
Copy Markdown
Contributor

this would have to propagate to ttgen, sampling, index building all separately, is this really needed @nittin-murthi ? this would need to be tested across benchmarks

This branch was previously deployed

1 inactive deployment
gha-kumo-workflow-tests — c1f9b5d3 Deployed Nov 18, 2026 by nittin-murthi via import #2630
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.

Support explicit inclusive/exclusive cutoff policies for temporal graph sampling [kumo.pytorch]

2 participants