Skip to content

Reuse typed Arrow anchor IDs during Kumo preparation - #349

Merged
nittin-murthi merged 4 commits into
mainfrom
perf/pytorch-columnar-anchor-keys
Nov 24, 2026
Merged

nittin-murthi merged 4 commits into
mainfrom
perf/pytorch-columnar-anchor-keys

Conversation

@nittin-murthi

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

Copy link
Copy Markdown
Contributor

Summary

DiskGraph-backed anchor preparation currently converts already typed Arrow ID columns to Python scalars, validates each scalar, and rebuilds an Arrow array. This repeats in scalar-value materialization and native anchor binding.

Reuse an integer/string array when its Arrow type exactly matches the declared key type. A shared private helper keeps the existing normalization path for every other input. There is no API change, new cache, or concurrency. Integer bounds, rejected coercions, null handling and unknown-entity checks retain their existing behavior.

Performance

Six sequential, counterbalanced comparisons against main 08577147e832585cc6e6094188ecb81f7bf904ae:

Scope Main median Candidate median Elapsed-time reduction
Whole GraphSAGE fixture job 26.389 s 24.914 s 5.6%
Materialize anchors and fit encoders 8.707 s 7.975 s 8.4%
Prepare inference with fitted state 5.981 s 5.191 s 13.2%

All six whole-job pairs improved; individual reductions were 3.6–7.1%. Phase medians are calculated independently. Fitted-state fingerprints, sample/batch counts, mean training loss, final weights and predictions matched exactly in every pair.

The job builds a fresh index, materializes all anchors and fits input encoders, constructs the model/Adam optimizer, saves the Kumo artifact, trains one full epoch, rematerializes the inference task using the fitted state, runs the full test split, and closes resources. The timer includes preparation and fitting; it excludes Python startup, fixture generation and post-run output hashing.

Environment: macOS ARM64; Python 3.12.14, PyTorch 2.13.0, PyArrow 24.0.0, NumPy 2.5.4, DiskGraph 0.2.0 built from the same main commit. Native and PyTorch intra/inter-op thread settings are 1. The source is the existing e2e.datasets.hm M fixture, generator version 2, seed 0: 50,000 customers, 5,000 articles, 1,246,040 transactions, 700,000 anchors; 400,000 train and 200,000 test examples. The consumer is e2e.flows.hm_gnn.PurchaseGNN, width 64, batch size 512, seed 0, Adam 1e-3.

Common package path Expected benefit
AnchorTable scalar entity features and aggregate targets Avoid Python conversion during scalar-value materialization.
Native anchor binding for entity, event and graph contracts Avoid the same conversion when constructing native seed tables.
Iterating an already materialized task No direct steady-state training improvement; savings are in preparation.

This is CPU synthetic-fixture evidence with a warm filesystem cache and no exclusive CPU allocation. It is not an Arena-model, GPU or full-data result, and does not establish a 5% improvement for long, model-dominated training jobs. The measured improvement is below the later 10% target; this smaller, independently reviewable optimization is intentionally being proposed separately.

Testing Done

From packages/experimental/kumo-pytorch, using the selected compatible native runtime and PYTHONPATH=src:

python -m pytest tests/test_anchor_key_arrays.py tests/test_anchor_tables.py \
  tests/test_native_anchor_handoff.py tests/test_aggregate_materialization.py \
  tests/test_materialized_native_batches.py tests/test_materialized_feature_stats.py \
  tests/conformance/test_dtype_matrix.py -q

272 passed, 0 failed, 2 skipped (Linux /proc mapping accounting). New coverage includes signed/unsigned bounds, nulls, duplicates, Unicode, mismatched integer widths, rejected bool/float/string coercions, overflow, large-string fallback and the existing native null-key exception. Ruff and git diff --check pass.

Change map

File-by-file change map

Checklist

  • No breaking API changes.
  • Documentation review: no public interface or workflow changes.
  • Added focused regression coverage.

@copy-pr-bot

copy-pr-bot Bot commented Nov 15, 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 15, 2026 03:49 — with GitHub Actions Inactive
@nittin-murthi

nittin-murthi commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Change map

Observed issue: preparation converts already correctly typed anchor ID columns through Python scalar lists at two native boundaries. The requested optimization removes that repeated work while preserving accepted inputs and errors.

