Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions src/transformers/models/granite/configuration_granite.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ class GraniteConfig(PreTrainedConfig):
attention_bias: bool = False
attention_dropout: float | int = 0.0
mlp_bias: bool = False
embedding_multiplier: float = 1.0
logits_scaling: float = 1.0
residual_multiplier: float = 1.0
attention_multiplier: float = 1.0
embedding_multiplier: float | int = 1.0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

there are more Granite models with xxx_multiplier, xan you update all of them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated GraniteMoe and GraniteMoeShared. GraniteMoeHybrid already supports int | float | None.

Let me know if you spot any other fixes or anything else to add!

logits_scaling: float | int = 1.0
residual_multiplier: float | int = 1.0
attention_multiplier: float | int = 1.0

def __post_init__(self, **kwargs):
if self.num_key_value_heads is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class GraniteMoeConfig(PreTrainedConfig):
rope_parameters: RopeParameters | dict | None = None
attention_bias: bool = False
attention_dropout: float | int | None = 0.0
embedding_multiplier: float | None = 1.0
logits_scaling: float | None = 1.0
residual_multiplier: float | None = 1.0
attention_multiplier: float | None = 1.0
embedding_multiplier: float | int | None = 1.0
logits_scaling: float | int | None = 1.0
residual_multiplier: float | int | None = 1.0
attention_multiplier: float | int | None = 1.0
num_local_experts: int | None = 8
num_experts_per_tok: int | None = 2
output_router_logits: bool | None = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ class GraniteMoeSharedConfig(PreTrainedConfig):
rope_parameters: RopeParameters | dict | None = None
attention_bias: bool = False
attention_dropout: float | int | None = 0.0
embedding_multiplier: float | None = 1.0
logits_scaling: float | None = 1.0
residual_multiplier: float | None = 1.0
attention_multiplier: float | None = 1.0
embedding_multiplier: float | int | None = 1.0
logits_scaling: float | int | None = 1.0
residual_multiplier: float | int | None = 1.0
attention_multiplier: float | int | None = 1.0
num_local_experts: int | None = 8
num_experts_per_tok: int | None = 2
output_router_logits: bool | None = False
Expand Down
9 changes: 9 additions & 0 deletions tests/models/granite/test_modeling_granite.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
"""Testing suite for the PyTorch Granite model."""

import tempfile
import unittest

from transformers import GraniteConfig, is_torch_available
Expand Down Expand Up @@ -185,6 +186,14 @@ def setUp(self):
def test_config(self):
self.config_tester.run_common_tests()

def test_config_int_multiplier_roundtrip(self):
config = GraniteConfig(embedding_multiplier=12, logits_scaling=8)
with tempfile.TemporaryDirectory() as tmpdir:
config.save_pretrained(tmpdir)
loaded = GraniteConfig.from_pretrained(tmpdir)
self.assertEqual(loaded.embedding_multiplier, 12)
self.assertEqual(loaded.logits_scaling, 8)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)
Expand Down
Loading