Skip to content

Measure host memory in the opt-in PyTorch loader - #477

Draft
nittin-murthi wants to merge 3 commits into
codex/pytorch-loader-file-cachefrom
codex/pytorch-loader-host-memory
Draft

nittin-murthi wants to merge 3 commits into
codex/pytorch-loader-file-cachefrom
codex/pytorch-loader-host-memory

Conversation

@nittin-murthi

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

Copy link
Copy Markdown
Contributor

Stacked on #476. Implements C-139–143 from the #353 inventory.

Summary

The existing 33-anchor loader can now measure host memory during ingestion, fresh and reloaded materialization, iterator startup and each batch request. Every repetition runs unprivileged in a dedicated Linux cgroup. Choose kernel for per-interval memory.peak or sampled for memory.current every 10 ms. Both modes sample anonymous memory and keep the raw observations and gaps in the worker results.

Testing Done

From packages/experimental/kumo-pytorch on Linux, set PARENT to an existing delegated cgroup v2 parent with the memory controller enabled. Each loader invocation defaults to three workers.

python -m pytest -q tests/e2e/test_runs.py --cgroup-parent "$PARENT"
python -m tests.e2e.runs loader --host-memory kernel --cgroup-parent "$PARENT" --e2e-dir "$OUT/kernel"
python -m tests.e2e.runs loader --host-memory sampled --cgroup-parent "$PARENT" --e2e-dir "$OUT/sampled"

On Linux 7.0.14, the unprivileged preflight worker saw memory.peak go from 524,288 B to 34,340,864 B after a 32 MiB allocation, then back to 520,192 B after resetting the same descriptor.

At commit 3708ec8e, the validator module recorded 7 passes and 1 skip for the separately opted-in cache validator. Both memory modes passed all three repetitions. Each produced 12 complete epochs, 84 batches and 117 memory intervals, including the three-anchor tail in each epoch. The ordinary loader passed four epochs and returned its original report format. Timeout and SIGTERM cleanup left zero worker cgroups.

Median of three workers’ stage peaks on this host, in MiB. Both modes sampled anonymous charges every 10 ms.

Stage Kernel total Kernel run anonymous Sampled total Sampled run anonymous
Ingestion 276.9 273.0 276.8 273.0
Fresh materialization 281.9 275.9 280.5 276.0
Reloaded materialization 285.4 278.7 283.9 278.7
Fresh batch production 283.4 278.6 283.4 278.6
Reloaded batch production 283.4 278.8 284.1 278.8

Change map

File-by-file change map

@copy-pr-bot

copy-pr-bot Bot commented Nov 22, 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 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Change map

C-139–143 require stage-level host memory measurements on a delegated Linux host. The existing package runner already exercises both fit paths and all 33 anchors. The opt-in modes add cgroup isolation and memory observations to that workload.

File Function / scope What changed Why
packages/experimental/kumo-pytorch/tests/conftest.py pytest_addoption Accept a delegated cgroup parent for the live validators. Ordinary package tests can run on any host.
packages/experimental/kumo-pytorch/tests/e2e/memory_worker.py run_isolated, worker_identity, validate_membership Start an unprivileged worker in its own cgroup, check its process tree and clean up on exit, timeout or interruption. Attribute kernel charges to one worker and its descendants.
packages/experimental/kumo-pytorch/tests/e2e/host_memory.py memory_interval Read the worker’s selected mode at the measured interval. Reset and read the kernel peak on one descriptor or sample total charges. Sample anonymous charges in both modes and save interval evidence. Report stage peaks and expose the sampling gaps that can hide short allocations.
packages/experimental/kumo-pytorch/tests/e2e/loader_timing.py measure_epoch Measure iterator startup and every batch request, including the terminal request. Use the existing batch boundaries and retain delivered batches on failure.
packages/experimental/kumo-pytorch/tests/e2e/runs.py main, _timing_campaign, time_loader Add loader options, launch isolated repetitions and attach fresh and reloaded materialization measurements. Reuse the package campaign, provenance and per-worker reports.
packages/experimental/kumo-pytorch/tests/test_native_anchor_handoff.py test_native_cpu_loader_timing Measure ingestion and check the recorded intervals and epoch maxima on the 33-anchor fixture. Verify memory measurements against actual batch delivery.
packages/experimental/kumo-pytorch/tests/e2e/test_runs.py test_loader_host_memory, test_memory_worker_timeout_removes_only_its_cgroup Check independent parent and child allocations, reject unrelated PIDs and use pytest output capture to verify timeout cleanup. Validate both collectors and isolation on the selected Linux host.

The validation covers delegation, per-interval reset, held allocations, exited children, cleanup and the complete loader workload.

@coderabbitai

coderabbitai Bot commented Nov 22, 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

