Repository: huggingface/transformers
Pull request: Reinstate self.scaling in Gemma3nTextAttention

# What does this PR do?

Previously, the `Gemma3nTextAttention` class removed the `self.scaling` property and passed 1.0 as a hard-coded value to the `attention_interface()` function. 

This PR reinstates the `self.scaling` property, sets it to 1.0, and passes `self.scaling` to the `attention_interface()` function  in `Gemma3nTextAttention.forward()`, which should make it more configurable for users interested in experimenting with the Gemma 3n arch, and improves the lineage of its modular inheritance relative to Gemma 3.

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [x] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [x] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@ArthurZucker @Cyrilvallez


Changed files:
filename: src/transformers/models/gemma3n/modeling_gemma3n.py
patch: @@ -1237,6 +1237,7 @@ def __init__(self, config: Gemma3nTextConfig, layer_idx: int):
         self.layer_idx = layer_idx
         self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
         self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
+        self.scaling = 1.0
         self.attention_dropout = self.config.attention_dropout
         self.is_causal = True
 
@@ -1335,7 +1336,7 @@ def forward(
             value_states,
             attention_mask,
             dropout=self.attention_dropout if self.training else 0.0,
-            scaling=1.0,
+            scaling=self.scaling,
             sliding_window=self.sliding_window,
             **kwargs,
         )

filename: src/transformers/models/gemma3n/modular_gemma3n.py
patch: @@ -1703,7 +1703,7 @@ def __init__(self, config: Gemma3nTextConfig, layer_idx: int):
         super().__init__(config, layer_idx)
         self.is_causal = True
         del self.attn_logit_softcapping
-        del self.scaling
+        self.scaling = 1.0
         self.v_norm = Gemma3nRMSNorm(dim=config.head_dim, eps=config.rms_norm_eps, with_scale=False)
 
         first_kv_shared_layer_idx = self.config.num_hidden_layers - self.config.num_kv_shared_layers
@@ -1782,7 +1782,7 @@ def forward(
             value_states,
             attention_mask,
             dropout=self.attention_dropout if self.training else 0.0,
-            scaling=1.0,
+            scaling=self.scaling,
             sliding_window=self.sliding_window,
             **kwargs,
         )