Skip to content

Add new features, make training parameters configurable - #2

Merged
alefisico merged 33 commits into
mainfrom
n_jets
Oct 22, 2026
Merged

alefisico merged 33 commits into
mainfrom
n_jets

Conversation

@aniketkhanal

Copy link
Copy Markdown
Collaborator

This pull request adds the following major features to the network:

  1. Training recipe becomes dynamic: user can now specify no. of folds, when ghost batch size changes, finetuning schedule, etc. Was previously hardcoded

  2. No. of folds is no longer read from the input file (folds are now separated before training starts)

  3. 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

  4. 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

@alefisico
alefisico requested review from alefisico and a balanced review from Copilot October 22, 2026 16:13
@alefisico
alefisico merged commit 9ce6ac2 into main Oct 22, 2026
6 checks passed

Copilot AI 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.

🟡 Changes recommended

Unresolved runtime failures, input-handling regressions and silently incorrect feature or fold behavior need correction before approval.

8 open issues
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 thread src/corenet/data/folds.py
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 thread src/corenet/data/h5.py
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
Comment thread src/corenet/train.py
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))
Comment thread src/corenet/data/h5.py
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}
Comment thread src/corenet/data/h5.py
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
Comment thread src/corenet/train.py
if epoch == args.freeze_epoch:
n_trainable = freeze_heads(model)
if args.finetune_layers:
n_trainable = freeze_heads(model, args.finetune_layers)
Comment thread src/corenet/train.py
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):
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.

3 participants