code: 
  
  
  from collections import OrderedDict
  from typing import Any, List, Mapping, Optional
  
  from ... import PreTrainedTokenizer, TensorType, is_torch_available
  from ...configuration_utils import PretrainedConfig
  from ...onnx import OnnxConfigWithPast, PatchingSpec
  from ...utils import logging
  
  
  SCREAMING_SNAKE_CASE__				:    str         =    logging.get_logger(__name__)
  
  SCREAMING_SNAKE_CASE__				:    str         =    {
      'gpt2': 'https://huggingface.co/gpt2/resolve/main/config.json',
      'gpt2-medium': 'https://huggingface.co/gpt2-medium/resolve/main/config.json',
      'gpt2-large': 'https://huggingface.co/gpt2-large/resolve/main/config.json',
      'gpt2-xl': 'https://huggingface.co/gpt2-xl/resolve/main/config.json',
      'distilgpt2': 'https://huggingface.co/distilgpt2/resolve/main/config.json',
  }
  
  
  class 		_SCREAMING_SNAKE_CASE    (	A    ):
       __SCREAMING_SNAKE_CASE    				=						'''gpt2'''
       __SCREAMING_SNAKE_CASE    				=						['''past_key_values''']
       __SCREAMING_SNAKE_CASE    				=						{
           '''hidden_size''': '''n_embd''',
           '''max_position_embeddings''': '''n_positions''',
           '''num_attention_heads''': '''n_head''',
           '''num_hidden_layers''': '''n_layer''',
       }
  
  
       def __init__(     self       ,				A_=5_02_57       ,				A_=10_24       ,				A_=7_68       ,				A_=12       ,				A_=12       ,				A_=None       ,				A_="gelu_new"       ,				A_=0.1       ,				A_=0.1       ,				A_=0.1       ,				A_=1e-5       ,				A_=0.0_2       ,				A_="cls_index"       ,				A_=True       ,				A_=None       ,				A_=True       ,				A_=0.1       ,				A_=True       ,				A_=True       ,				A_=5_02_56       ,				A_=5_02_56       ,				A_=False       ,				A_=False       ,				**A_       ,				):
         _UpperCAmelCase		:       List[Any]       =    vocab_size
         _UpperCAmelCase		:       Union[str, Any]       =    n_positions
         _UpperCAmelCase		:       Optional[int]       =    n_embd
         _UpperCAmelCase		:       int       =    n_layer
         _UpperCAmelCase		:       Dict       =    n_head
         _UpperCAmelCase		:       Tuple       =    n_inner
         _UpperCAmelCase		:       int       =    activation_function
         _UpperCAmelCase		:       str       =    resid_pdrop
         _UpperCAmelCase		:       str       =    embd_pdrop
         _UpperCAmelCase		:       List[Any]       =    attn_pdrop
         _UpperCAmelCase		:       Any       =    layer_norm_epsilon
         _UpperCAmelCase		:       Union[str, Any]       =    initializer_range
         _UpperCAmelCase		:       List[Any]       =    summary_type
         _UpperCAmelCase		:       str       =    summary_use_proj
         _UpperCAmelCase		:       Any       =    summary_activation
         _UpperCAmelCase		:       Any       =    summary_first_dropout
         _UpperCAmelCase		:       List[Any]       =    summary_proj_to_labels
         _UpperCAmelCase		:       Optional[int]       =    scale_attn_weights
         _UpperCAmelCase		:       str       =    use_cache
         _UpperCAmelCase		:       Dict       =    scale_attn_by_inverse_layer_idx
         _UpperCAmelCase		:       List[str]       =    reorder_and_upcast_attn
  
         _UpperCAmelCase		:       Optional[Any]       =    bos_token_id
         _UpperCAmelCase		:       Dict       =    eos_token_id
  
         super().__init__(bos_token_id=A_       ,				eos_token_id=A_       ,				**A_						)
  
  
  class 		_SCREAMING_SNAKE_CASE    (	A    ):
  
  
       def __init__(     self       ,				A_       ,				A_ = "default"       ,				A_ = None       ,				A_ = False       ,				):
         super().__init__(A_       ,				task=A_       ,				patching_specs=A_       ,				use_past=A_						)
         if not getattr(self._config       ,				"""pad_token_id"""       ,				A_						):
           # TODO: how to do that better?
           _UpperCAmelCase		:       Optional[int]       =    0
  
  
       @property
       def 					__snake_case(     self						):
         _UpperCAmelCase		:       Optional[int]       =    OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}}						)
         if self.use_past:
           self.fill_with_past_key_values_(A_       ,				direction="""inputs"""						)
           _UpperCAmelCase		:       List[str]       =    {0: """batch""", 1: """past_sequence + sequence"""}
         else:
           _UpperCAmelCase		:       Optional[Any]       =    {0: """batch""", 1: """sequence"""}
  
         return common_inputs
  
  
       @property
       def 					__snake_case(     self						):
         return self._config.n_layer
  
  
       @property
       def 					__snake_case(     self						):
         return self._config.n_head
  
  
       def 					__snake_case(     self       ,				A_       ,				A_ = -1       ,				A_ = -1       ,				A_ = False       ,				A_ = None       ,				):
         _UpperCAmelCase		:       Tuple       =    super(A_       ,				self						).generate_dummy_inputs(
             A_       ,				batch_size=A_       ,				seq_length=A_       ,				is_pair=A_       ,				framework=A_						)
  
         # We need to order the input in the way they appears in the forward()
         _UpperCAmelCase		:       Optional[int]       =    OrderedDict({"""input_ids""": common_inputs["""input_ids"""]}						)
  
         # Need to add the past_keys
         if self.use_past:
           if not is_torch_available():
             raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""						)
           else:
             import torch
  
             _UpperCAmelCase,_UpperCAmelCase		:       int       =    common_inputs["""input_ids"""].shape
             # Not using the same length for past_key_values
             _UpperCAmelCase		:       Optional[int]       =    seqlen + 2
             _UpperCAmelCase		:       List[Any]       =    (
                 batch,
                 self.num_attention_heads,
                 past_key_values_length,
                 self._config.hidden_size // self.num_attention_heads,
             )
             _UpperCAmelCase		:       Any       =    [
                 (torch.zeros(A_						), torch.zeros(A_						)) for _ in range(self.num_layers						)
             ]
  
         _UpperCAmelCase		:       str       =    common_inputs["""attention_mask"""]
         if self.use_past:
           _UpperCAmelCase		:       Dict       =    ordered_inputs["""attention_mask"""].dtype
           _UpperCAmelCase		:       Any       =    torch.cat(
               [ordered_inputs["""attention_mask"""], torch.ones(A_       ,				A_       ,				dtype=A_						)]       ,				dim=1						)
  
         return ordered_inputs
  
  
  
  
       @property
       def 					__snake_case(     self						):
         return 13
  
  
  
  
  
  
