Replies: 3 comments 1 reply
|
The warning comes from the recently integrated features for ensuring weight tying. For a model with tied embeddings like yours not setting Regarding your question: Untying has the negative effect of doubling the needed memory for the embedding matrix. In models like Gemma which feature a very large embedding matrix this can already be the difference between running out of memory during training or not. As long as you do fine-tuning (LoRA, MiSS, trainable tokens, ...) you can emulate the behavior of untying the embeddings by setting |
|
Option B: Untie embeddings (set |
|
Good question, and the existing comments are both partially right — let me try to give a complete picture since the nuance here actually matters a lot depending on what you plan to do with the model after training. What's actually happening under the hood When a model has The problem starts when LoRA gets involved. PEFT creates separate adapter modules for Option A — This is the right choice if you plan to merge the adapter back into the base model at any point. Setting from peft import LoraConfig, get_peft_model
config = LoraConfig(
r=16,
lora_alpha=32,
target_modules=["q_proj", "v_proj"],
modules_to_save=["embed_tokens", "lm_head"],
ensure_weight_tying=True, # critical if you ever merge
)
model = get_peft_model(model, config)The tradeoff is that you're training the embedding and lm_head as one unit — which is actually what you want if the model was pretrained that way. Option B — Untie before training ( This is valid if you genuinely want model.config.tie_word_embeddings = False
model.resize_token_embeddings(len(tokenizer))
# now embed_tokens and lm_head are separate tensorsThe downsides are real though — it roughly doubles the memory for the embedding matrix (relevant for models like Gemma or Llama with large vocabularies), and it changes the model's architecture from what it was pretrained on, which can hurt downstream performance for tasks where the output token distribution matters. For your specific case (just adding a pad token) Adding a single pad token is a minimal change. You don't need the full independence of Option B. The recommended path is Option A with If you never intend to merge (i.e., you always load via Quick decision table
The PEFT docs on weight tying and issue #2864 have more context on the ongoing work in this area. |
Uh oh!
There was an error while loading. Please reload this page.
Context
When fine-tuning with LoRA and adding special tokens (e.g. a pad token via
tokenizer.add_special_tokens+model.resize_token_embeddings), I encounter the following warning:This raises a design question I'd like clarification on.
Question
When adding special tokens (particularly a pad token) and applying LoRA, which approach is preferred:
Option A: Keep
tie_word_embeddings=Trueand setensure_weight_tying=Trueto maintain the pretrained model's architecture.Option B: Untie embeddings before fine-tuning (set
tie_word_embeddings=False) so thatembed_tokensandlm_headare trained independently.If anyone has experience with this or can point me to relevant discussions, I'd really appreciate the guidance!
All reactions