configuration_pixtral.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # coding=utf-8
  2. # Copyright 2024 HuggingFace Inc. team. All rights reserved.
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Pixtral model configuration"""
  15. from ...configuration_utils import PretrainedConfig
  16. from ...utils import logging
  17. logger = logging.get_logger(__name__)
  18. class PixtralVisionConfig(PretrainedConfig):
  19. r"""
  20. This is the configuration class to store the configuration of a [`PixtralVisionModel`]. It is used to instantiate an
  21. Pixtral vision encoder according to the specified arguments, defining the model architecture. Instantiating a configuration
  22. with the defaults will yield a similar configuration to the vision encoder used by Pixtral-12B.
  23. e.g. [pixtral-hf/pixtral-9b](https://huggingface.co/pixtral-hf/pixtral-9b)
  24. Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
  25. documentation from [`PretrainedConfig`] for more information.
  26. Args:
  27. hidden_size (`int`, *optional*, defaults to 1024):
  28. Dimension of the hidden representations.
  29. intermediate_size (`int`, *optional*, defaults to 4096):
  30. Dimension of the MLP representations.
  31. num_hidden_layers (`int`, *optional*, defaults to 24):
  32. Number of hidden layers in the Transformer encoder.
  33. num_attention_heads (`int`, *optional*, defaults to 16):
  34. Number of attention heads in the Transformer encoder.
  35. num_channels (`int`, *optional*, defaults to 3):
  36. Number of input channels in the input images.
  37. image_size (`int`, *optional*, defaults to 1024):
  38. Max dimension of the input images.
  39. patch_size (`int`, *optional*, defaults to 16):
  40. Size of the image patches.
  41. hidden_act (`str`, *optional*, defaults to `"gelu"`):
  42. Activation function used in the hidden layers.
  43. attention_dropout (`float`, *optional*, defaults to 0.0):
  44. Dropout probability for the attention layers.
  45. rope_theta (`float`, *optional*, defaults to 10000.0):
  46. The base period of the RoPE embeddings.
  47. initializer_range (`float`, *optional*, defaults to 0.02):
  48. The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
  49. Example:
  50. ```python
  51. >>> from transformers import PixtralVisionModel, PixtralVisionConfig
  52. >>> # Initializing a Pixtral-12B style configuration
  53. >>> config = PixtralVisionConfig()
  54. >>> # Initializing a model (with randomly initialized weights) from the configuration
  55. >>> model = PixtralVisionModel(configuration)
  56. >>> # Accessing the model configuration
  57. >>> configuration = model.config
  58. ```"""
  59. model_type = "pixtral"
  60. def __init__(
  61. self,
  62. hidden_size=1024,
  63. intermediate_size=4096,
  64. num_hidden_layers=24,
  65. num_attention_heads=16,
  66. num_channels=3,
  67. image_size=1024,
  68. patch_size=16,
  69. hidden_act="gelu",
  70. attention_dropout=0.0,
  71. rope_theta=10000.0,
  72. initializer_range=0.02,
  73. **kwargs,
  74. ):
  75. super().__init__(**kwargs)
  76. self.hidden_size = hidden_size
  77. self.intermediate_size = intermediate_size
  78. self.num_hidden_layers = num_hidden_layers
  79. self.num_attention_heads = num_attention_heads
  80. self.num_channels = num_channels
  81. self.patch_size = patch_size
  82. self.image_size = image_size
  83. self.attention_dropout = attention_dropout
  84. self.hidden_act = hidden_act
  85. self.rope_theta = rope_theta
  86. self.head_dim = hidden_size // num_attention_heads
  87. self.initializer_range = initializer_range
  88. __all__ = ["PixtralVisionConfig"]