File Function / scope What changed Why
packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/parquet_anchors.py _anchor_key_array Add a private helper that returns exact-type integer/string arrays directly and otherwise performs the existing scalar normalization. Arrow already enforces the declared integer/string storage type; retain strict fallback behavior for mismatches and other scalar families.
packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/diskgraph.py DiskGraphSource.materialize_scalar_batches Use the helper before native root-ID lookup. Remove the Python round trip during scalar-feature and aggregate-target preparation.
packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/native_anchors.py NativeAnchors._materialize Use the same helper when binding seed rows. Remove the duplicate round trip from native task preparation with one shared implementation.
packages/experimental/kumo-pytorch/tests/test_anchor_key_arrays.py Typed-array reuse and fallback regression cases Check signed/unsigned bounds, nulls, duplicates, Unicode, integer-width fallback, large strings and refused coercions/overflow. Verify that column reuse preserves values and that mismatched inputs still undergo strict validation.
packages/experimental/kumo-pytorch/tests/test_native_anchor_handoff.py test_invalid_native_anchors_do_not_drop_rows Add null-key coverage with the existing native exception type; keep the unknown-ID and null-cutoff cases. Verify the optimization preserves rejection instead of silently dropping invalid anchors.
packages/experimental/kumo-transaction/src/tfm/data/token_cache/formats.py token_cache_format Document and annotate the columnar registration import. Importing the module registers the format before lookup and the annotation clears the dead-code check.
packages/experimental/kumo-pytorch/tests/test_type_resolution.py Type-resolution checks Construct DiskGraphEngine using its current API in five places. The existing fixture configures isolated scratch storage for each test.

Smallest sufficient change: one helper and its two call sites. Verification: 272 focused tests passed, 2 Linux-only checks skipped; six complete-job pairs preserve fitted state, counts, loss, weights and predictions exactly. The stopping condition is removal of these typed-key conversions while retaining validation behavior; broader dtype conversion optimizations remain separate.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

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

No actionable comments were generated in the recent review.

Walkthrough

DiskGraph and native anchor materialization now use _anchor_key_array to convert entity IDs. The helper preserves matching integer and string Arrow arrays. Otherwise, it normalizes values and constructs an array with the declared type. Tests cover array identity, type conversion, invalid values, and null entity errors. Other changes update DiskGraphEngine test construction and annotate an existing columnar import without changing its behavior.

Merge Risk: Minimal · up to bc4bd

This change speeds up anchor key preparation by reusing correctly typed Arrow arrays, and its validation behavior is meant to stay the same. No merge-blocking risk was found.

Security architecture risk: Minimal · up to bc4bd

The change reuses already-typed entity IDs without changing which graph table is queried or how unknown IDs are rejected. Inputs that do not match the declared type still go through the existing validation path. The reviewed change showed no material increase in security or failure-containment risk.

Retained concerns
No architecture-level concerns identified.

Security review details

Trust Boundaries and Controls

  • observed — The fast path requires exact equality with the declared Arrow type; it does not cast mismatched input. The fallback still rejects invalid integer types and out-of-range values before lookup.

