Skip to content

kumo-pytorch: take the in-memory engine out of the serving path - #379

Open
lambyqq wants to merge 1 commit into
mainfrom
serving-without-in-memory
Open

lambyqq wants to merge 1 commit into
mainfrom
serving-without-in-memory

Conversation

@lambyqq

@lambyqq lambyqq commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Design discussion or issue: follow-up to kumo-ai/rdl-platform#148 and #149

Summary

Cleanup: online serving no longer goes through the in-memory engine. DiskGraph is the one engine kumo-pytorch ships for real data; InMemoryEngine is a test and demo tool. Serving was never an engine job (the caller fetches the rows rows_spec lists, and the library turns them into batches with the artifact's fitted state), but ServingAssembler built an InMemoryEngine for its contract checks and assembled through InMemorySource.

  • The row-to-sample code (samples.py, graph.py) moves from engines/in_memory/ to a neutral kumo.pytorch.rows package, with a RowSource that serving uses. The in-memory engine's InMemorySource now subclasses RowSource and adds only what fitting needs (column statistics, text). Dependencies run one way: engines.in_memory imports rows, and serving imports nothing from engines.in_memory.
  • Times in rows are counted by a small Clock. The in-memory engine keeps whole seconds, and serving uses DiskGraph's clock: the finest timestamp unit the schema declares. The DiskGraph config now takes its timestamp_unit from the same Clock.of, so both share one rule.
  • ServingAssembler checks the contract without an engine preflight.
  • Docs, the regenerated API reference and G-SERVING-001 change only where a statement was no longer accurate (serving "uses the in-memory engine"; no test comparing served values with DiskGraph).

Change map: #379 (comment)

Behavior changes for users

None, except one side effect: because serving no longer runs the in-memory engine's checks, a contract with ms/us/ns timestamps is now served in that clock instead of being refused at ServingAssembler construction. The tie rule at a recent fanout limit and graph node order are unchanged.

Testing Done

From packages/experimental/kumo-pytorch, with DiskGraph built from this branch's packages/diskgraph:

  • python -m pytest -q --require-imports: 2426 passed, 5 skipped.
  • python -m conformance --engine all: 707 passed.
  • uvx [email protected] check . and uvx [email protected] format --check .: clean.

New tests in tests/test_serving.py compare ServingAssembler output value for value with DiskGraphEngine batch inference (plan.materialize(..., inference=True)): for the example, bounded-window and event-limit contracts, and for a contract on microsecond and on nanosecond clocks (window, recency and event ages). The existing serving tests against in-memory batch inference are unchanged and pass.

Checklist

  • I listed all the breaking changes introduced by the PR (none; internal modules moved: kumo.pytorch.engines.in_memory.samples/graph are now kumo.pytorch.rows.samples/graph)
  • I made sure to update examples and documentation with my changes (if necessary)
  • I have added and modified unit tests required to cover changes made by this PR.

🤖 Generated with Claude Code

Row-to-sample assembly moves from engines/in_memory to the neutral
kumo.pytorch.rows package (RowSource, Clock); ServingAssembler and the
in-memory engine both use it, and serving imports nothing from
engines.in_memory. Serving no longer runs the in-memory engine's contract
checks, so it now counts time in DiskGraph's clock instead of refusing
sub-second timestamps. Tie and node order are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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.

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

lambyqq commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Change map

Requested change: online serving must not depend on the in-memory engine (follow-up to kumo-ai/rdl-platform#148 and #149). Before: ServingAssembler checked contracts with InMemoryEngine and assembled through InMemorySource. Smallest change: move the shared row assembly to a neutral package and point serving at it. Verified by the package suite, conformance on both engines, and new serving-vs-DiskGraph tests. Stopping condition: serving imports nothing from engines.in_memory, with no behavior change beyond the sub-second side effect.

File Function / scope What changed Why
packages/experimental/kumo-pytorch/src/kumo/pytorch/rows/samples.py RowSampleBuilder (was InMemorySampleBuilder) Moved from engines/in_memory/; times counted by a Clock (seconds by default) Neutral home serving and the in-memory engine share
packages/experimental/kumo-pytorch/src/kumo/pytorch/rows/graph.py RowGraphSampler (was InMemoryGraphSampler) Moved; time filter and recency order via Clock; tie rule unchanged Same
packages/experimental/kumo-pytorch/src/kumo/pytorch/rows/clock.py Clock, Clock.of New: ticks of one unit, stored times rounded up, cutoffs down One clock rule for serving and the DiskGraph config
packages/experimental/kumo-pytorch/src/kumo/pytorch/rows/source.py RowSource New: build, sample_graph, fit_graph_fields over supplied rows The sample source serving uses
packages/experimental/kumo-pytorch/src/kumo/pytorch/rows/__init__.py package Exports Clock, RowSource Package entry
packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/in_memory/source.py InMemorySource Subclasses RowSource; keeps column_stats, column_text In-memory engine imports the neutral code, not the reverse
packages/experimental/kumo-pytorch/src/kumo/pytorch/serving.py ServingAssembler.__init__, assemble, module docstring No engine preflight; assembles through RowSource in DiskGraph's clock Remove the in-memory engine from serving
packages/experimental/kumo-pytorch/src/kumo/pytorch/preparation.py _check, _binding_issues, _source_issues Accept engine=None (public check unchanged) Contract check without an engine
packages/experimental/kumo-pytorch/src/kumo/pytorch/materialization.py _compile_diskgraph_config timestamp_unit from Clock.of(schema) (same values) One shared clock rule
packages/experimental/kumo-pytorch/conformance/registry.py DIV-TIMED-HOP-MEM reason Path updated to rows/samples.py File moved
packages/experimental/kumo-pytorch/conformance/spec/guarantees/G-SERVING-001/guarantee.md Scope Lists the new direct DiskGraph comparisons "No test compares with DiskGraph" was no longer true
packages/experimental/kumo-pytorch/docs/01-concepts.md, packages/experimental/kumo-pytorch/docs/limitations.md serving wording Serving uses the in-memory engine's rules, not the engine; DiskGraph's clock Statements made untrue by the cleanup
packages/experimental/kumo-pytorch/docs/api/artifacts-and-serving.md ServingAssembler Regenerated from the docstring Generated reference
packages/experimental/kumo-pytorch/tests/test_serving.py test_serving_equals_diskgraph_batch_inference, test_sub_second_clocks_are_served_as_diskgraph_batch_inference New comparisons with DiskGraph batch inference Evidence for G-SERVING-001 and the side effect
packages/experimental/kumo-pytorch/tests/serving_fetch.py fetch, _ticks, _windowed, _limited Windows and limits in the schema's clock Fetch reference for sub-second contracts
packages/experimental/kumo-pytorch/tests/conformance/test_sampling_harness.py, packages/experimental/kumo-pytorch/tests/test_batch_api.py, packages/experimental/kumo-pytorch/tests/test_core_api.py, packages/experimental/kumo-pytorch/tests/test_entity_contract.py, packages/experimental/kumo-pytorch/tests/test_event_output_order.py, packages/experimental/kumo-pytorch/tests/test_graph_time_and_reductions.py, packages/experimental/kumo-pytorch/tests/test_in_memory_samples.py, packages/experimental/kumo-pytorch/tests/test_mode_reduction.py, packages/experimental/kumo-pytorch/tests/test_public_contract.py, packages/experimental/kumo-pytorch/tests/test_temporal_declarations.py, packages/experimental/kumo-pytorch/tests/test_typed_sample_values.py imports New module and class names Moved code

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d3b8963 and d3b8963.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized key: "tone_instructions" at "reviews"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Walkthrough

The change adds a schema-based clock for timestamp handling in row sampling, graph sampling, DiskGraph configuration, and serving. It introduces RowSource and routes serving batch assembly through it. Serving tests add comparisons with DiskGraph batch inference, including microsecond and nanosecond timestamp cases. Existing sampling tests now use the row-based builders.

Sequence Diagram(s)

sequenceDiagram
  participant ServingAssembler
  participant Clock
  participant RowSource
  participant RowSampleBuilder
  ServingAssembler->>Clock: Derive clock from contract schema
  ServingAssembler->>RowSource: Create source with supplied rows and clock
  RowSource->>RowSampleBuilder: Build requested samples
  RowSampleBuilder-->>RowSource: Return built samples
  RowSource-->>ServingAssembler: Return batch data
Loading
Merge Risk: Moderate · up to d3b89

With sub-second timestamp contracts, candidate samples are evaluated at a much later time than their parent request and can include future events. Passing the original request time to candidate requests fixes this before merge. Second-based contracts are unaffected.

Security architecture risk: Low · up to d3b89

The time-handling change can give candidate features a later prediction cutoff than requested. Exposure is bounded to data already supplied by the caller, and normal training workflows constrain the affected combination. No broader access or privilege expansion was established.

Retained concerns

  • Low · architecture · inferred: Candidate construction reinterprets normalized ticks as epoch seconds. RowSampleBuilder converts the primary request time into ticks, then passes that integer as the recursive candidate request's as_of_time. For millisecond, microsecond, and nanosecond clocks, the child converts it again. Candidate aggregates with an unbounded historical window can therefore include supplied rows later than the primary prediction time, contrary to CandidateSetSpec's same-time contract. Seconds clocks are unaffected. The new exported row API exposes this combination directly; ordinary serving exposure is constrained by the shipped engines' candidate-set and subsecond-schema restrictions.
Security review details

Security Blast Radius

  • observed — The inspected serving path processes only caller-supplied tables and requests; it does not fetch additional records. Row builders normalize supplied values and maintain instance-local row collections and indexes. The identified cutoff issue changes selection within those supplied rows, not access to another data store.

Trust Boundaries and Controls

  • observed — Removing engine preflight does not remove generic contract resolution and validation. Serving still requires complete fitted state belonging to the contract, validates supplied table and column declarations and types, rejects null or duplicate primary keys, and checks requested entity and candidate presence. These controls do not validate recursive clock-unit inheritance.

Resilience and Maintainability Implications

  • observed — Each assembly call creates its own row source and binds it through a copied plan rather than replacing the reusable plan's source. Batch construction completes inside a finally-protected scope, and the source holds no open resources. These lifecycle properties remain consistent with request-local failure containment.
Pre-merge checks: Passed 2 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Change Map Design Review Warning Summary: The change-map comment (marker <!-- kumo-pr-change-map -->) is not in the checkout, and no tool here reads PR comments. I could not assess its wording. I assessed the proposed design th… 1. In packages/experimental/kumo-pytorch/src/kumo/pytorch/rows/samples.py, change the candidate request (around line 341) from as_of_time=cutoff to as_of_time=request.as_of_time. The child call then converts the original time once, wi…
Passed Passed checks: 2 passed

Check name Status Explanation
Pr Size Passed The PR size check fails only when the changed-file count exceeds 40. The reviewed range (refs/coderabbit/pre-merge-check/base to refs/coderabbit/pre-merge-check/head) changes 27 files. The `git diff -…
Public Resource Access Passed The check covers only external resource references whose text this PR adds or modifies. I searched all added diff lines in the reviewed range (refs/coderabbit/pre-merge-check/base to head) for URLs (h…
Full details: Pr Size

Explanation

The PR size check fails only when the changed-file count exceeds 40. The reviewed range (refs/coderabbit/pre-merge-check/base to refs/coderabbit/pre-merge-check/head) changes 27 files. The git diff --name-status output lists 27 entries: 20 modified (M), 3 added (A), and 2 renamed (R098, R096). The git diff --name-only -M count is also 27. Even without rename detection, the count would be 29, which is still under 40. Line counts were ignored, as the check requires. No failure condition applies.

Full details: Public Resource Access

Explanation

The check covers only external resource references whose text this PR adds or modifies. I searched all added diff lines in the reviewed range (refs/coderabbit/pre-merge-check/base to head) for URLs (http/https, www.), git/SSH sources, package install commands, package index options, and Markdown link syntax. The only match was a Python subscript call (CASES[name]()), which is not an external reference. The changed-file list also contains no dependency manifests, lock files, pyproject/requirements files, CI or Docker files, or package.json. The PR description's uvx [email protected] command is contributor prose outside the diff, so it is not an added code or doc reference. The PR adds or changes no external resource reference, so the check passes.

Full details: Change Map Design Review

Explanation

Summary: The change-map comment (marker &lt;!-- kumo-pr-change-map --&gt;) is not in the checkout, and no tool here reads PR comments. I could not assess its wording. I assessed the proposed design through the code instead. The design has a proven defect in the new non-second clock path, and the PR description says there are no user-visible behavior changes except one. That claim is incomplete. Defect (direct code evidence): - rows/samples.py _build_one computes cutoff = self._clock.cutoff(request.as_of_time). That value is a tick count in the schema's clock unit (ms, us, or ns). - For candidate sets, lines 335–346 call self._build_one(..., SampleRequest(as_of_time=cutoff, ...)). The recursive call passes the tick count, not request.as_of_time. - rows/clock.py _epoch_nanos treats any plain int as epoch seconds (int(value) * 10**9). So a millisecond cutoff of 100000 ticks (for as_of_time=100) becomes a cutoff of 100000 seconds in the child call. The later time admits future events into candidate samples. - Second-based clocks are unaffected, because flooring an integer second count returns the same value. The defect only appears for ms, us, and ns contracts. PR causality: Before this PR, ServingAssembler refused ms, us, and ns contracts. The PR removes that refusal (the description says so), and serving now calls RowSource.build → RowSampleBuilder._build_one. So the candidate path is newly reachable for those contracts. The new tests cover microsecond and nanosecond window, recency, and event-age cases. The review thread on this line reports the same defect. I did not find candidate-set coverage for non-second clocks in the test list named in the PR description. Design and explanation gaps: - The description's "Behavior changes for users: None, except…" section omits that candidate samples use the wrong evaluation time for non-second clocks. - The description says tie handling and node order are unchanged. This is not verified for candidate sets under non-second clocks. - The change design is otherwise reasonable: a shared Clock, a rows package, and one-way dependencies. The problem is the recursive time handoff, which mixes tick counts and epoch seconds. Limit: I did not read the change-map comment. The verdict rests on the code and the PR description. A FAIL here does not confirm or refute the comment's table text.

Resolution

  1. In packages/experimental/kumo-pytorch/src/kumo/pytorch/rows/samples.py, change the candidate request (around line 341) from as_of_time=cutoff to as_of_time=request.as_of_time. The child call then converts the original time once, with the same clock. 2. Add a test with a millisecond (and microsecond and nanosecond) contract that includes a candidate set. Assert that a candidate excludes events after the parent as_of_time. 3. Correct the PR description's "Behavior changes for users" section. State the candidate-time fix and any other non-second clock behavior. 4. Update the change-map comment to describe the candidate evaluation-time behavior and its verification. Then re-run this check on that comment.
Finishing Touches

Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f1cc20a and d3b8963.

Files selected for processing: 27

  • packages/experimental/kumo-pytorch/conformance/registry.py
  • packages/experimental/kumo-pytorch/conformance/spec/guarantees/G-SERVING-001/guarantee.md
  • packages/experimental/kumo-pytorch/docs/01-concepts.md
  • packages/experimental/kumo-pytorch/docs/api/artifacts-and-serving.md
  • packages/experimental/kumo-pytorch/docs/limitations.md
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/in_memory/source.py
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/materialization.py
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/preparation.py
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/rows/__init__.py
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/rows/clock.py
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/rows/graph.py
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/rows/samples.py
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/rows/source.py
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/serving.py
  • packages/experimental/kumo-pytorch/tests/conformance/test_sampling_harness.py
  • packages/experimental/kumo-pytorch/tests/serving_fetch.py
  • packages/experimental/kumo-pytorch/tests/test_batch_api.py
  • packages/experimental/kumo-pytorch/tests/test_core_api.py
  • packages/experimental/kumo-pytorch/tests/test_entity_contract.py
  • packages/experimental/kumo-pytorch/tests/test_event_output_order.py
  • packages/experimental/kumo-pytorch/tests/test_graph_time_and_reductions.py
  • packages/experimental/kumo-pytorch/tests/test_in_memory_samples.py
  • packages/experimental/kumo-pytorch/tests/test_mode_reduction.py
  • packages/experimental/kumo-pytorch/tests/test_public_contract.py
  • packages/experimental/kumo-pytorch/tests/test_serving.py
  • packages/experimental/kumo-pytorch/tests/test_temporal_declarations.py
  • packages/experimental/kumo-pytorch/tests/test_typed_sample_values.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.

target.name: target for target in _normalize_supplied_targets(recipe, request.targets)
}
cutoff = cutoff_to_epoch(request.as_of_time)
cutoff = self._clock.cutoff(request.as_of_time)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Major · Functional Correctness · Quick win

Preserve the original request time when building candidates.

With a millisecond clock, as_of_time=100 becomes cutoff=100000. Line 341 passes that tick count into a candidate's SampleRequest.as_of_time. The recursive call converts it as epoch seconds and produces cutoff=100000000.

Candidate samples therefore use a later evaluation time and can include future events. Microsecond and nanosecond clocks have the same defect.

Pass request.as_of_time, not cutoff, to the recursive candidate request. Each candidate will then receive the parent's evaluation time, and second-based behavior will remain unchanged.

This branch was previously deployed

1 inactive deployment
gha-kumo-workflow-tests — d3b8963a Deployed Nov 17, 2026 by lambyqq via import #2529
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.

1 participant