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 #409] The reproducibility feature makes it impossible to use checkpoints made on older versions of heretic, can you disable it? #201

Closed
opened 2026-11-01 04:18:35 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @erm14254 on GitHub (Jul 12, 2026).
Original GitHub issue: https://github.com/p-e-w/heretic/issues/409

Like inside config.toml, can you use something like:

reproducibility = false
reproduction = false
scores = false
score = false

Any options like that to disable reproducibility? Because right now "backward compatibility" is completely broken as far as I can tell.

Here is the error:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in _run_module_as_main:198 │
│ in _run_code:88 │
│ │
│ in :5 │
│ │
│ 2 from heretic.main import main │
│ 3 if name == 'main': │
│ 4 │ sys.argv[0] = sys.argv[0].removesuffix('.exe') │
│ ❱ 5 │ sys.exit(main()) │
│ 6 │
│ │
│ D:\heretic\src\heretic\main.py:1496 in main │
│ │
│ 1493 │ install() │
│ 1494 │ │
│ 1495 │ try: │
│ ❱ 1496 │ │ run() │
│ 1497 │ except BaseException as error: │
│ 1498 │ │ # Transformers appears to handle KeyboardInterrupt (or BaseException) │
│ 1499 │ │ # internally in some places, which can re-raise a different error in the handler │
│ │
│ D:\heretic\src\heretic\main.py:776 in run │
│ │
│ 773 │ │ │ │ raise KeyboardInterrupt │
│ 774 │ │ │ │
│ 775 │ │ │ # Best trials isn't sorted, so sort by all the scores in non-decreasing orde │
│ ❱ 776 │ │ │ sorted_trials = sorted( │
│ 777 │ │ │ │ study.best_trials, │
│ 778 │ │ │ │ key=lambda trial: ( │
│ 779 │ │ │ │ │ tuple( │
│ │
│ D:\heretic\src\heretic\main.py:779 in │
│ │
│ 776 │ │ │ sorted_trials = sorted( │
│ 777 │ │ │ │ study.best_trials, │
│ 778 │ │ │ │ key=lambda trial: ( │
│ ❱ 779 │ │ │ │ │ tuple( │
│ 780 │ │ │ │ │ │ next( │
│ 781 │ │ │ │ │ │ │ ( │
│ 782 │ │ │ │ │ │ │ │ score["score"]["value"] │
│ │
│ D:\heretic\src\heretic\main.py:783 in │
│ │
│ 780 │ │ │ │ │ │ next( │
│ 781 │ │ │ │ │ │ │ ( │
│ 782 │ │ │ │ │ │ │ │ score["score"]["value"] │
│ ❱ 783 │ │ │ │ │ │ │ │ for score in trial.user_attrs["scores"] │
│ 784 │ │ │ │ │ │ │ │ if score["name"] == name │
│ 785 │ │ │ │ │ │ │ ), │
│ 786 │ │ │ │ │ │ │ None, │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'scores'

There is also this error:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in _run_module_as_main:198 │
│ in _run_code:88 │
│ │
│ in :5 │
│ │
│ 2 from heretic.main import main │
│ 3 if name == 'main': │
│ 4 │ sys.argv[0] = sys.argv[0].removesuffix('.exe') │
│ ❱ 5 │ sys.exit(main()) │
│ 6 │
│ │
│ D:\heretic\src\heretic\main.py:1496 in main │
│ │
│ 1493 │ install() │
│ 1494 │ │
│ 1495 │ try: │
│ ❱ 1496 │ │ run() │
│ 1497 │ except BaseException as error: │
│ 1498 │ │ # Transformers appears to handle KeyboardInterrupt (or BaseException) │
│ 1499 │ │ # internally in some places, which can re-raise a different error in the handler │
│ │
│ D:\heretic\src\heretic\main.py:749 in run │
│ │
│ 746 │ │ │ print("Resuming existing study.") │
│ 747 │ │ │
│ 748 │ │ try: │
│ ❱ 749 │ │ │ study.optimize( │
│ 750 │ │ │ │ objective_wrapper, │
│ 751 │ │ │ │ n_trials=settings.n_trials - len(study.trials), │
│ 752 │ │ │ ) │
│ │
│ D:\heretic\venv\Lib\site-packages\optuna\study\study.py:516 in optimize │
│ │
│ 513 │ │ │ RuntimeError: │
│ 514 │ │ │ │ If nested invocation of this method occurs. │
│ 515 │ │ """ │
│ ❱ 516 │ │ _optimize( │
│ 517 │ │ │ study=self, │
│ 518 │ │ │ func=func, │
│ 519 │ │ │ n_trials=n_trials, │
│ │
│ D:\heretic\venv\Lib\site-packages\optuna\study_optimize.py:68 in _optimize │
│ │
│ 65 │ │
│ 66 │ try: │
│ 67 │ │ if n_jobs == 1: │
│ ❱ 68 │ │ │ _optimize_sequential( │
│ 69 │ │ │ │ study, │
│ 70 │ │ │ │ func, │
│ 71 │ │ │ │ n_trials, │
│ │
│ D:\heretic\venv\Lib\site-packages\optuna\study_optimize.py:165 in _optimize_sequential │
│ │
│ 162 │ │ │ │ break │
│ 163 │ │ │
│ 164 │ │ try: │
│ ❱ 165 │ │ │ frozen_trial_id = _run_trial(study, func, catch) │
│ 166 │ │ finally: │
│ 167 │ │ │ # The following line mitigates memory problems that can be occurred in some │
│ 168 │ │ │ # environments (e.g., services that use computing containers such as GitHub │
│ │
│ D:\heretic\venv\Lib\site-packages\optuna\study_optimize.py:263 in _run_trial │
│ │
│ 260 │ │ and func_err is not None │
│ 261 │ │ and not isinstance(func_err, catch) │
│ 262 │ ): │
│ ❱ 263 │ │ raise func_err │
│ 264 │ return trial._trial_id │
│ 265 │
│ 266 │
│ │
│ D:\heretic\venv\Lib\site-packages\optuna\study_optimize.py:206 in _run_trial │
│ │
│ 203 │ │
│ 204 │ with get_heartbeat_thread(trial._trial_id, study._storage): │
│ 205 │ │ try: │
│ ❱ 206 │ │ │ value_or_values = func(trial) │
│ 207 │ │ except exceptions.TrialPruned as e: │
│ 208 │ │ │ # TODO(mamu): Handle multi-objective cases. │
│ 209 │ │ │ state = TrialState.PRUNED │
│ │
│ D:\heretic\src\heretic\main.py:716 in objective_wrapper │
│ │
│ 713 │ │
│ 714 │ def objective_wrapper(trial: Trial) -> tuple[float, ...]: │
│ 715 │ │ try: │
│ ❱ 716 │ │ │ return objective(trial) │
│ 717 │ │ except KeyboardInterrupt: │
│ 718 │ │ │ # Stop the study gracefully on Ctrl+C. │
│ 719 │ │ │ trial.study.stop() │
│ │
│ D:\heretic\src\heretic\main.py:687 in objective │
│ │
│ 684 │ │ print("* Resetting model...") │
│ 685 │ │ model.reset_model() │
│ 686 │ │ print("* Abliterating...") │
│ ❱ 687 │ │ model.abliterate(residual_directions, direction_index, parameters) │
│ 688 │ │ print("* Evaluating...") │
│ 689 │ │ scores = evaluator.get_scores() │
│ 690 │ │ objective_values = evaluator.get_objective_values(scores) │
│ │
│ D:\heretic\src\heretic\model.py:619 in abliterate │
│ │
│ 616 │ │ │ │ │ │ # svd_lowrank is randomized: │
│ 617 │ │ │ │ │ │ # github.com/pytorch/pytorch@2091905230 │
│ 618 │ │ │ │ │ │ # Reseed immediately before the call so restoring a trial is ind │
│ ❱ 619 │ │ │ │ │ │ torch.manual_seed(self.settings.seed) │
│ 620 │ │ │ │ │ │ # "It's safe to call this function if CUDA is not available; │
│ 621 │ │ │ │ │ │ # in that case, it is silently ignored." │
│ 622 │ │ │ │ │ │ torch.cuda.manual_seed_all(self.settings.seed) # ty:ignore[inva │
│ │
│ D:\heretic\venv\Lib\site-packages\torch_compile.py:54 in inner │
│ │
│ 51 │ │ │ │ disable_fn = torch._dynamo.disable(fn, recursive, wrapping=False) │
│ 52 │ │ │ │ fn.__dynamo_disable = disable_fn # type: ignore[attr-defined] │
│ 53 │ │ │ │
│ ❱ 54 │ │ │ return disable_fn(*args, **kwargs) │
│ 55 │ │ │
│ 56 │ │ return inner │
│ 57 │ else: │
│ │
│ D:\heretic\venv\Lib\site-packages\torch_dynamo\eval_frame.py:1446 in _fn │
│ │
│ 1443 │ │ │ │ │ │ │ } │
│ 1444 │ │ │ │ │ │ ): │
│ 1445 │ │ │ │ │ │ │ return fn(*args, **kwargs) │
│ ❱ 1446 │ │ │ │ │ return fn(*args, **kwargs) │
│ 1447 │ │ │ │ finally: │
│ 1448 │ │ │ │ │ set_eval_frame(None) │
│ 1449 │ │ │ finally: │
│ │
│ D:\heretic\venv\Lib\site-packages\torch\random.py:59 in manual_seed │
│ │
│ 56 │ │ │ is raised. Negative inputs are remapped to positive values with the formula │
│ 57 │ │ │ 0xffff_ffff_ffff_ffff + seed. │
│ 58 │ """ │
│ ❱ 59 │ return _manual_seed_impl(seed) │
│ 60 │
│ 61 │
│ 62 def _manual_seed_impl(seed) -> torch._C.Generator: │
│ │
│ D:\heretic\venv\Lib\site-packages\torch\random.py:63 in _manual_seed_impl │
│ │
│ 60 │
│ 61 │
│ 62 def _manual_seed_impl(seed) -> torch._C.Generator: │
│ ❱ 63 │ seed = int(seed) │
│ 64 │ import torch.cuda │
│ 65 │ │
│ 66 │ if not torch.cuda._is_in_bad_fork(): │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

But I found that this one can be fixed or bypassed by adding:

seed = false

Inside config,toml.

Originally created by @erm14254 on GitHub (Jul 12, 2026). Original GitHub issue: https://github.com/p-e-w/heretic/issues/409 Like inside config.toml, can you use something like: `reproducibility = false` `reproduction = false` `scores = false` `score = false` Any options like that to disable reproducibility? Because right now "backward compatibility" is completely broken as far as I can tell. Here is the error: ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ in _run_module_as_main:198 │ │ in _run_code:88 │ │ │ │ in <module>:5 │ │ │ │ 2 from heretic.main import main │ │ 3 if __name__ == '__main__': │ │ 4 │ sys.argv[0] = sys.argv[0].removesuffix('.exe') │ │ ❱ 5 │ sys.exit(main()) │ │ 6 │ │ │ │ D:\heretic\src\heretic\main.py:1496 in main │ │ │ │ 1493 │ install() │ │ 1494 │ │ │ 1495 │ try: │ │ ❱ 1496 │ │ run() │ │ 1497 │ except BaseException as error: │ │ 1498 │ │ # Transformers appears to handle KeyboardInterrupt (or BaseException) │ │ 1499 │ │ # internally in some places, which can re-raise a different error in the handler │ │ │ │ D:\heretic\src\heretic\main.py:776 in run │ │ │ │ 773 │ │ │ │ raise KeyboardInterrupt │ │ 774 │ │ │ │ │ 775 │ │ │ # Best trials isn't sorted, so sort by all the scores in non-decreasing orde │ │ ❱ 776 │ │ │ sorted_trials = sorted( │ │ 777 │ │ │ │ study.best_trials, │ │ 778 │ │ │ │ key=lambda trial: ( │ │ 779 │ │ │ │ │ tuple( │ │ │ │ D:\heretic\src\heretic\main.py:779 in <lambda> │ │ │ │ 776 │ │ │ sorted_trials = sorted( │ │ 777 │ │ │ │ study.best_trials, │ │ 778 │ │ │ │ key=lambda trial: ( │ │ ❱ 779 │ │ │ │ │ tuple( │ │ 780 │ │ │ │ │ │ next( │ │ 781 │ │ │ │ │ │ │ ( │ │ 782 │ │ │ │ │ │ │ │ score["score"]["value"] │ │ │ │ D:\heretic\src\heretic\main.py:783 in <genexpr> │ │ │ │ 780 │ │ │ │ │ │ next( │ │ 781 │ │ │ │ │ │ │ ( │ │ 782 │ │ │ │ │ │ │ │ score["score"]["value"] │ │ ❱ 783 │ │ │ │ │ │ │ │ for score in trial.user_attrs["scores"] │ │ 784 │ │ │ │ │ │ │ │ if score["name"] == name │ │ 785 │ │ │ │ │ │ │ ), │ │ 786 │ │ │ │ │ │ │ None, │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ KeyError: 'scores' There is also this error: ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ in _run_module_as_main:198 │ │ in _run_code:88 │ │ │ │ in <module>:5 │ │ │ │ 2 from heretic.main import main │ │ 3 if __name__ == '__main__': │ │ 4 │ sys.argv[0] = sys.argv[0].removesuffix('.exe') │ │ ❱ 5 │ sys.exit(main()) │ │ 6 │ │ │ │ D:\heretic\src\heretic\main.py:1496 in main │ │ │ │ 1493 │ install() │ │ 1494 │ │ │ 1495 │ try: │ │ ❱ 1496 │ │ run() │ │ 1497 │ except BaseException as error: │ │ 1498 │ │ # Transformers appears to handle KeyboardInterrupt (or BaseException) │ │ 1499 │ │ # internally in some places, which can re-raise a different error in the handler │ │ │ │ D:\heretic\src\heretic\main.py:749 in run │ │ │ │ 746 │ │ │ print("Resuming existing study.") │ │ 747 │ │ │ │ 748 │ │ try: │ │ ❱ 749 │ │ │ study.optimize( │ │ 750 │ │ │ │ objective_wrapper, │ │ 751 │ │ │ │ n_trials=settings.n_trials - len(study.trials), │ │ 752 │ │ │ ) │ │ │ │ D:\heretic\venv\Lib\site-packages\optuna\study\study.py:516 in optimize │ │ │ │ 513 │ │ │ RuntimeError: │ │ 514 │ │ │ │ If nested invocation of this method occurs. │ │ 515 │ │ """ │ │ ❱ 516 │ │ _optimize( │ │ 517 │ │ │ study=self, │ │ 518 │ │ │ func=func, │ │ 519 │ │ │ n_trials=n_trials, │ │ │ │ D:\heretic\venv\Lib\site-packages\optuna\study\_optimize.py:68 in _optimize │ │ │ │ 65 │ │ │ 66 │ try: │ │ 67 │ │ if n_jobs == 1: │ │ ❱ 68 │ │ │ _optimize_sequential( │ │ 69 │ │ │ │ study, │ │ 70 │ │ │ │ func, │ │ 71 │ │ │ │ n_trials, │ │ │ │ D:\heretic\venv\Lib\site-packages\optuna\study\_optimize.py:165 in _optimize_sequential │ │ │ │ 162 │ │ │ │ break │ │ 163 │ │ │ │ 164 │ │ try: │ │ ❱ 165 │ │ │ frozen_trial_id = _run_trial(study, func, catch) │ │ 166 │ │ finally: │ │ 167 │ │ │ # The following line mitigates memory problems that can be occurred in some │ │ 168 │ │ │ # environments (e.g., services that use computing containers such as GitHub │ │ │ │ D:\heretic\venv\Lib\site-packages\optuna\study\_optimize.py:263 in _run_trial │ │ │ │ 260 │ │ and func_err is not None │ │ 261 │ │ and not isinstance(func_err, catch) │ │ 262 │ ): │ │ ❱ 263 │ │ raise func_err │ │ 264 │ return trial._trial_id │ │ 265 │ │ 266 │ │ │ │ D:\heretic\venv\Lib\site-packages\optuna\study\_optimize.py:206 in _run_trial │ │ │ │ 203 │ │ │ 204 │ with get_heartbeat_thread(trial._trial_id, study._storage): │ │ 205 │ │ try: │ │ ❱ 206 │ │ │ value_or_values = func(trial) │ │ 207 │ │ except exceptions.TrialPruned as e: │ │ 208 │ │ │ # TODO(mamu): Handle multi-objective cases. │ │ 209 │ │ │ state = TrialState.PRUNED │ │ │ │ D:\heretic\src\heretic\main.py:716 in objective_wrapper │ │ │ │ 713 │ │ │ 714 │ def objective_wrapper(trial: Trial) -> tuple[float, ...]: │ │ 715 │ │ try: │ │ ❱ 716 │ │ │ return objective(trial) │ │ 717 │ │ except KeyboardInterrupt: │ │ 718 │ │ │ # Stop the study gracefully on Ctrl+C. │ │ 719 │ │ │ trial.study.stop() │ │ │ │ D:\heretic\src\heretic\main.py:687 in objective │ │ │ │ 684 │ │ print("* Resetting model...") │ │ 685 │ │ model.reset_model() │ │ 686 │ │ print("* Abliterating...") │ │ ❱ 687 │ │ model.abliterate(residual_directions, direction_index, parameters) │ │ 688 │ │ print("* Evaluating...") │ │ 689 │ │ scores = evaluator.get_scores() │ │ 690 │ │ objective_values = evaluator.get_objective_values(scores) │ │ │ │ D:\heretic\src\heretic\model.py:619 in abliterate │ │ │ │ 616 │ │ │ │ │ │ # svd_lowrank is randomized: │ │ 617 │ │ │ │ │ │ # https://github.com/pytorch/pytorch/blob/20919052303c0b5ba87f8b │ │ 618 │ │ │ │ │ │ # Reseed immediately before the call so restoring a trial is ind │ │ ❱ 619 │ │ │ │ │ │ torch.manual_seed(self.settings.seed) │ │ 620 │ │ │ │ │ │ # "It's safe to call this function if CUDA is not available; │ │ 621 │ │ │ │ │ │ # in that case, it is silently ignored." │ │ 622 │ │ │ │ │ │ torch.cuda.manual_seed_all(self.settings.seed) # ty:ignore[inva │ │ │ │ D:\heretic\venv\Lib\site-packages\torch\_compile.py:54 in inner │ │ │ │ 51 │ │ │ │ disable_fn = torch._dynamo.disable(fn, recursive, wrapping=False) │ │ 52 │ │ │ │ fn.__dynamo_disable = disable_fn # type: ignore[attr-defined] │ │ 53 │ │ │ │ │ ❱ 54 │ │ │ return disable_fn(*args, **kwargs) │ │ 55 │ │ │ │ 56 │ │ return inner │ │ 57 │ else: │ │ │ │ D:\heretic\venv\Lib\site-packages\torch\_dynamo\eval_frame.py:1446 in _fn │ │ │ │ 1443 │ │ │ │ │ │ │ } │ │ 1444 │ │ │ │ │ │ ): │ │ 1445 │ │ │ │ │ │ │ return fn(*args, **kwargs) │ │ ❱ 1446 │ │ │ │ │ return fn(*args, **kwargs) │ │ 1447 │ │ │ │ finally: │ │ 1448 │ │ │ │ │ set_eval_frame(None) │ │ 1449 │ │ │ finally: │ │ │ │ D:\heretic\venv\Lib\site-packages\torch\random.py:59 in manual_seed │ │ │ │ 56 │ │ │ is raised. Negative inputs are remapped to positive values with the formula │ │ 57 │ │ │ `0xffff_ffff_ffff_ffff + seed`. │ │ 58 │ """ │ │ ❱ 59 │ return _manual_seed_impl(seed) │ │ 60 │ │ 61 │ │ 62 def _manual_seed_impl(seed) -> torch._C.Generator: │ │ │ │ D:\heretic\venv\Lib\site-packages\torch\random.py:63 in _manual_seed_impl │ │ │ │ 60 │ │ 61 │ │ 62 def _manual_seed_impl(seed) -> torch._C.Generator: │ │ ❱ 63 │ seed = int(seed) │ │ 64 │ import torch.cuda │ │ 65 │ │ │ 66 │ if not torch.cuda._is_in_bad_fork(): │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType' But I found that this one can be fixed or bypassed by adding: `seed = false` Inside config,toml.
Author
Owner

@p-e-w commented on GitHub (Jul 12, 2026):

Checkpoints are always version-specific because they serialize the entire config. This is not particular to the reproducibility feature. Even an update of the Optuna package can break compatibility without anything changing in Heretic. The fix is to run the version you created the checkpoint with, or to use a hack like the one you came up with.

Please note that the ecosystem is extremely complex and rapidly evolving, so in general, no aspect of Heretic is guaranteed to be backwards compatible.

<!-- gh-comment-id:4951093300 --> @p-e-w commented on GitHub (Jul 12, 2026): Checkpoints are always version-specific because they serialize the entire config. This is not particular to the reproducibility feature. Even an update of the Optuna package can break compatibility without anything changing in Heretic. The fix is to run the version you created the checkpoint with, or to use a hack like the one you came up with. Please note that the ecosystem is extremely complex and rapidly evolving, so in general, no aspect of Heretic is guaranteed to be backwards compatible.
Author
Owner

@erm14254 commented on GitHub (Jul 12, 2026):

or to use a hack like the one you came up with.

That only fix the "Seed" issue, it doesn't fix the " KeyError: 'scores'" issue.

Please note that the ecosystem is extremely complex and rapidly evolving, so in general, no aspect of Heretic is guaranteed to be backwards compatible.

Got it, thanks for the reply.

<!-- gh-comment-id:4951737652 --> @erm14254 commented on GitHub (Jul 12, 2026): > or to use a hack like the one you came up with. That only fix the "Seed" issue, it doesn't fix the " KeyError: 'scores'" issue. > Please note that the ecosystem is extremely complex and rapidly evolving, so in general, no aspect of Heretic is guaranteed to be backwards compatible. Got it, thanks for the reply.
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#201
No description provided.