layer_numerics: make stage observations producer-ordered - #301
Open
oyazdanb wants to merge 2 commits into
Open
Conversation
Track batches across TorchRec stages and add optional post-step bracketing so timing-sensitive corruption can be localized without serializing the pipeline. Expand coverage and handoff guidance for trustworthy customer evidence. Co-authored-by: Cursor <cursoragent@cursor.com>
Preserve pipeline audit counters after weak-registry cleanup and fail closed when event queries, compute-token resolution, or reset boundaries make timing evidence ambiguous. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the layer_numerics NaN logger’s pipeline-stage “follow” mode to produce timing-safe, producer-ordered stage observations (copy/sparse via TorchRec producer streams + side streams; forward entry ordered on compute stream), adds an optional post-step (C+) observation path, and hardens draining/shutdown behavior with expanded documentation and tests.
Changes:
- Reworked pipeline tracking to avoid mutating customer batch objects by introducing external per-pipeline batch tokens and richer stage evidence auditing.
- Implemented deferred, non-blocking draining for incomplete stage observations, plus bounded deferral and stricter “skip + audit” behavior when evidence can’t be trusted.
- Expanded docs/recipes and added extensive CPU/GPU/runtime test coverage for v6 pipeline wrapper behavior, stage evidence validity, and post-step observations.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/aorta/instrumentation/layer_numerics/instrument_nan_logger.py |
Major v6 refactor: producer-ordered stage reads, external batch tokens, deferred draining, post-step observations, and expanded summary audit fields. |
src/aorta/instrumentation/layer_numerics/README.md |
Updated behavior description and added Buck .par integration guidance + customer self-check jq snippet. |
docs/layer-numerics.md |
Updated spec schema/docs for stage_reads + new post_step, added operational guidance and expanded output/audit semantics. |
recipes/README.md |
Updated recipe example NANLOG_SPEC to the new stage-read schema. |
tests/instrumentation/test_layer_numerics_spec.py |
Added spec validation/rollback tests for post_step and stale flat-var clearing. |
tests/instrumentation/test_layer_numerics_smoke_gpu.py |
Updated smoke scenarios to new follow schema and added assertions for stage-read audit fields. |
tests/instrumentation/test_layer_numerics_runtime.py |
Added extensive runtime tests covering wrapper signatures, token lifecycle, evidence invalidation, deferred drain behavior, and post-step semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+2726
to
+2733
| def _checkpoint( | ||
| batch, | ||
| phase: str, | ||
| *, | ||
| token=None, | ||
| observer=None, | ||
| source_stream=None, | ||
| source_kind: str = "unknown", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan
PYTHONPATH=src conda run -n ort_312 python -m pytest tests/instrumentation/test_layer_numerics.py tests/instrumentation/test_layer_numerics_docs.py tests/instrumentation/test_layer_numerics_spec.py tests/instrumentation/test_layer_numerics_runtime.py tests/instrumentation/test_layer_numerics_smoke_gpu.py -q(168 passed, 9 CUDA/Docker skips)python -m py_compilefor the logger and modified testsgit diff --checkpipeline_observer_count=1andpipeline_ticks=20in the emitted summary