Resilience and Maintainability Implications

  • observed — Native materialization still closes stage writers on exit and invokes task cleanup if construction raises. The added null-key test asserts that this failure leaves no new anchor staging directory.
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 is not in the supplied evidence, and this sandbox has no tool to read PR conversation commen… To complete this check, make the PR conversation comment readable to the reviewer and rerun it. For example, run gh api --paginate --slurp repos/NVIDIA/kumo-engine/issues/349/comments | jq 'add', then select the comment whose body starts …
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. git diff --name-status over the review range (refs/coderabbit/pre-merge-check/base to refs/coderabbit/pre-merge-check/head) lists…
Public Resource Access Passed The check applies only to external resource references (URLs, repository locations, package source locations) that this PR adds or modifies. I listed the 7 changed files in the reviewed range (4 modif…
Full details: Pr Size

Explanation

The PR size check fails only when the changed-file count exceeds 40. git diff --name-status over the review range (refs/coderabbit/pre-merge-check/base to refs/coderabbit/pre-merge-check/head) lists 7 changed files: 6 modified and 1 added (tests/test_anchor_key_arrays.py). git diff --name-only also returns 7. The count is well 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 applies only to external resource references (URLs, repository locations, package source locations) that this PR adds or modifies. I listed the 7 changed files in the reviewed range (4 modified source/test files under kumo-pytorch, 1 added test file, 1 modified kumo-transaction file, and 1 modified test). I then grepped every added line for http(s) URLs, git+/git@ sources, github.com, PyPI/registry, bucket URIs, file:// paths, .git references, and pip install or index-URL flags. No matches were found. The added lines contain only Python imports, a private helper _anchor_key_array, test code, and comments. Its # noqa: F401 change and the import tfm.data.token_cache.columnar line are internal module imports, not external resource references. The PR description links to a PR comment. That text is not part of the repository change, and the link is not needed to understand, build, or test the changed code, so it falls outside this check.

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 is not in the supplied evidence, and this sandbox has no tool to read PR conversation comments. The only related text is the link in the PR description (issuecomment-6888771989) and a reference in docs/development/review.md. I could not read the Change map, so I could not check its necessity claims, abstraction-layer choice, stated failure, stopping condition, or verification scope. Missing evidence cannot establish PASS. I checked the code diff as partial design evidence. It does not establish a defect: - _anchor_key_array (parquet_anchors.py) returns the input array unchanged only when the dtype is an integer or string and the Arrow type matches exactly. Otherwise it runs the original per-value normalize path. - Null handling is unchanged. DType.normalize(None) returns None (dtypes.py:158-159), so the old path also built nulls. The fast path keeps nulls too. The native layer still raises null primary key (diskgraph-index/layout.rs:209; test_native_anchor_handoff.py:472). - Integer bounds are unchanged for the fast path. An exact-type Arrow integer array already fits the declared width. - The string fast path skips the isinstance(str) check. An exact Arrow string column holds only strings, so this is safe. - The formats.py change only adds # noqa: F401 to an intentional side-effect import. It is not a behavior change. Changed-file coverage is complete: 7 files, matching the diff stat.

Resolution

To complete this check, make the PR conversation comment readable to the reviewer and rerun it. For example, run gh api --paginate --slurp repos/NVIDIA/kumo-engine/issues/349/comments | jq 'add', then select the comment whose body starts with &lt;!-- kumo-pr-change-map --&gt;. Evaluate its Change map against this diff: 1. For each row, check that the stated failure or requirement is observed or required, and that the existing behavior was inspected. 2. Check that the change is the smallest sufficient change. Confirm whether the formats.py import annotation and the test_type_resolution.py scratch-path edits belong in this performance PR, or in separate changes. The description says optional refinements are kept separate. 3. Check that the map covers the material behavior: the fast path skips per-value Python normalization, so confirm that string exact-type arrays need no further validation. 4. Check that the map's verification scope matches the focused pytest command and the fixture-based benchmark.

  • 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 52ab019 and bc4bd70.

Files selected for processing: 2

  • packages/experimental/kumo-pytorch/tests/test_type_resolution.py
  • packages/experimental/kumo-transaction/src/tfm/data/token_cache/formats.py

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

Victsm
Victsm previously approved these changes Nov 24, 2026

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

The typed Arrow reuse preserves the strict fallback normalization and native NULL/unknown-ID checks. The 57 focused anchor-key/handoff tests passed. On rebase, retain #442’s int64 warehouse-key coercion alongside this helper.

…-anchor-keys

# Conflicts:
#	packages/experimental/kumo-pytorch/src/kumo/pytorch/engines/parquet_anchors.py
@nittin-murthi
nittin-murthi temporarily deployed to gha-kumo-workflow-tests November 24, 2026 22:04 — with GitHub Actions Inactive
@nittin-murthi
nittin-murthi temporarily deployed to gha-kumo-workflow-tests November 24, 2026 22:09 — with GitHub Actions Inactive

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

Re-reviewed the rebase and retained the strict Arrow-key reuse/normalization behavior. The added managed-scratch test migration and registration-import annotation are narrow CI repairs. Re-approved after focused anchor-key, native-handoff and type-resolution verification.

@nittin-murthi
nittin-murthi merged commit 5673ec9 into main Nov 24, 2026
115 checks passed
@nittin-murthi
nittin-murthi deleted the perf/pytorch-columnar-anchor-keys branch November 24, 2026 22:34

This branch was previously deployed

1 inactive deployment
gha-kumo-workflow-tests — bc4bd70a Deployed Nov 24, 2026 by nittin-murthi via import #3230
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