The timing tools add optional Linux cgroup-v2 host-memory measurement in kernel and sampled modes. The supervisor runs workers in isolated cgroups. Measurement intervals record host and anonymous memory peaks for loader operations. The timing command accepts host-memory and cgroup-parent options and includes measurement metadata in reports. Tests cover allocation measurements, loader interval records, cgroup membership validation, and timeout cleanup.

Sequence Diagram(s)

sequenceDiagram
  participant TimingCLI
  participant TimingCampaign
  participant run_isolated
  participant Worker
  participant memory_interval
  participant cgroup_v2
  TimingCLI->>TimingCampaign: Pass host-memory method and cgroup parent
  TimingCampaign->>run_isolated: Run timing worker
  run_isolated->>cgroup_v2: Create private cgroup
  run_isolated->>Worker: Launch interpreter with cgroup settings
  Worker->>cgroup_v2: Join cgroup and run loader operation
  Worker->>memory_interval: Measure operation interval
  memory_interval->>cgroup_v2: Validate membership and read memory counters
  memory_interval-->>Worker: Record interval peaks
  run_isolated->>cgroup_v2: Clean up worker cgroup
Loading
Merge Risk: Low · up to d6ea0

This adds opt-in host-memory measurement to the test tooling. Two minor issues remain: failure reports can omit a batch that was already returned, and the kernel-mode documentation omits the writable memory.peak prerequisite. Neither affects default runs, so the change is mergeable with owner awareness.

Security architecture risk: Moderate · up to d6ea0

When the benchmark runs with administrator privileges, an unprivileged worker can redirect a file read by the supervisor. If worker cleanup fails, the run can also leave a cgroup behind without a recovery step. These risks are limited to hosts that opt into memory measurement.

Retained concerns

  • Medium · security · observed: In root mode, the supervisor grants the worker group write access to the repetition directory and then follows the worker-controlled result pathname as root. The unchanged read now crosses a privilege boundary: a worker or another principal with write access to that directory can redirect the read to a regular file outside the run. Parsing and aggregation happen after the open, so they do not prevent the unauthorized read or resulting campaign failure. Disclosure through the report is conditional and was not demonstrated.
  • Low · reliability · observed: The new teardown can exit before removing the worker cgroup if a kill operation fails, the child wait times out, or the group remains populated. The campaign stops launching workers for caught cleanup errors but provides no retry or later cleanup owner. A stale group can remain, and surviving processes are possible if termination did not take effect. This is a recovery gap, not evidence of a cgroup escape.
Security review details

Security Blast Radius

  • inferred — The identified privileged read requires a root opt-in run and influence over its worker output. Its direct scope is files readable by that supervisor on the benchmark host; the inspected path does not establish remote or cross-service reachability.

Security Findings and Attack Paths

  • observed — The privileged input is the worker-writable result path. The supervisor's regular-file check follows links, and the subsequent read is not constrained to the repetition directory. The report's numeric aggregation is downstream of that read.

Trust Boundaries and Controls

  • observed — Each worker receives a fresh cgroup and a separate repetition directory. The root-owned campaign directory grants the worker group traversal but not write access; that protects the aggregate report's location, not the integrity of the path used to collect worker results.

Resilience and Maintainability Implications

  • observed — The supervisor defers cancellation during launch, targets its own child cgroup during teardown, and restores signal handlers. The timeout regression test checks descendant cleanup and sibling survival; it does not exercise a failed teardown or recovery.

Hardening Proposals

  • proposed — Collect results without root filesystem authority, or use a supervisor-controlled result channel with bounded reads and schema validation instead of opening a worker-controlled pathname as root.
  • proposed — On teardown failure, record the exact cgroup and cleanup phase, retain the original failure, and assign an explicit recovery owner before treating the campaign as finished.
