Repository navigation
Conversation
alefisico
approved these changes
Oct 22, 2026
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved runtime failures, input-handling regressions and silently incorrect feature or fold behavior need correction before approval.
8 open issues
Use typing.Union for Python 3.9-compatible fold type aliases · New Allow no-fold dataset loading for inference and export · New Wire context-only extra features into the embedding · New Ensure ghost-batch count divides the requested batch size · New Preserve selector precision until ranking is complete · New Resolve next validation fold using actual fold IDs · New Reject fine-tune prefixes matching no trainable parameters · New Reject missing or non-finite validation AUC for early stopping · New
What changed in this PR
This PR extends CoReNet’s training controls and data configuration, adding deterministic event-based folds, fine-tuning options, and optional early stopping.
Changes:
- Adds configurable fine-tuning layers, learning rate and batch size, plus validation-AUC early stopping.
- Records fold rules in checkpoints and reuses them during evaluation and export.
- Generalizes object selectors, separates selection columns from network inputs, and makes the jet-count offset configurable.
| File | Description |
|---|---|
| tests/test_validate.py | Tests selector reporting and fold validation. |
| tests/test_train.py | Tests early stopping, fine-tuning and fold persistence. |
| tests/test_network_bbww.py | Updates input fixtures for selection-only btag. |
| tests/test_h5.py | Tests generic selectors, input channels and fold rules. |
| tests/test_config.py | Tests selector grammar and minimum jet configuration. |
| tests/test_checkpoint.py | Adds checkpoint-format and legacy-loading tests. |
| src/corenet/validate.py | Reports selector inputs and computed fold assignments. |
| src/corenet/train.py | Implements fine-tuning controls, early stopping and fold options. |
| src/corenet/models/network.py | Includes extra features and configurable jet-count offsets. |
| src/corenet/models/config.py | Parses generic selectors and minimum jet counts. |
| src/corenet/export.py | Uses checkpoint fold settings when loading inputs. |
| src/corenet/evaluate.py | Restores fold rules and supports overrides. |
| src/corenet/data/h5.py | Separates selection columns and computes optional event-based folds. |
| src/corenet/data/folds.py | Adds deterministic Squares-based fold assignment. |
| src/corenet/checkpoint.py | Versions checkpoints and translates legacy feature configurations. |
| README.md | Updates configuration, training and inference guidance. |
| pixi.lock | Records the optional Ruff lint dependency. |
| examples/hh4b/hh4b.yaml | Removes selection-only btag from network features. |
| examples/hh4b/hh4b_hyperparameters.yaml | Aligns HH4b feature inputs. |
| examples/bbww/bbww.yaml | Removes selection-only btag from network features. |
| examples/bbww/bbww_hyperparameters.yaml | Aligns bbWW feature inputs. |
| docs/Options.md | Documents fine-tuning, early stopping and fold options. |
| docs/HH4b.md | Updates feature semantics and fold examples. |
| docs/EventInfo.md | Documents generic selectors and minimum jet counts. |
| docs/Dataset.md | Explains selection columns and event-based folds. |
| docs/BBWW.md | Clarifies kinematic inputs and btag selection. |
Review effort: Balanced
Comment on lines
+21
to
+27
| from collections.abc import Iterable | ||
|
|
||
| import numpy as np | ||
|
|
||
| _UINT64_32 = np.uint64(32) | ||
|
|
||
| SeedLike = int | str | Iterable[int | str] |
Comment on lines
+236
to
+240
| if FOLD_KEY not in f: | ||
| raise KeyError( | ||
| f"{self.path.name}: no {FOLD_KEY} dataset; pass --n-folds K (H5Dataset(n_folds=K)) " | ||
| f"to use fold = squares(event) % K from {EVENT_KEY}" | ||
| ) |
Comment on lines
+405
to
+407
| return [ | ||
| f for f in feats if f not in KINEMATIC | ||
| ] # every non-kinematic feature is an input |
| if finetune_batch_size is None: | ||
| return bs, n_gb | ||
| bs = finetune_batch_size | ||
| return bs, min(n_gb, max(1, bs // MIN_GHOST_BATCH_SIZE)) |
| k: np.atleast_2d(group[k][...].astype(np.float32).T).T for k in coll.features | ||
| } | ||
| n, slots = feats[coll.features[0]].shape | ||
| feats = {k: np.atleast_2d(group[k][...].astype(np.float32).T).T for k in columns} |
| f"to use fold = squares(event) % K from {EVENT_KEY}" | ||
| ) | ||
| folds = f[FOLD_KEY][...].astype(np.int64) | ||
| return torch.from_numpy(folds), len(np.unique(folds)), FOLD_RULE_COLUMN |
| if epoch == args.freeze_epoch: | ||
| n_trainable = freeze_heads(model) | ||
| if args.finetune_layers: | ||
| n_trainable = freeze_heads(model, args.finetune_layers) |
Comment on lines
+383
to
+385
| if args.early_stop_patience and len(val_idx): | ||
| auc = entry.get("val_auc") | ||
| if auc is not None and (best_auc is None or auc > best_auc): |
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.


This pull request adds the following major features to the network:
Training recipe becomes dynamic: user can now specify no. of folds, when ghost batch size changes, finetuning schedule, etc. Was previously hardcoded
No. of folds is no longer read from the input file (folds are now separated before training starts)
The no. of jets passed to the network was transformed as n_jets - 3 (hard-coded for HH4b analysis). Now n_jets for the analysis is dynamic and is required in the config file
Adds early stopping feature - the network has an early stopping feature. This feature is off by default but can be used like this for training:
corenet-train ... --early-stop-patience 5