Skip to content

fix: Reset model after saving merged model#321

Merged
p-e-w merged 3 commits into
p-e-w:masterfrom
anrp:anrp/lora-fix
May 9, 2026
Merged

fix: Reset model after saving merged model#321
p-e-w merged 3 commits into
p-e-w:masterfrom
anrp:anrp/lora-fix

Conversation

@anrp
Copy link
Copy Markdown
Contributor

@anrp anrp commented May 5, 2026

The adapter is lost and writes 0-byte adapters if you save an adapter after saving the merged model.

@anrp anrp mentioned this pull request May 5, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the model resetting and abliteration logic into a local function named reset_trial_model within count_completed_trials. This function is now called in the original execution flow as well as after saving the model and pushing it to the Hugging Face Hub. A review comment pointed out that the new function signature lacks a return type annotation, which is a violation of the repository's style guide.

Comment thread src/heretic/main.py Outdated
@anrp anrp force-pushed the anrp/lora-fix branch from ad484b7 to bdea2ef Compare May 5, 2026 11:13
@p-e-w
Copy link
Copy Markdown
Owner

p-e-w commented May 7, 2026

Yeah, now that I figured out what the problem is, I was actually able to find a discussion confirming just that: huggingface/peft#868 (comment)

Not having an option to disable this behavior is very poor API design.

Comment thread src/heretic/main.py
del merged_model
empty_cache()
model.tokenizer.save_pretrained(save_directory)
reset_trial_model()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Maybe add a comment here explaining why you are doing this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Commented function

@p-e-w
Copy link
Copy Markdown
Owner

p-e-w commented May 7, 2026

The fix is correct, but the PR is missing the logic from #308, since that was reverted again.

anrp added 3 commits May 7, 2026 06:58
The adapter is lost and writes 0-byte adapters if you save an adapter after saving the merged model.
@anrp anrp force-pushed the anrp/lora-fix branch from bdea2ef to 02239b3 Compare May 7, 2026 11:01
@anrp
Copy link
Copy Markdown
Contributor Author

anrp commented May 7, 2026

The fix is correct, but the PR is missing the logic from #308, since that was reverted again.

Embedded revert-revert in this PR.

@p-e-w p-e-w merged commit 1b48515 into p-e-w:master May 9, 2026
4 checks passed
@p-e-w
Copy link
Copy Markdown
Owner

p-e-w commented May 9, 2026

Thanks, merged! Feels good to finally understand what was going wrong before.

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