fix(hpo): sign-safe penalties, head_layer_size_length handling, honor random_state - #431
Open
ChrisW09 wants to merge 2 commits into
Open
fix(hpo): sign-safe penalties, head_layer_size_length handling, honor random_state#431ChrisW09 wants to merge 2 commits into
ChrisW09 wants to merge 2 commits into
Conversation
… random_state
- The crashed-trial penalty best_val_loss*100 rewarded crashes whenever
the best loss was negative (routine for LSS NLL), so gp_minimize could
return a configuration that failed to fit as the best hyperparameters.
It is now best + 100*abs(best) + 1.
- The pruning threshold best*1.5 fell *below* a negative best loss,
pruning every subsequent trial at prune_epoch; now best + 0.5*abs(best).
- The final best-params loop lacked the head_layer_size_length branch the
trial loop has, and 'head_layer_size_length'.startswith('head_layer_size_')
is True: the optimized length was rounded to 0, prepended as a layer
size, and the list was never truncated to that length.
- gp_minimize now uses the estimator's random_state when set instead of a
hardcoded 42.
- on_validation_epoch_end no longer records the pre-training sanity-check
loss, which shifted epoch_val_loss_at() -- the pruning baseline -- by
one epoch.
Fixes #420
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
model._task_model is typed ITaskModel | None, which has no .val_losses. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #420
Problems
best_val_loss * 100. When the best loss is negative — routine for LSS models, whoseval_lossis a mean NLL — that is an extremely good objective, sogp_minimizecould return the crashing configuration asresult.x.best_epoch_val_loss * 1.5sits below a negative best loss, so every subsequent trial exceeded the threshold atprune_epochand was pruned, gutting the search.head_layer_size_lengthcorruptshead_layer_sizes. The trial loop special-cases the key first, but the final apply loop only checkedkey.startswith("head_layer_size_")— which the length key matches. The length (1–5) went throughround_to_nearest_16→ 0, was prepended as a layer size, and the list was never truncated:[0, s1, ..., s5], a config no trial ever evaluated.random_state=42hardcoded).val_losses, shiftingepoch_val_loss_at()— the pruning baseline — by one epoch. Verified: a 2-epoch fit produced 3 entries.Fix
Sign-safe arithmetic for both the penalty and the threshold, an explicit
head_layer_size_lengthbranch plus truncation in the apply loop,random_stateplumbed intogp_minimize, and atrainer.sanity_checkingguard inon_validation_epoch_end.Tests
New
tests/test_hpo_pruning.py: the penalty/threshold expressions stay worse than the incumbent across negative, zero and positive losses; thestartswithcollision andround_to_nearest_16(1..5) == 0are pinned as the reason the length branch is needed; and a fit assertslen(val_losses) == 2after 2 epochs.🤖 Generated with Claude Code