Skip to content

feat(nn): training options and in-memory batching#35

Draft
szvsw wants to merge 4 commits intofeature/create-refactored-surrogate-trainingfrom
cursor/early-stopping-improvement-threshold-d64c
Draft

feat(nn): training options and in-memory batching#35
szvsw wants to merge 4 commits intofeature/create-refactored-surrogate-trainingfrom
cursor/early-stopping-improvement-threshold-d64c

Conversation

@szvsw
Copy link
Copy Markdown
Contributor

@szvsw szvsw commented Mar 29, 2026

Summary

Extends the PyTorch NN surrogate backend with:

  1. Early stopping improvement thresholdearly_stopping_min_delta on NNTrainerConfig. Validation loss must improve by at least this amount versus the previous best to reset patience (default 0.0: any strictly lower val loss counts).

  2. L1 regularizationl1_penalty on NNTrainerConfig. When positive, training loss is MSE plus l1_penalty * sum(|theta|) over trainable parameters. Default 0.0 disables it. Validation and early stopping still use plain MSE.

  3. Max training timemax_training_minutes on NNTrainerConfig (default None). When set, training stops once monotonic elapsed time from the start of the first training batch of the first epoch reaches that many minutes. The current epoch is abandoned without validation if the limit is hit mid-epoch. Uses time.monotonic().

  4. In-memory batching — Training no longer uses DataLoader. Data stays as CPU torch tensors built from NumPy; each epoch uses np.random.permutation(n_samples) and batch indices with drop_last-equivalent batch count (n // batch_size). Validation uses sequential tensor slices with the same drop-last rule and no shuffle.

L2: Unchanged — Adam/SGD weight_decay remains the L2-style term on the optimizer.

Example (YAML)

early_stopping_min_delta: 1.0e-4
l1_penalty: 1.0e-5
max_training_minutes: 120
optimizer:
  optimizer: adam
  weight_decay: 1.0e-4  # L2-style

Testing

  • uv run pytest — 5 passed

Notes

  • Local commits may use -c commit.gpgsign=false when the SSH signing helper hits a GLIBC mismatch in this environment.
Open in Web Open in Cursor 

cursoragent and others added 2 commits March 29, 2026 21:20
…eshold

Require validation loss to improve by at least min_delta vs the previous
best before resetting early stopping patience. Default 0 preserves prior
behavior (any strictly lower val loss counts).

Co-authored-by: Sam Wolk <szvsw@users.noreply.github.com>
Trainer l1_penalty adds lambda * sum(|theta|) to the training MSE loss.
L2-style regularization remains optimizer weight_decay. Validation uses
plain MSE only.

Co-authored-by: Sam Wolk <szvsw@users.noreply.github.com>
@cursor cursor bot changed the title feat(nn): early stopping validation improvement threshold (min_delta) feat(nn): early stopping min-delta and L1 weight penalty Mar 29, 2026
Stop when monotonic elapsed time from the first training batch exceeds
the limit. Partial epochs are skipped without validation; best checkpoint
and post-training flow unchanged.

Co-authored-by: Sam Wolk <szvsw@users.noreply.github.com>
@cursor cursor bot changed the title feat(nn): early stopping min-delta and L1 weight penalty feat(nn): early stopping min-delta, L1 penalty, and max training time Mar 29, 2026
Shuffle each epoch with np.random.permutation over row indices; slice
batches with drop-last semantics. Validation uses sequential tensor slices.
Avoids DataLoader overhead for data already in memory.

Co-authored-by: Sam Wolk <szvsw@users.noreply.github.com>
@cursor cursor bot changed the title feat(nn): early stopping min-delta, L1 penalty, and max training time feat(nn): training options and in-memory batching Mar 30, 2026
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.

2 participants