style_context: 
  
  
  from dataclasses import dataclass
  from enum import Enum
  from typing import List, Optional, Union
  
  import numpy as np
  import PIL
  from PIL import Image
  
  from ...utils import BaseOutput, is_torch_available, is_transformers_available
  
  
  @dataclass
  class 		_SCREAMING_SNAKE_CASE    (	A    ):
       __SCREAMING_SNAKE_CASE    				=						{
           '''sld_warmup_steps''': 1_5,
           '''sld_guidance_scale''': 2_0,
           '''sld_threshold''': 0.0,
           '''sld_momentum_scale''': 0.0,
           '''sld_mom_beta''': 0.0,
       }
       __SCREAMING_SNAKE_CASE    				=						{
           '''sld_warmup_steps''': 1_0,
           '''sld_guidance_scale''': 1_0_0_0,
           '''sld_threshold''': 0.01,
           '''sld_momentum_scale''': 0.3,
           '''sld_mom_beta''': 0.4,
       }
       __SCREAMING_SNAKE_CASE    				=						{
           '''sld_warmup_steps''': 7,
           '''sld_guidance_scale''': 2_0_0_0,
           '''sld_threshold''': 0.025,
           '''sld_momentum_scale''': 0.5,
           '''sld_mom_beta''': 0.7,
       }
       __SCREAMING_SNAKE_CASE    				=						{
           '''sld_warmup_steps''': 0,
           '''sld_guidance_scale''': 5_0_0_0,
           '''sld_threshold''': 1.0,
           '''sld_momentum_scale''': 0.5,
           '''sld_mom_beta''': 0.7,
       }
  
  
  @dataclass
  class 		_SCREAMING_SNAKE_CASE    (	A    ):
       __SCREAMING_SNAKE_CASE    				=						42
       __SCREAMING_SNAKE_CASE    				=						42
       __SCREAMING_SNAKE_CASE    				=						42
       __SCREAMING_SNAKE_CASE    				=						42
  
  
  if is_transformers_available() and is_torch_available():
   from .pipeline_stable_diffusion_safe import StableDiffusionPipelineSafe
   from .safety_checker import SafeStableDiffusionSafetyChecker
  
  
  
  
  
  