Harden instrumentation-state (Stage 1): self-verifying telemetry completeness + order-independent tests#151
Open
Pendu wants to merge 7 commits into
Open
Conversation
…t-ai#88-class stream lands)
…A-28 order-dependence)
…elemetry streams will be dark
…recording reset
4 tasks
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.
Addresses #141 (Stage 1). Follows up the DataLoader-completeness discussion from #88 / #135 (now merged; this branch is rebased onto current
main). Stage 2 (the negative-control conformance test, unblocked by #146 removing the legacy import-time auto-init) is a separate follow-up.What changed
Additive instrumentation-state hardening. No change to the training path, public API, or wire format (+453 lines, 7 files, all additions):
test_hf_init_enables_dataloader_and_h2d_patchesprovesinit()requests the DataLoader patch; this guard goes one step further and proves the stream actually emits during a realTrainer+TraceMLTrainerCallbackrun, with_traceml_internal:dataloader_nextevents landing in flushed StepTimeBatches (tests/integrations/test_hf_trainer.py). A config flag can't catch a broken patch, a renamed event, or a buffer that never flushes.StreamContract); a parametrized test runs a tiny end-to-end CPU run via the integration's documentedinit()entry point and asserts every declared stream emitted (tests/integrations/test_telemetry_conformance.py). Wires HF now; Lightning skips until it's a test dependency.train()call inon_train_begin; never raises, never touches the per-step hot path (src/traceml_ai/integrations/_capability.py, wired intoTraceMLTrainerCallback).reset_optimizer_timing()plus an autouse conftest teardown that clears the global optimizer-hook handles/flag and restores default trace-recording state (.../hooks/optimizer_hooks.py,tests/conftest.py). Makes the suite order-independent.test_hf_trainer_callback_grad_accum_folds_microbatchesis red on currentmain(run the file standalone: 1 failed, 6 passed; it counts forward/backward auto-timer events but nothing installs the patches before it in file order, and CI doesn't runtests/integrations/, so it's invisible there). Oneinit()call makes it self-initializing. Fittingly, the new capability warning named the cause in the failure log:... these telemetry streams will NOT be captured: backward, dataloader_fetch, forward, h2d.Why
The callback-based HF integration (#88 / #135) originally emitted DataLoader-fetch timing only incidentally, and nothing verified completeness; the gap was caught by maintainer review, not by the system. Separately, a global optimizer-hook flag was never reset, so
wrap_optimizertests passed or failed depending on suite order, and the grad-accum test onmainfails for the same class of reason today. One root cause: ungoverned global instrumentation state. This PR makes telemetry completeness a self-verifying property and the suite order-independent, without touching the training path.How I tested
Each new test was written fails-first / passes-after (TDD).
black/ruffclean on touched files.Runtime impact
Notes: Additive. New tests, a test-only reset hook, and a best-effort warning that fires once per
train()call inon_train_begin(outside the step loop), only when an integration is active but unconfigured.Documentation
Stage 1 is internal hardening; the public
init()+ callback flow is unchanged.Risk checklist
Screenshots or output
The capability warning in action (from the pre-fix grad-accum failure log):