Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,20 @@ def __post_init__(self, **kwargs):
"`vlm_config` is `None`. Initializing `vlm_config` with the `Qwen2VLConfig` with default values."
)
elif isinstance(self.vlm_config, dict):
sub_sub_configs = [self.vlm_config["text_config"], self.vlm_config["vision_config"]]
tie_word_embeddings = {s_s_c.pop("tie_word_embeddings") for s_s_c in sub_sub_configs}
tie_word_embeddings.discard(None)
if len(tie_word_embeddings) > 1:
raise ValueError(
"`tie_word_embeddings` was specified in both text and vision configs but with different values."
)
if tie_word_embeddings:
self.vlm_config["tie_word_embeddings"] = tie_word_embeddings.pop()
self.vlm_config = CONFIG_MAPPING[self.vlm_config["model_type"]](**self.vlm_config)

if not hasattr(self.vlm_config, "vocab_size"):
self.vlm_config.vocab_size = self.vlm_config.get_text_config().vocab_size

# Move `tie_word_embeddings` under `vlm_config` for BC
if self.vlm_config.text_config.tie_word_embeddings and not self.vlm_config.tie_word_embeddings:
self.vlm_config.tie_word_embeddings = self.vlm_config.text_config.tie_word_embeddings
super().__post_init__(**kwargs)

def get_text_config(self, *args, **kwargs) -> PreTrainedConfig:
Expand Down
12 changes: 9 additions & 3 deletions src/transformers/models/colqwen2/configuration_colqwen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,20 @@ def __post_init__(self, **kwargs):
"`vlm_config` is `None`. Initializing `vlm_config` with the `Qwen2VLConfig` with default values."
)
elif isinstance(self.vlm_config, dict):
sub_sub_configs = [self.vlm_config["text_config"], self.vlm_config["vision_config"]]
tie_word_embeddings = {s_s_c.pop("tie_word_embeddings") for s_s_c in sub_sub_configs}
tie_word_embeddings.discard(None)
if len(tie_word_embeddings) > 1:
raise ValueError(
"`tie_word_embeddings` was specified in both text and vision configs but with different values."
)
if tie_word_embeddings:
self.vlm_config["tie_word_embeddings"] = tie_word_embeddings.pop()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we are checking tie word embedding from both text and vision config to know if we should tie for the vlm?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I guess the vision config is a VLM as well?

self.vlm_config = CONFIG_MAPPING[self.vlm_config["model_type"]](**self.vlm_config)

if not hasattr(self.vlm_config, "vocab_size"):
self.vlm_config.vocab_size = self.vlm_config.get_text_config().vocab_size

# Move `tie_word_embeddings` under `vlm_config` for BC
if self.vlm_config.text_config.tie_word_embeddings and not self.vlm_config.tie_word_embeddings:
self.vlm_config.tie_word_embeddings = self.vlm_config.text_config.tie_word_embeddings
super().__post_init__(**kwargs)

def get_text_config(self, *args, **kwargs) -> PreTrainedConfig:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
class ModernVBertForMaskedLM(ModernVBertPreTrainedModel):
_tied_weights_keys = {"lm_head.weight": "model.text_model.embeddings.tok_embeddings.weight"}

def __init__(self, config):
def __init__(self, config: ModernVBertConfig):
super().__init__(config)

self.vocab_size = config.text_config.vocab_size
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/modernvbert/modular_modernvbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class ModernVBertPredictionHead(ModernBertPredictionHead):
class ModernVBertForMaskedLM(ModernVBertPreTrainedModel):
_tied_weights_keys = {"lm_head.weight": "model.text_model.embeddings.tok_embeddings.weight"}

def __init__(self, config):
def __init__(self, config: ModernVBertConfig):
super().__init__(config)

self.vocab_size = config.text_config.vocab_size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ class Qwen2_5_VLTextConfig(PreTrainedConfig):
bos_token_id: int | None = 151643
eos_token_id: int | list[int] | None = 151645
pad_token_id: int | None = None
tie_word_embeddings: bool = False

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

its false by default so that does not change much


def __post_init__(self, **kwargs):
self.sliding_window = self.sliding_window if self.use_sliding_window else None
Expand Down
1 change: 0 additions & 1 deletion src/transformers/models/qwen2_vl/configuration_qwen2_vl.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class Qwen2VLTextConfig(PreTrainedConfig):
bos_token_id: int | None = 151643
eos_token_id: int | list[int] | None = 151645
pad_token_id: int | None = None
tie_word_embeddings: bool = False

def __post_init__(self, **kwargs):
self.sliding_window = self.sliding_window if self.use_sliding_window else None
Expand Down
Loading