Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update modular_modernbert.py to support input_embeddings #35422

Closed
wants to merge 11 commits into from
12 changes: 12 additions & 0 deletions src/transformers/models/modernbert/modeling_modernbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,12 @@ def __init__(self, config: ModernBertConfig):
# Initialize weights and apply final processing
self.post_init()

def get_input_embeddings(self):
return self.model.embeddings.tok_embeddings

def set_input_embeddings(self, value):
self.model.embeddings.tok_embeddings = value

@add_start_docstrings_to_model_forward(MODERNBERT_INPUTS_DOCSTRING)
@add_code_sample_docstrings(
checkpoint=_CHECKPOINT_FOR_DOC,
Expand Down Expand Up @@ -1236,6 +1242,12 @@ def __init__(self, config: ModernBertConfig):
# Initialize weights and apply final processing
self.post_init()

def get_input_embeddings(self):
return self.model.embeddings.tok_embeddings

def set_input_embeddings(self, value):
self.model.embeddings.tok_embeddings = value

@add_start_docstrings_to_model_forward(MODERNBERT_INPUTS_DOCSTRING)
@add_code_sample_docstrings(
checkpoint=_CHECKPOINT_FOR_DOC,
Expand Down
12 changes: 12 additions & 0 deletions src/transformers/models/modernbert/modular_modernbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,12 @@ def __init__(self, config: ModernBertConfig):
# Initialize weights and apply final processing
self.post_init()

def get_input_embeddings(self):
return self.model.embeddings.tok_embeddings

def set_input_embeddings(self, value):
self.model.embeddings.tok_embeddings = value

@add_start_docstrings_to_model_forward(MODERNBERT_INPUTS_DOCSTRING)
@add_code_sample_docstrings(
checkpoint=_CHECKPOINT_FOR_DOC,
Expand Down Expand Up @@ -1389,6 +1395,12 @@ def __init__(self, config: ModernBertConfig):
# Initialize weights and apply final processing
self.post_init()

def get_input_embeddings(self):
return self.model.embeddings.tok_embeddings

def set_input_embeddings(self, value):
self.model.embeddings.tok_embeddings = value

@add_start_docstrings_to_model_forward(MODERNBERT_INPUTS_DOCSTRING)
@add_code_sample_docstrings(
checkpoint=_CHECKPOINT_FOR_DOC,
Expand Down