Pre-merge checks: Passed 2 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Change Map Design Review Warning (previously flagged, unaddressed) Details from the previous assessment are unavailable.
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..head lists 7 changed files: 5 modified (`tes…
Public Resource Access Passed The check applies only to external resource references whose text this PR adds or modifies. I inspected the complete reviewed diff (7 changed files, about 435 insertions) for URLs, git/SSH/package-ind…
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..head lists 7 changed files: 5 modified (tests/conftest.py, tests/e2e/loader_timing.py, tests/e2e/runs.py, tests/e2e/test_runs.py, tests/test_native_anchor_handoff.py) and 2 added (tests/e2e/host_memory.py, tests/e2e/memory_worker.py). No renames or deletions appear. The count is 7, which 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 applies only to external resource references whose text this PR adds or modifies. I inspected the complete reviewed diff (7 changed files, about 435 insertions) for URLs, git/SSH/package-index references, registry or package sources, and documentation links. Neither the case-insensitive pattern search nor the broader search for http, www, kernel.org, docs, .html, .md or "reference" text found any added external reference in the changed files. The changed files are conftest.py, host_memory.py, loader_timing.py, memory_worker.py, runs.py, test_runs.py and test_native_anchor_handoff.py. The only link-like text is the "File-by-file change map" link in the PR description. That is a pointer to a PR comment on the same PR. It is not repository content and is not required to understand, build, or test the changed code, so it falls outside this check. Because the check only fails on a confirmed inaccessible reference, and none was added to the code, the check passes.

Latest assessment: Change Map Design Review

Latest assessment: The latest assessment was inconclusive; the previous failure remains unresolved.

Latest explanation: The check reviews the PR conversation comment that starts with <!-- kumo-pr-change-map -->. That comment is not available to this run. What I checked: - The checkout has no copy of the comment. The marker appears only in the PR template, docs/development/review.md, .coderabbit.yaml, and .github/scripts/pr-change-table.cjs. - No tool in this run reads PR conversation comments. The primary PR record gives only the identity and author. - The PR description links to the comment (issuecomment-7075125627) but does not reproduce its table. - The PR objectives include a distilled "Comments summary" of the change map. It is a paraphrase, not the comment. It does not show whether the comment states the observed failure, the inspected existing behavior, the smallest sufficient change, focused verification, and a stopping condition. - The changed-file inventory matches the seven files named in the summary. The deterministic table check covers file coverage. This check does not assess coverage. Because the table text is missing, I cannot judge whether each change is necessary or belongs at the right layer. I did not assess the design from the summary alone. The previous FAIL has no details. I cannot confirm or refute it from the available evidence. The PR description also cites the "#353 inventory" (C-139–143) as the source of the requirement. That source is not in the checkout, so the observed failure cannot be verified here.

Latest resolution: Provide the full body of the <!-- kumo-pr-change-map --> comment, or make the PR comment readable to this check. Then rerun the check. The rerun should confirm that the comment: 1. States the observed failure or the explicit release requirement. It should name the C-139–143 inventory items or give the equivalent requirement text. 2. Describes the existing behavior that was inspected. 3. Explains why each row is the smallest sufficient change. Optional refinements should appear in a separate section. 4. Names the focused verification for each behavior change. 5. States a stopping condition. If the rerun finds an unsupported row, the author should narrow or remove that row. The table should describe material behavior, including the fallback to subprocess.run when host-memory measurement is off and the cleanup behavior on timeout and interruption.

  • 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 3708ec8 and d6ea033.

Files selected for processing: 3

  • packages/experimental/kumo-pytorch/tests/e2e/loader_timing.py
  • packages/experimental/kumo-pytorch/tests/e2e/runs.py
  • packages/experimental/kumo-pytorch/tests/test_native_anchor_handoff.py

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

Finishing Touches
Fix failing CI checks

  • Commit to this branch
  • Create a new PR

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

@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: 2

packages/experimental/kumo-pytorch/tests/e2e/loader_timing.py: 1

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

Preserve a returned batch if memory finalization fails.

If next(batches, None) returns a batch and memory_interval then raises during its end sample or membership check, the exception handler reports only the previous batches. Lines 301-307 never record the returned batch or its native profile. time_loader then saves this incomplete accounting in results.json.

Track successful retrieval separately from measurement completion. If collection fails after retrieval, retain that batch's accounting before propagating the error. Keep requests that fail before returning a batch uncounted.

packages/experimental/kumo-pytorch/tests/e2e/runs.py: 1

24-24: Minor · Functional Correctness · Quick win

Document the additional kernel-mode requirement.

A delegated memory controller is not sufficient for kernel mode. Linux 6.8 exposes memory.peak as read-only, so host_memory.py fails when it opens that file with "r+b". Newer kernels document reset support through a writable file descriptor. (kernel.org)

State that kernel mode requires resettable memory.peak support. Direct users to sampled mode when that support is unavailable.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e43511c and 3708ec8.

Files selected for processing: 7

  • packages/experimental/kumo-pytorch/tests/conftest.py
  • packages/experimental/kumo-pytorch/tests/e2e/host_memory.py
  • packages/experimental/kumo-pytorch/tests/e2e/loader_timing.py
  • packages/experimental/kumo-pytorch/tests/e2e/memory_worker.py
  • packages/experimental/kumo-pytorch/tests/e2e/runs.py
  • packages/experimental/kumo-pytorch/tests/e2e/test_runs.py
  • packages/experimental/kumo-pytorch/tests/test_native_anchor_handoff.py

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

@nittin-murthi
nittin-murthi removed this pull request from stack #484 November 23, 2026 02:55
@nittin-murthi
nittin-murthi added this pull request to stack #485 November 23, 2026 02:56
nittin-murthi added a commit that referenced this pull request Nov 23, 2026
@nittin-murthi
nittin-murthi temporarily deployed to gha-kumo-workflow-tests November 23, 2026 18:35 — with GitHub Actions Inactive
@nittin-murthi
nittin-murthi marked this pull request as draft November 23, 2026 20:27

This branch was previously deployed

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