Fix BOS token embedding: use embed_tokens() instead of raw integer#264
Open
Mr-Neutr0n wants to merge 1 commit intoOpenGVLab:mainfrom
Open
Fix BOS token embedding: use embed_tokens() instead of raw integer#264Mr-Neutr0n wants to merge 1 commit intoOpenGVLab:mainfrom
Mr-Neutr0n wants to merge 1 commit intoOpenGVLab:mainfrom
Conversation
…nteger In the forward() methods, the BOS token position in inputs_embeds was being set to the raw integer bos_token_id (e.g. 1) instead of the actual embedding vector. Since inputs_embeds is a float tensor produced by embed_tokens(), assigning a scalar integer broadcasts that value across the entire embedding dimension, corrupting the BOS representation. Fix by passing bos_token_id through embed_tokens() to obtain the correct embedding vector before assignment. This is applied consistently across all four model files, respecting each file's model attribute path and LoRA configuration. Affected files: - video_chat/models/videochat_it.py - video_chat2/models/videochat_vicuna/videochat2_it_vicuna.py - video_chat2/models/videochat_mistra/videochat2_it_mistral.py - video_chat2/models/videochat_mistra/videochat2_it_hd_mistral.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
forward()methods across 4 model files, the BOS token position ininputs_embedsis set using the raw integerbos_token_id(e.g.,1) instead of its actual embedding vector. Sinceinputs_embedsis a float tensor produced byembed_tokens(), assigning a scalar integer broadcasts that value across the entire embedding dimension, effectively corrupting the BOS position with a uniform constant instead of the learned BOS embedding.bos_token_idthroughembed_tokens()to obtain the proper embedding vector before assigning it toinputs_embeds[:, :1]. The fix respects each file's model attribute path (llama_modelvsmistral_model) and LoRA configuration (base_model.model.modelvsmodel).Affected files
video_chat/models/videochat_it.pyvideo_chat2/models/videochat_vicuna/videochat2_it_vicuna.pyvideo_chat2/models/videochat_mistra/videochat2_it_mistral.pyvideo_chat2/models/videochat_mistra/videochat2_it_hd_mistral.pyBefore (buggy)
After (fixed)
Test plan
inputs_embeds[:, :1]now contains a proper embedding vector (varying values across the hidden dimension) rather than a uniform scalar