GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Optuna integration for hyperparameter optimization by forklady42 · Pull Request #84 · Quantum-Accelerators/electrai

Conversation

@forklady42

@forklady42 forklady42 commented Feb 18, 2026

Copy link
Copy Markdown
Collaborator

Optuna setup for initial coarse hyperparameter search. WandB runs are under betsy-mp-hpo-tier1.

Best trial over 15 epochs:

=== Best Trial ===
Trial number: 71
Value (val_loss): 0.033743

Best hyperparameters:
  n_channels: 32
  n_residual_blocks: 1
  kernel_size: 5
  lr: 0.003580430023049488

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hanaol reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@forklady42

forklady42 commented Feb 18, 2026

Copy link
Copy Markdown
Collaborator Author

@claude review this PR

claude[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@claude

claude Bot commented Feb 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Claude finished @forklady42's task in 2m 4s —— View job


PR Review: Optuna Integration for Hyperparameter Optimization

Tasks:

  • Gather context and read changed files
  • Review hpo.py entrypoint
  • Review YAML config files
  • Review pyproject.toml changes
  • Post comprehensive review feedback

Overall this is a solid and well-structured HPO integration. The design choices (ddp_spawn over ddp, per-trial W&B runs, optional dependency group) are all sensible. A few issues worth addressing before merge:

Bugs / Correctness

val_loss metric name ambiguity

lightning.py logs val_loss with on_step=True, on_epoch=True:

self.log("val_loss", loss, on_step=True, on_epoch=True, sync_dist=True)

In PyTorch Lightning, this creates both val_loss_step and val_loss_epoch keys during training. The plain val_loss key in callback_metrics should resolve to the epoch aggregate at epoch end, but this depends on Lightning version behavior. The ModelCheckpoint and EarlyStopping monitors, and the final trainer.callback_metrics.get("val_loss") at hpo.py:210, all rely on this. Worth verifying the logged key name matches exactly — if it resolves to val_loss_epoch instead, all three will silently fail (checkpoint won't save, early stopping won't trigger, and val_loss will be None, causing all trials to prune).

Fix this →


Issues

train_workers/val_workers commented out in tier1 config (config_hpo_tier1.yaml:49-50)

  # train_workers: 8
  # val_workers: 2

If RhoRead defaults to 0 workers, data loading will be single-threaded and a significant bottleneck across 50+ trials. The full config has these set — the tier1 config should too unless there's a deliberate reason to drop them.

Fix this →


OOM heuristic ignores batch size (hpo.py:131-140)

The memory check guards against large channel counts but doesn't account for batch_size, which is also in the full search space in config_hpo.yaml. A combination like batch_size=4, depth=4, n_channels=32 could OOM without triggering the bottleneck check. Consider incorporating batch size into the heuristic, or moving the check after batch_size is applied.


No installation hint in docstring (hpo.py:1-8)

optuna and optuna-integration are optional extras. The module-level imports on lines 19 and 26 will raise ImportError if the user runs the script without uv sync --extra hpo. The docstring at the top should note this requirement.

Fix this →


Nits

WandB reinit=True is deprecated (hpo.py:162)

In WandB SDK ≥0.18, reinit=True is deprecated in favor of reinit="finish_previous". Worth updating to avoid future breakage, though it works for now.

Checkpoint accumulation (hpo.py:169-172)

With n_trials=50, this will create 50 subdirectories under hpo_checkpoints/, each with a saved checkpoint. For a coarse search that's probably fine, but in longer runs this could consume significant disk space. Consider adding a note or cleanup step.

gradient_clip_value: 20.0 is a very high upper bound (config_hpo.yaml:51)

The search space includes [1.0, 5.0, 20.0] for gradient clipping. A value of 20.0 is effectively no clipping for most training scenarios and could destabilize learning. Consider capping at 10.0 or using [0.5, 1.0, 5.0].

sqlite:/// storage for parallel trials (config_hpo.yaml:9, config_hpo_tier1.yaml:8)

SQLite is fine for sequential trials but can have contention with n_jobs > 1. If you ever parallelize the outer study (multiple HPO processes), consider switching to PostgreSQL or RDB storage.


All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@forklady42 forklady42 mentioned this pull request Feb 25, 2026
Hyperparameter tuning #88
Open
1 of 5 tasks
@forklady42
forklady42 force-pushed the betsy/resunet-hpo branch from 65514bb to 23a0aa4 Compare February 25, 2026 18:57
@forklady42

forklady42 commented Mar 3, 2026

Copy link
Copy Markdown
Collaborator Author

We're not currently experimenting with batch_size. It causing an OOM isn't currently a concern.

@claude re-review this PR

claude[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@claude

claude Bot commented Mar 3, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Claude finished @forklady42's task in 1m 56s —— View job


PR Re-Review: Optuna Integration for Hyperparameter Optimization

Tasks:

  • Read changed files
  • Re-review with batch_size OOM concern dropped
  • Post updated review

Good progress — the previous round of comments has been well addressed. One new bug surfaced during this pass.

Addressed Since Previous Review

  • val_loss metric ambiguity — Fixed. validation_step now logs with on_step=False, on_epoch=True, so val_loss in callback_metrics unambiguously resolves to the epoch aggregate. All three monitors (ModelCheckpoint, EarlyStopping, callback_metrics.get) will work correctly.
  • train_workers/val_workers commented out — Fixed. Both are now set in config_hpo_tier1.yaml.
  • No installation hint in docstring — Fixed. Docstring now includes the uv sync --extra hpo note.
  • WandB reinit=True deprecated — Fixed. Updated to reinit="finish_previous".
  • OOM heuristic / batch_size — Not a concern; noted and dropped.

Bug: src.electrai imports in HPO files

The parent commit 8c4418a explicitly fixed all from src.electrai. imports and _target_: src.electrai. references across the codebase. The new files in this PR reintroduce the old pattern:

hpo.py:31:

from src.electrai.lightning import LightningGenerator  # broken

All other entrypoints use from electrai.lightning import LightningGenerator. The src. prefix only works if the project root is on sys.path, which isn't guaranteed when the package is installed.

config_hpo.yaml:63,78 and config_hpo_tier1.yaml:44,58:

_target_: src.electrai.dataloader.dataset.RhoRead   # broken
_target_: src.electrai.model.resunet.ResUNet3D       # broken

Compare with the existing config_resunet.yaml which correctly uses:

_target_: electrai.dataloader.dataset.RhoRead
_target_: electrai.model.resunet.ResUNet3D

Fix this →


Remaining Nits

Checkpoint accumulation — With n_trials=50, hpo_checkpoints/ and hpo_tier1_checkpoints/ will each accumulate 50 subdirectories. Fine for a coarse search, but worth a comment or a cleanup note for longer runs.

gradient_clip_value: 20.0 in config_hpo.yaml (config_hpo.yaml:51) — choices: [1.0, 5.0, 20.0] still includes 20.0, which is effectively no clipping. Minor, but could destabilize some trials.

SQLite storage for parallel outer-loop runs — No concern if n_jobs=1 (the default), but worth a note if you ever parallelize across multiple HPO processes.


All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

forklady42 and others added 7 commits March 3, 2026 12:43
@forklady42 @claude
Add Optuna hyperparameter optimization integration
f0386db
Introduces HPO infrastructure for ResUNet model tuning:
- New hpo.py entrypoint with Optuna objective function and pruning
- config_hpo.yaml defining search space for model/training params
- W&B logging for trial tracking with per-trial runs grouped by study
- Memory-safe pruning for high channel count configurations

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@forklady42 @claude
Add Tier 1 coarse HPO config
4174192
Separate config for initial hyperparameter search focusing on critical
parameters: depth, n_channels, n_residual_blocks, kernel_size, and lr.
Fixes Tier 2 params (warmup, weight_decay, etc.) at sensible defaults.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@forklady42 @claude
Fix multi-GPU HPO and ResUNet decoder bug
d661e7d
HPO changes:
- Use ddp_spawn instead of ddp to avoid subprocess re-launching issue
  where each GPU process created different Optuna trials
- Add --devices flag to control GPU count per trial

ResUNet fix:
- Fix decoder channel mismatch when n_residual_blocks > 1
- First decoder block takes 2*ch (concatenated), subsequent take ch

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@forklady42
Tier1 hyperparameter search config
4f2b16e
@forklady42
Address comments
44c949a
@forklady42 @claude
Fix val_loss metric key ambiguity for HPO callbacks
735e50d
With on_step=True and on_epoch=True, Lightning creates val_loss_step
and val_loss_epoch keys, making the plain val_loss key unreliable in
callback_metrics. This caused ModelCheckpoint, EarlyStopping, and the
HPO trial result to silently fail. Setting on_step=False ensures the
metric is logged only as val_loss at epoch end.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@forklady42 @claude
Update src.electrai imports to electrai to match parent commit
0482924
Co-Authored-By: Claude Opus 4.6 <[email protected]>
@forklady42
forklady42 force-pushed the betsy/resunet-hpo branch from 2a91af7 to 0482924 Compare March 3, 2026 17:47
@forklady42

forklady42 commented Mar 4, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased and fixed the src.electrai references. Ready for review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@forklady42
forklady42 requested a review from hanaol March 4, 2026 20:00
@forklady42
forklady42 marked this pull request as ready for review March 4, 2026 20:00
@hanaol

hanaol commented Mar 12, 2026

Copy link
Copy Markdown
Collaborator

Thanks for looking into this Betsy. Did you happen to check larger kernel sizes like 7?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@forklady42

forklady42 commented Mar 12, 2026

Copy link
Copy Markdown
Collaborator Author

@hanaol I initially tested 3 and 5 for kernel size. Since there's architectural changes still in flight, I've been limiting some of the sweeps until those land.

To be clear, this PR focuses on the Optuna integration for running hyperparameter sweeps, rather than the output of the sweep itself.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hanaol

hanaol commented Mar 12, 2026

Copy link
Copy Markdown
Collaborator

I understand. Since you reported the best trial, I was curious which kernel sizes you had explored. I can now see the [3,5] case in your code.

forklady42 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@forklady42
Merge branch 'main' into betsy/resunet-hpo
987cf2e
@forklady42

forklady42 commented Mar 19, 2026

Copy link
Copy Markdown
Collaborator Author

@hanaol anything you'd like addressed on this branch or should I go ahead and merge so we can keep iterating on hyperparameter sweep code?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@forklady42

forklady42 commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator Author

@claude review once more

claude[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@claude

claude Bot commented Apr 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@forklady42 forklady42 mentioned this pull request Apr 7, 2026
Pin claude-code-action to v1.0.88 to dodge symlink ENOENT #117
Merged
3 of 4 tasks
@hanaol

hanaol commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator

@forklady42 I had missed this one, reviewing now...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

forklady42 added a commit that referenced this pull request Apr 7, 2026
@forklady42
Pin claude-code-action to v1.0.88 to dodge symlink ENOENT (#117)
8c69c69
## Summary

- Pin `anthropics/claude-code-action` to `v1.0.88` in
`.github/workflows/claude.yml`
- Works around anthropics/claude-code-action#1187 — v1.0.89's
`restoreConfigFromBase` crashes with `ENOENT: no such file or directory,
symlink` because our `CLAUDE.md` is a symlink to `AGENTS.md` (from #91)
- Every `@claude` trigger has failed since v1.0.89 went out on
2026-04-05; most recent failure:
https://github.com/Quantum-Accelerators/electrai/actions/runs/24089849192

## Why v1.0.88

- Last release before the regression (#1172 / #1174 landed in v1.0.89)
- Upstream fix is anthropics/claude-code-action#1186 but it is still
open; once that ships we can revert the pin back to `@v1`

## Test plan

Note: `@claude`-ing this PR won't test the fix — `issue_comment`
workflows are always resolved from the default branch, so the broken
`@v1` on `main` would still run. The test has to happen post-merge.

- [ ] Merge to `main`
- [ ] Retrigger `@claude review once more` on #84 (it's already failing
on v1.0.89)
- [ ] Confirm the workflow run gets past `Restoring ... from origin/main
(PR head is untrusted)` without an `ENOENT: no such file or directory,
symlink` error
- [ ] Once anthropics/claude-code-action#1186 ships, revert the pin back
to `@v1`
hanaol
hanaol reviewed Apr 7, 2026
View reviewed changes
Comment thread src/electrai/entrypoints/hpo.py
return params


def apply_hyperparameters(cfg_dict: dict, params: dict) -> dict:

@hanaol hanaol Apr 7, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a new parameter is added to search_space in the YAML but not added here, it will be silently dropped. This could produce a study with no error or warning.

There could be a guard at the top:

known_params = {"depth", "n_channels", "n_residual_blocks", "kernel_size",
                "lr", "weight_decay", "warmup_length", "gradient_clip_value",
                "batch_size", "augmentation"}
unknown = set(params) - known_params
if unknown:
    raise ValueError(f"Unknown hyperparameters with no config mapping: {unknown}")

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
hanaol
hanaol reviewed Apr 7, 2026
View reviewed changes
Comment thread src/electrai/entrypoints/hpo.py
depth = trial_cfg_dict["model"]["depth"]
n_channels = trial_cfg_dict["model"]["n_channels"]
max_channels_at_bottleneck = n_channels * (2**depth)
if max_channels_at_bottleneck > 512:

@hanaol hanaol Apr 7, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious how you arrived at the heuristic. Do you think the spatial dimensions of the input grid and precision should also factor in?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
hanaol
hanaol reviewed Apr 7, 2026
View reviewed changes
Comment thread src/electrai/lightning.py
self.log(
"val_loss", loss, prog_bar=True, on_step=True, on_epoch=True, sync_dist=True
"val_loss",
loss,

@hanaol hanaol Apr 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense for HPO since on_step=True creates two metrics (val_loss and val_loss_epoch) which can confuse the monitoring callbacks. That said, per-step validation tracking is still useful during early model development to catch instabilities mid-epoch. Would it be worth making this configurable (e.g. a flag in the config) so we can track it closely while we're still iterating on the architecture?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
hanaol
hanaol approved these changes Apr 7, 2026
View reviewed changes

@hanaol hanaol left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments. Feel free to merge.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@hanaol

hanaol commented May 12, 2026

Copy link
Copy Markdown
Collaborator

@forklady42 there is a pyproject.toml conflict that should be addressed to allow merging. Do you want me to fix it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hanaol pushed a commit that referenced this pull request May 21, 2026
@forklady42 Hananeh Oliaei
Pin claude-code-action to v1.0.88 to dodge symlink ENOENT (#117)
4f087ea
## Summary

- Pin `anthropics/claude-code-action` to `v1.0.88` in
`.github/workflows/claude.yml`
- Works around anthropics/claude-code-action#1187 — v1.0.89's
`restoreConfigFromBase` crashes with `ENOENT: no such file or directory,
symlink` because our `CLAUDE.md` is a symlink to `AGENTS.md` (from #91)
- Every `@claude` trigger has failed since v1.0.89 went out on
2026-04-05; most recent failure:
https://github.com/Quantum-Accelerators/electrai/actions/runs/24089849192

## Why v1.0.88

- Last release before the regression (#1172 / #1174 landed in v1.0.89)
- Upstream fix is anthropics/claude-code-action#1186 but it is still
open; once that ships we can revert the pin back to `@v1`

## Test plan

Note: `@claude`-ing this PR won't test the fix — `issue_comment`
workflows are always resolved from the default branch, so the broken
`@v1` on `main` would still run. The test has to happen post-merge.

- [ ] Merge to `main`
- [ ] Retrigger `@claude review once more` on #84 (it's already failing
on v1.0.89)
- [ ] Confirm the workflow run gets past `Restoring ... from origin/main
(PR head is untrusted)` without an `ENOENT: no such file or directory,
symlink` error
- [ ] Once anthropics/claude-code-action#1186 ships, revert the pin back
to `@v1`

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hanaol hanaol hanaol approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@forklady42 @hanaol
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.