Add train_stream verb for streaming training on live data sources#987
Draft
drewoldag wants to merge 3 commits into
Draft
Add train_stream verb for streaming training on live data sources#987drewoldag wants to merge 3 commits into
drewoldag wants to merge 3 commits into
Conversation
Introduce a `train_stream` verb, the training counterpart to the recently
merged `infer_stream`. It loads a model once and trains on batches from an
open-ended IterableDataset (e.g. KafkaStreamDataset) through a context-manager
session object, mirroring the InferStream pattern.
Because a live stream has no epochs, length, or train/validate/test splits, the
verb bypasses the Ignite create_trainer / max_epochs path and drives a per-batch
loop directly, reusing create_process_func("train_batch", ...) — the model's
self-contained train_batch already runs the full optimizer step.
Highlights:
- TrainStream verb + TrainStreamSession (iterable and manual train_batch/process
modes); run_cli raises NotImplementedError (programmatic API only).
- Weights persisted periodically (save_weights_every) and on close; close()
returns the trained model.
- Full MLflow + TensorBoard logging: a session-spanning MLflow run started in
run() and ended in close(), per-batch loss logged to both back-ends.
- Ragged/partial batches (streaming timeout flushes) are trained as-is, with a
defensive empty-batch skip and an optional min_batch_size guard.
- New [train_stream] config section; verb auto-exposed via @hyrax_verb.
Adds tests/hyrax/test_train_stream.py and specs/train_stream.spec.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vhimu4YPAyMBPj3dPzEmp4
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #987 +/- ##
==========================================
+ Coverage 65.69% 66.23% +0.54%
==========================================
Files 85 86 +1
Lines 8170 8373 +203
==========================================
+ Hits 5367 5546 +179
- Misses 2803 2827 +24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
Note for Drew for later to run the hyrax dataset producer to emit HSC images: |
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.
Change Description
Adds a new
train_streamverb that enables training models on open-ended streaming data sources (e.g., Kafka topics) using a context-manager session pattern. This mirrors the existinginfer_streamverb but for training workflows.Solution Description
New Components
TrainStreamverb (src/hyrax/verbs/train_stream.py):TrainStreamSessionfor on-demand batch training[data_request.train_stream]with a streaming dataset; the session is iterable and yields(batch, metrics)pairssample_batchand feed batches viasession.train_batch(batch)create_process_func("train_batch", ...)for the per-batch training step,setup_model/setup_model_from_samplefor model initialization, and MLflow + TensorBoard loggingTrainStreamSessioncontext manager:min_batch_size(guards against size-1 batches breaking BatchNorm in user models)save_weights_everyis set)close()Configuration
Added
[train_stream]section tohyrax_default_config.toml:model_weights_file: warm-start weights path (default:false= train from scratch)weights_filename: checkpoint filename (default:"example_model.pth")save_weights_every: checkpoint interval in batches (default:false= only on close)experiment_name: MLflow experiment (default:"notebook")run_name: MLflow run name (default:false= use results-dir name)min_batch_size: skip batches smaller than this (default:false= train all)Design Rationale
create_trainer/trainer.run(..., max_epochs=...)pathmin_batch_sizeguardinfer_streampattern; no shared-base refactor to avoid over-engineeringTesting
Added comprehensive test suite (
tests/hyrax/test_train_stream.py):KafkaStreamDataset(usingFakeConsumerstand-in)process_functo verify empty/small-batch skippingclose()and error handlingNotImplementedError(programmatic API only)Code Quality
https://claude.ai/code/session_01Vhimu4YPAyMBPj3dPzEmp4