diff --git a/src/transformers/models/stablelm/configuration_stablelm.py b/src/transformers/models/stablelm/configuration_stablelm.py index a8bf97887e45..f28c0ecfc076 100644 --- a/src/transformers/models/stablelm/configuration_stablelm.py +++ b/src/transformers/models/stablelm/configuration_stablelm.py @@ -87,6 +87,8 @@ class StableLmConfig(PreTrainedConfig, RotaryEmbeddingConfigMixin): The id of the `BOS` token in the vocabulary. eos_token_id (int, *optional*, defaults to 0): The id of the `EOS` token in the vocabulary. + pad_token_id (int, *optional*): + The id of the `PAD` token in the vocabulary. Example: @@ -122,6 +124,7 @@ def __init__( attention_dropout: float | None = 0.0, bos_token_id: int | None = 0, eos_token_id: int | None = 0, + pad_token_id: int | None = None, **kwargs, ): self.vocab_size = vocab_size @@ -147,6 +150,7 @@ def __init__( self.bos_token_id = bos_token_id self.eos_token_id = eos_token_id + self.pad_token_id = pad_token_id self.tie_word_embeddings = tie_word_embeddings super().__init__(**kwargs) diff --git a/tests/models/stablelm/test_modeling_stablelm.py b/tests/models/stablelm/test_modeling_stablelm.py index c5412db98a47..832c492a43ec 100644 --- a/tests/models/stablelm/test_modeling_stablelm.py +++ b/tests/models/stablelm/test_modeling_stablelm.py @@ -47,6 +47,16 @@ class StableLmModelTester(CausalLMModelTester): @require_torch class StableLmModelTest(CausalLMModelTest, unittest.TestCase): model_tester_class = StableLmModelTester + def test_config_has_pad_token_id(self): + """Test that StableLmConfig includes pad_token_id attribute (fixes #43572)""" + from transformers import StableLmConfig + + config = StableLmConfig() + self.assertTrue(hasattr(config, "pad_token_id")) + + # Verify model can be instantiated from config without AttributeError + model = StableLmModel(config) + self.assertIsNotNone(model) @require_torch