Skip to content

kumo-pytorch: keep batch.inputs declaration order through Artifact save/load - #408

Open
lambyqq wants to merge 1 commit into
mainfrom
keep-input-order
Open

lambyqq wants to merge 1 commit into
mainfrom
keep-input-order

Conversation

@lambyqq

@lambyqq lambyqq commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Artifact.save wrote contract.json with sort_keys=True, so after Artifact.load batch.inputs came back in alphabetical order instead of declaration order. Models that read inputs by position (torch.cat(list(batch.inputs.values())), zipping a ModuleList) silently received the wrong inputs. Fingerprints and == did not notice, because the fingerprint hashes its own sorted copy.

DataLoaderSpec.to_json now keeps declaration order. Fingerprints are unchanged. Artifacts saved earlier have sorted keys on disk and load in that stored order.

Tracks CONTRACT-40 (rdl-platform#157).

Test plan

  • New test_saved_artifact_keeps_input_declaration_order: declares inputs z_input, a_input, m_input, saves and loads, and asserts declaration order on the loaded contract, a batch-inference batch, and ServingAssembler.assemble. It fails before the change and passes after; it also checks the fingerprint is unchanged.
  • test_contract_serialization.py and test_api_reference.py pass. docs/api/lifecycle.md is regenerated from the updated docstring.
  • The full non-e2e suite was not run to green locally: diskgraph cannot be built on this machine, and the same 232 tests fail with and without this change.

🤖 Generated with Claude Code

…ve/load

DataLoaderSpec.to_json sorted every key, so a loaded artifact reordered
batch.inputs alphabetically while fingerprints (which hash a sorted copy)
and equality did not notice. Positional consumers got the wrong inputs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@copy-pr-bot

copy-pr-bot Bot commented Nov 19, 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 deployed to gha-kumo-workflow-tests November 19, 2026 01:47 — with GitHub Actions Active
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

DataLoaderSpec.to_json now preserves declaration order instead of sorting JSON object keys. The documentation distinguishes this behavior from the key-sorted copy used by fingerprint. A new test checks that the declared input order and fingerprint persist after saving and reloading an artifact, and that the input order appears in inference batches and serving output.

Merge Risk: Minimal · up to 5a820

Saved contracts now keep inputs in the order they were declared, so code that relies on input position gets the right order after reloading an artifact. Fingerprints and existing artifacts are unaffected. No concrete merge risk was found; the PR change-table check still needs updating.

Security architecture risk: Minimal · up to 5a820

The change preserves declared model-input order while keeping identity hashing and file-integrity checks unchanged. No introduced security or failure-containment risk was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed flow carries caller-authored declaration order into persisted contract text and the reconstructed contract. The inspected change does not add a caller, filesystem destination, credential, or execution capability to that flow.

Trust Boundaries and Controls

  • observed — File digests detect inconsistent saved contents, not an authenticated publisher; the save contract explicitly states that they are not signatures. Load retains digest verification before contract decoding, and decoding rejects unknown specification types. These controls and their limits predate the PR.
Pre-merge checks: Passed 2 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Change Map Design Review Inconclusive The check reviews the PR conversation comment that begins with <!-- kumo-pr-change-map -->. That comment is not in the supplied context. The checkout has no copy of it. The PR description does not l… To complete this check, provide the current PR conversation comment that starts with <!-- kumo-pr-change-map -->. Also link it from the PR description, as docs/development/review.md requires. Then re-run the check. The Change map should…
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. I ran git diff --name-status refs/coderabbit/pre-merge-check/base refs/coderabbit/pre-merge-check/head for PR NVIDIA/kumo-engine#…
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 PR changes three files: docs/api/lifecycle.md, `src/k…
Full details: Pr Size

Explanation

The PR size check fails only when the changed-file count exceeds 40. I ran git diff --name-status refs/coderabbit/pre-merge-check/base refs/coderabbit/pre-merge-check/head for PR #408 (head branch keep-input-order, base main). It reports 3 modified files: 1. packages/experimental/kumo-pytorch/docs/api/lifecycle.md 2. packages/experimental/kumo-pytorch/src/kumo/pytorch/spec.py 3. packages/experimental/kumo-pytorch/tests/test_contract_serialization.py The count of 3 does not exceed 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. The PR changes three files: docs/api/lifecycle.md, src/kumo/pytorch/spec.py, and tests/test_contract_serialization.py. I scanned every added and removed line in the diff for URLs, git or package source locations, and hosting domains. None matched. The added lines contain only code, a docstring, a doc sentence, and a test. The PR description mentions rdl-platform#157 and CONTRACT-40, but those are tracker references in the PR text, not code or docs that the change depends on, and the check does not cover them. No external resource reference is added or modified, so the check passes.

Full details: Change Map Design Review

Explanation

The check reviews the PR conversation comment that begins with &lt;!-- kumo-pr-change-map --&gt;. That comment is not in the supplied context. The checkout has no copy of it. The PR description does not link to it. The review threads list is empty. Without the Change map, the check cannot assess whether each change is necessary, whether the abstraction layer is correct, or whether the stated failure, inspected behavior, verification, and stopping condition are present. The code change is small. In packages/experimental/kumo-pytorch/src/kumo/pytorch/spec.py, DataLoaderSpec.to_json drops sort_keys=True and keeps allow_nan=False. The docstring and docs/api/lifecycle.md are updated to match. The diff touches three files: spec.py, lifecycle.md, and test_contract_serialization.py. The PR description states the failure mode: positional consumers of batch.inputs received inputs in alphabetical order after Artifact.load. The description also states that artifacts saved before the change keep sorted keys on disk. The fix does not repair those artifacts. The description states this limit. It is not a defect in the table. Observations on the code, not on the table: - fingerprint still hashes a key-sorted copy. The description says this keeps fingerprints unchanged. This is consistent with the diff, but the test that checks it was not run to green. - The full non-e2e suite was not run. The author reports 232 failures that also occur without the change. No design defect is proven from the available evidence.

Resolution

To complete this check, provide the current PR conversation comment that starts with &lt;!-- kumo-pr-change-map --&gt;. Also link it from the PR description, as docs/development/review.md requires. Then re-run the check. The Change map should state, for each changed file or symbol: 1. The observed failure or release requirement, with the reproduction or issue reference (CONTRACT-40 or rdl-platform#157). 2. The existing behavior that was inspected, including the effect of sort_keys on Artifact.save and Artifact.load. 3. Why this change is the smallest sufficient change at the DataLoaderSpec.to_json layer. 4. The focused verification, including the test test_saved_artifact_keeps_input_declaration_order and the fingerprint check. 5. The stopping condition, including the behavior for artifacts saved before this change. Also state that the full non-e2e suite was not run to green. Keep any optional refinements in a separate section.

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
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d8aaf2b and 5a820ca.

Files selected for processing: 3

  • packages/experimental/kumo-pytorch/docs/api/lifecycle.md
  • packages/experimental/kumo-pytorch/src/kumo/pytorch/spec.py
  • packages/experimental/kumo-pytorch/tests/test_contract_serialization.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.

This branch was successfully deployed

1 active deployment
gha-kumo-workflow-tests — 5a820ca7 Deployed Nov 19, 2026 by lambyqq via import #2667
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