1
0
Fork 0
mirror of https://github.com/p-e-w/heretic.git synced 2026-12-03 18:42:57 +07:00

[GH-ISSUE #95] State save possible? #50

Closed
opened 2026-11-01 04:16:59 +07:00 by bsakaguchi · 5 comments
Owner

Originally created by @Hotohori on GitHub (Jan 2, 2026).
Original GitHub issue: https://github.com/p-e-w/heretic/issues/95

I wonder if it would be possible to save states between trials so you can continue if anything stops the app or save trials directly which are under a set value of KL/refusal?

I tried to use my RTX 4090 to run Heretic on Mistral Nemo 12B (no quant), but because 24GB VRAM is a bit too less for the full model some parts needed to be on CPU it and so it runs close on full VRAM and for reasons it failed after over 2h with CUDA out of memory on trial 35 and with that you lose everything.

Originally created by @Hotohori on GitHub (Jan 2, 2026). Original GitHub issue: https://github.com/p-e-w/heretic/issues/95 I wonder if it would be possible to save states between trials so you can continue if anything stops the app or save trials directly which are under a set value of KL/refusal? I tried to use my RTX 4090 to run Heretic on Mistral Nemo 12B (no quant), but because 24GB VRAM is a bit too less for the full model some parts needed to be on CPU it and so it runs close on full VRAM and for reasons it failed after over 2h with CUDA out of memory on trial 35 and with that you lose everything.
Author
Owner

@Vinay-Umrethe commented on GitHub (Jan 2, 2026):

that's a cracking idea actually and something i’d considered before but i haven't made any PRs for it or gave much attention... I know optuna uses sqlite to save data in a .db file but I’m not entirely sure if heretic actually makes use of that built in feature or not

<!-- gh-comment-id:3706473348 --> @Vinay-Umrethe commented on GitHub (Jan 2, 2026): that's a cracking idea actually and something i’d considered before but i haven't made any PRs for it or gave much attention... I know optuna uses sqlite to save data in a .db file but I’m not entirely sure if heretic actually makes use of that built in feature or not
Author
Owner

@Hotohori commented on GitHub (Jan 3, 2026):

Well, it would be great, because now it was even more annoying. I tried the actual branch to set max_memory. It worked good until the end. When I should selected the trial I want to save and give it a directory name > CUDA out of memory. Closed all to make as much VRAM free as possible, didn't help and in the end the app crashed totally with a CUDA out of memory and already all the work for nothing.

So, yes, a save of the trials under a specific rate would be great.

<!-- gh-comment-id:3706580322 --> @Hotohori commented on GitHub (Jan 3, 2026): Well, it would be great, because now it was even more annoying. I tried the actual branch to set max_memory. It worked good until the end. When I should selected the trial I want to save and give it a directory name > CUDA out of memory. Closed all to make as much VRAM free as possible, didn't help and in the end the app crashed totally with a CUDA out of memory and already all the work for nothing. So, yes, a save of the trials under a specific rate would be great.
Author
Owner

@spikymoth commented on GitHub (Jan 3, 2026):

I actually implemented something like this locally, just extracted it into a branch:

https://github.com/spikymoth/heretic/tree/save-and-resume (the commits: github.com/spikymoth/heretic@d0d9092a30 & github.com/spikymoth/heretic@4ac0d54c83)

It's a bit rough:

  1. I used the JSON-based storage (JournalFileBackend), so it's more easily editable but maybe also more fragile than sqlite
  2. It always stores the active study in log/study.jsonl and uses fixed internal name my_study
  3. It doesn't do any checking to see if the logged study corresponds to the current session (you can run with different settings or on a completely different model and it'll let you resume anyway)
  4. There's no file locking and it's append-only during runtime, so if you wipe it accidentally, it's gone forever
  5. If you use Ctrl+C to cancel early, the last trial is ignored but still counted toward the total (this is pretty minor)

So it needs more work before it can be called production ready, but it's usable if you know the limitations.

If anyone wants to use it as a starting point for a pull request, you have my blessing :)

<!-- gh-comment-id:3706625518 --> @spikymoth commented on GitHub (Jan 3, 2026): I actually implemented something like this locally, just extracted it into a branch: https://github.com/spikymoth/heretic/tree/save-and-resume (the commits: https://github.com/spikymoth/heretic/commit/d0d9092a3046e5d517d9b67a87866b11d0ee3274 & https://github.com/spikymoth/heretic/commit/4ac0d54c83367969a9526614d62c64cf4d21a244) It's a bit rough: 1. I used the JSON-based storage ([JournalFileBackend](https://optuna.readthedocs.io/en/v4.0.0/reference/generated/optuna.storages.journal.JournalFileBackend.html#optuna.storages.journal.JournalFileBackend)), so it's more easily editable but maybe also more fragile than sqlite 2. It always stores the active study in `log/study.jsonl` and uses fixed internal name `my_study` 3. It doesn't do any checking to see if the logged study corresponds to the current session (you can run with different settings or on a completely different model and it'll let you resume anyway) 4. There's no file locking and it's append-only during runtime, so if you wipe it accidentally, it's gone forever 5. If you use Ctrl+C to cancel early, the last trial is ignored but still counted toward the total (this is pretty minor) So it needs more work before it can be called production ready, but it's usable if you know the limitations. If anyone wants to use it as a starting point for a pull request, you have my blessing :)
Author
Owner

@spikymoth commented on GitHub (Jan 3, 2026):

My implementation can be simplified a bit more by setting load_if_exists=True in optuna.create_study instead of using optuna.load_study. Pushed a 2nd commit for that: github.com/spikymoth/heretic@4ac0d54c83

<!-- gh-comment-id:3707162276 --> @spikymoth commented on GitHub (Jan 3, 2026): My implementation can be simplified a bit more by setting `load_if_exists=True` in `optuna.create_study` instead of using `optuna.load_study`. Pushed a 2nd commit for that: https://github.com/spikymoth/heretic/commit/4ac0d54c83367969a9526614d62c64cf4d21a244
Author
Owner

@anrp commented on GitHub (Jan 15, 2026):

Reworked/improved your change, in https://github.com/p-e-w/heretic/pull/106

<!-- gh-comment-id:3755054192 --> @anrp commented on GitHub (Jan 15, 2026): Reworked/improved your change, in https://github.com/p-e-w/heretic/pull/106
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
p-e-w/heretic#50
No description provided.