Repository: huggingface/transformers
File: src/transformers/models/gpt_oss/configuration_gpt_oss.py (Python)

Code before:
        self.num_key_value_heads = num_key_value_heads
        self.hidden_act = hidden_act
        self.initializer_range = initializer_range
        self.rms_norm_eps = rms_norm_eps
        self.attention_dropout = attention_dropout
        self.head_dim = head_dim if head_dim is not None else self.hidden_size // self.num_attention_heads
        self.layer_types = layer_types
        if self.layer_types is None:
            self.layer_types = [
                "sliding_attention" if bool((i + 1) % 2) else "full_attention" for i in range(self.num_hidden_layers)
            ]
        layer_type_validation(self.layer_types, self.num_hidden_layers)

        self.attention_bias = True
        self.max_position_embeddings = max_position_embeddings
        self.router_aux_loss_coef = router_aux_loss_coef
        self.output_router_logits = output_router_logits
        self.use_cache = use_cache
        self.rope_parameters = rope_parameters

        super().__init__(
            tie_word_embeddings=tie_word_embeddings,
            **kwargs,
        )


__all__ = ["GptOssConfig"]


Review comment (suggestion):
I had to overwrite the setter instead of the property, see the reasons below - tldr is that we have a method that sets the internal attribute which would not be considered with that. 

Code after:
        self.num_key_value_heads = num_key_value_heads
        self.hidden_act = hidden_act
        self.initializer_range = initializer_range
        self.rms_norm_eps = rms_norm_eps
        self.attention_dropout = attention_dropout
        self.head_dim = head_dim if head_dim is not None else self.hidden_size // self.num_attention_heads
        self.layer_types = layer_types
        if self.layer_types is None:
            self.layer_types = [
                "sliding_attention" if bool((i + 1) % 2) else "full_attention" for i in range(self.num_hidden_layers)
            ]
        layer_type_validation(self.layer_types, self.num_hidden_layers)

        self.attention_bias = True
        self.max_position_embeddings = max_position_embeddings
        self.router_aux_loss_coef = router_aux_loss_coef
        self.output_router_logits = output_router_logits
        self.use_cache = use_cache
        self.rope_parameters = rope_parameters

        super().__init__(
            tie_word_embeddings=tie_word_embeddings,
            **kwargs,
        )

    def __setattr__(self, key, value):
        """
        Overwritten to allow checking for the proper attention implementation to be used.

        Due to `set_attn_implementation` which internally assigns `_attn_implementation_internal = "..."`, simply overwriting
        the specific attention setter is not enough. Using a property/setter for `_attn_implementation_internal` would result in
        a recursive dependency (as `_attn_implementation` acts as a wrapper around `_attn_implementation_internal`) - hence, this
        workaround.
        """
        if key in ("_attn_implementation", "_attn_implementation_internal"):
            if value and "flash" in value and value.removeprefix("paged|") != "kernels-community/vllm-flash-attn3":
                raise ValueError(
                    f"GPT-OSS model does not support the specified flash attention implementation: {value}. "
                    "Only `kernels-community/vllm-flash-attn3` is supported."
                )
        super().__setattr__(key, value)


__all__ = ["GptOssConfig"]