Skip to content

Pass layers_to_transform, use_rslora and modules_to_save to LoraConfig on the SentenceTransformer fast encoder path - #14150

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
vineethsaivs:fix/st-fast-encoder-lora-args
Oct 19, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
vineethsaivs:fix/st-fast-encoder-lora-args

Conversation

@vineethsaivs

@vineethsaivs vineethsaivs commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

FastSentenceTransformer.get_peft_model on the fast encoder path (BERT/MPNet-style models) built its LoraConfig without layers_to_transform, layers_pattern, use_rslora or modules_to_save, so they were accepted and silently ignored. use_rslora=True trained with alpha/r scaling instead of alpha/sqrt(r), and layers_to_transform still adapted every layer.

Fix: pass the four arguments through, as the other branch already does.

Test: new tests/test_st_fast_encoder_lora_config.py on a tiny BERT, CPU. On main it fails (use_rslora False; 13 adapters, scaling 2.0). With the fix it passes (6 adapters on layer 1 only, scaling 4.0). The other sentence-transformer tests I ran still pass. Not run on GPU.

Follow-up fix: with modules_to_save now honoured, a model loaded in float16 (T4, V100) kept its trainable copies in float16 while the LoRA weights were float32, so the first optimizer step raised ValueError: Attempting to unscale FP16 gradients. The fast encoder path now calls _unfreeze_modules_to_save, the same helper the FastModel path uses, which upcasts float16 copies to float32 (#1200). Added test_float16_modules_to_save_copy_trains_in_float32, which fails without the upcast.

Verified on GPU with sentence-transformers/all-MiniLM-L6-v2 (r=8, alpha=16, layers [4, 5], rsLoRA, modules_to_save, 20 steps): base trains LoRA on every layer plus pooler.dense with 337920 trainable parameters at scaling 2.0; after this PR LoRA lands on layers 4 and 5 only, scaling is 16/sqrt(8), and the trainable count matches plain PEFT (111360). On a Colab T4 in float16 the original change crashed with the error above and the fixed head trains and saves a merged model.

…g on the SentenceTransformer fast encoder path

The fast encoder branch of FastSentenceTransformer.get_peft_model built its LoraConfig without these arguments, so they were accepted and silently ignored.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T09:19:10.568957Z d712c05 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 89f792e1a7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: d712c05c89

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants