Repository: huggingface/transformers
Pull request: fix: AttributeError for Qwen3_omni_moe

# What does this PR do?

This PR fixes a crash when initializing `Qwen3OmniMoeTalkerCodePredictorConfig` due to a missing attribute reference.

Specifically, it:
1.  **Removes** the reference to the non-existent `use_sliding_window` attribute, which was causing an `AttributeError`.
2.  **Adds** the missing `max_window_layers` initialization (defaulting to `28`). The existing `layer_types` logic relies on this attribute, and without it, `sliding_window` causes a secondary crash.
3.  **Adds** a new test case (`test_code_predictor_config_init`) to ensure the configuration initializes correctly. 

Fixes #43531


## Before submitting
- [x] 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?
- [x] 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. (Issue #43531)
- [ ] 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? 


Changed files:
filename: src/transformers/models/qwen3_omni_moe/configuration_qwen3_omni_moe.py
patch: @@ -572,6 +572,7 @@ def __init__(
         rope_parameters: int | None = None,
         attention_bias: bool | None = False,
         sliding_window: int | None = None,
+        max_window_layers: int | None = 28,
         layer_types: list[str] | None = None,
         attention_dropout: int | None = 0,
         num_code_groups: int | None = 32,
@@ -580,15 +581,15 @@ def __init__(
         eos_token_id: int | None = None,
         **kwargs,
     ):
-        self.sliding_window = sliding_window
         self.num_code_groups = num_code_groups
         self.vocab_size = vocab_size
         self.max_position_embeddings = max_position_embeddings
         self.hidden_size = hidden_size
         self.intermediate_size = intermediate_size
         self.num_hidden_layers = num_hidden_layers
         self.num_attention_heads = num_attention_heads
-        self.sliding_window = sliding_window if self.use_sliding_window else None
+        self.sliding_window = sliding_window
+        self.max_window_layers = max_window_layers
 
         # for backward compatibility
         if num_key_value_heads is None:

filename: src/transformers/models/qwen3_omni_moe/modular_qwen3_omni_moe.py
patch: @@ -464,6 +464,7 @@ def __init__(
         rope_parameters: int | None = None,
         attention_bias: bool | None = False,
         sliding_window: int | None = None,
+        max_window_layers: int | None = 28,
         layer_types: list[str] | None = None,
         attention_dropout: int | None = 0,
         num_code_groups: int | None = 32,
@@ -472,7 +473,6 @@ def __init__(
         eos_token_id: int | None = None,
         **kwargs,
     ):
-        self.sliding_window = sliding_window
         self.num_code_groups = num_code_groups
         super().__init__(
             vocab_size,
@@ -501,7 +501,8 @@ def __init__(
             **kwargs,
         )
         del self.use_sliding_window
-        del self.max_window_layers
+        self.sliding_window = sliding_window
+        self.max_window_layers = max_window_layers
 
 
 class Qwen3OmniMoeTalkerTextConfig(Qwen3MoeConfig):

filename: tests/models/qwen3_omni_moe/test_modeling_qwen3_omni_moe.py
patch: @@ -31,6 +31,7 @@
     is_torch_available,
     is_vision_available,
 )
+from transformers.models.qwen3_omni_moe.configuration_qwen3_omni_moe import Qwen3OmniMoeTalkerCodePredictorConfig
 from transformers.testing_utils import (
     Expectations,
     cleanup,
@@ -648,6 +649,31 @@ def _video_features_get_expected_num_hidden_states(self, model_tester=None):
             model_tester = self.model_tester
         return model_tester.vision_config["depth"] + 1
 
+    def test_code_predictor_config_init(self):
+        """
+        Test that Qwen3OmniMoeTalkerCodePredictorConfig initializes correctly
+        and accepts max_window_layers while removing use_sliding_window.
+        """
+
+        config = Qwen3OmniMoeTalkerCodePredictorConfig(
+            vocab_size=100,
+            hidden_size=32,
+            num_hidden_layers=2,
+            num_attention_heads=4,
+            max_window_layers=28,
+            sliding_window=2048,
+        )
+
+        # 1. Check max_window_layers is present
+        self.assertEqual(config.max_window_layers, 28)
+
+        # 2. Check sliding_window is present
+        self.assertEqual(config.sliding_window, 2048)
+
+        # 3. Check use_sliding_window is removed
+        with self.assertRaises(AttributeError):
+            _ = config.use_sliding_window
+
 
 @require_torch
 class Qwen3OmniModelIntegrationTest(unittest.TestCase):