configuration_fuyu.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright 2023 Adept AI and the HuggingFace Inc. team. All rights reserved.
  2. #
  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. """Fuyu model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...modeling_rope_utils import RopeParameters
  18. from ...utils import auto_docstring, logging
  19. from ..auto import CONFIG_MAPPING, AutoConfig
  20. logger = logging.get_logger(__name__)
  21. @auto_docstring(checkpoint="adept/fuyu-8b")
  22. @strict
  23. class FuyuConfig(PreTrainedConfig):
  24. r"""
  25. Example:
  26. ```python
  27. >>> from transformers import FuyuConfig
  28. >>> # Initializing a Fuyu fuyu-7b style configuration
  29. >>> configuration = FuyuConfig()
  30. ```"""
  31. model_type = "fuyu"
  32. sub_configs = {"text_config": AutoConfig}
  33. keys_to_ignore_at_inference = ["past_key_values"]
  34. default_theta = 25000.0
  35. vocab_size: int = 262144
  36. hidden_size: int = 4096
  37. intermediate_size: int = 16384
  38. num_hidden_layers: int = 36
  39. num_attention_heads: int = 64
  40. hidden_act: str = "relu2"
  41. max_position_embeddings: int = 16384
  42. image_size: int | None = 300
  43. patch_size: int | None = 30
  44. num_channels: int | None = 3
  45. initializer_range: float = 0.02
  46. layer_norm_eps: float | None = 1e-5
  47. use_cache: bool = True
  48. tie_word_embeddings: bool = False
  49. rope_parameters: RopeParameters | dict | None = None
  50. qk_layernorm: bool | None = True
  51. hidden_dropout: float | int | None = 0.0
  52. attention_dropout: float | int | None = 0.0
  53. pad_token_id: int | None = None
  54. bos_token_id: int | None = 1
  55. eos_token_id: int | list[int] | None = 2
  56. image_token_id: int | None = 71011
  57. text_config: dict | PreTrainedConfig | None = None
  58. def __post_init__(self, **kwargs):
  59. if self.text_config is None:
  60. text_config = {
  61. "vocab_size": self.vocab_size,
  62. "max_position_embeddings": self.max_position_embeddings,
  63. "hidden_size": self.hidden_size,
  64. "intermediate_size": self.intermediate_size,
  65. "num_hidden_layers": self.num_hidden_layers,
  66. "num_attention_heads": self.num_attention_heads,
  67. "hidden_act": self.hidden_act,
  68. "initializer_range": self.initializer_range,
  69. "layer_norm_eps": self.layer_norm_eps,
  70. "use_cache": self.use_cache,
  71. "rope_parameters": self.rope_parameters,
  72. "qk_layernorm": self.qk_layernorm,
  73. "hidden_dropout": self.hidden_dropout,
  74. "attention_dropout": self.attention_dropout,
  75. "pad_token_id": self.pad_token_id,
  76. "bos_token_id": self.bos_token_id,
  77. "eos_token_id": self.eos_token_id,
  78. }
  79. logger.info("text_config is None. initializing the text model with default values.")
  80. self.text_config = CONFIG_MAPPING["persimmon"](**text_config)
  81. elif isinstance(self.text_config, dict):
  82. text_model_type = self.text_config.get("model_type", "persimmon")
  83. self.text_config = CONFIG_MAPPING[text_model_type](**self.text_config)
  84. kwargs.setdefault("partial_rotary_factor", 0.5) # assign default for BC
  85. super().__post_init__(**kwargs)
  86. __all__ = ["FuyuConfig"]