configuration_imagegpt.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright 2021 The HuggingFace Inc. team.
  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. """OpenAI ImageGPT configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="openai/imagegpt-small")
  19. @strict
  20. class ImageGPTConfig(PreTrainedConfig):
  21. r"""
  22. scale_attn_by_inverse_layer_idx (`bool`, *optional*, defaults to `False`):
  23. Whether to additionally scale attention weights by `1 / layer_idx + 1`.
  24. reorder_and_upcast_attn (`bool`, *optional*, defaults to `False`):
  25. Whether to scale keys (K) prior to computing attention (dot-product) and upcast attention
  26. dot-product/softmax to float() when training with mixed precision.
  27. Example:
  28. ```python
  29. >>> from transformers import ImageGPTConfig, ImageGPTModel
  30. >>> # Initializing a ImageGPT configuration
  31. >>> configuration = ImageGPTConfig()
  32. >>> # Initializing a model (with random weights) from the configuration
  33. >>> model = ImageGPTModel(configuration)
  34. >>> # Accessing the model configuration
  35. >>> configuration = model.config
  36. ```"""
  37. model_type = "imagegpt"
  38. keys_to_ignore_at_inference = ["past_key_values"]
  39. attribute_map = {
  40. "hidden_size": "n_embd",
  41. "max_position_embeddings": "n_positions",
  42. "num_attention_heads": "n_head",
  43. "num_hidden_layers": "n_layer",
  44. }
  45. vocab_size: int = 512 + 1 # add one for start of sentence (sos) token
  46. n_positions: int = 32 * 32
  47. n_embd: int = 512
  48. n_layer: int = 24
  49. n_head: int = 8
  50. n_inner: int | None = None
  51. activation_function: str = "quick_gelu"
  52. resid_pdrop: float | int = 0.1
  53. embd_pdrop: float | int = 0.1
  54. attn_pdrop: float | int = 0.1
  55. layer_norm_epsilon: float = 1e-5
  56. initializer_range: float = 0.02
  57. scale_attn_weights: bool = True
  58. use_cache: bool = True
  59. tie_word_embeddings: bool = False
  60. scale_attn_by_inverse_layer_idx: bool = False
  61. reorder_and_upcast_attn: bool = False
  62. add_cross_attention: bool = False
  63. pad_token_id: int | None = None
  64. bos_token_id: int | None = None
  65. eos_token_id: int | list[int] | None = None
  66. __all__ = ["ImageGPTConfig"]