"""simple docstring"""






import numpy as np
import torch
from imwatermark import WatermarkEncoder


# Copied from https://github.com/Stability-AI/generative-models/blob/613af104c6b85184091d42d374fef420eddb356d/scripts/demo/streamlit_helpers.py#L66
__lowerCAmelCase    :       Union[str, Any]					     =0B1011_0011_1110_1100_1001_0000_0111_1011_1011_0001_1001_1110
# bin(x)[2:] gives bits of x as str, use int to convert them to 0/1
__lowerCAmelCase    :       Optional[int]					     =[int(bit) for bit in bin(WATERMARK_MESSAGE)[2:]]





class  _A						:

      def __init__(						self						):







            """simple docstring"""



            lowercase														=	WATERMARK_BITS
            lowercase														=	WatermarkEncoder()

            self.encoder.set_watermark("""bits"""		,       self.watermark						)







      def 				A__       (						self		,       __lowerCAmelCase						):







            """simple docstring"""



            if images.shape[-1] < 256:
                  return images

            lowercase														=	(255 * (images / 2 + 0.5)).cpu().permute(0		,       2		,       3		,       1						).float().numpy()

            lowercase														=	[self.encoder.encode(__lowerCAmelCase		,       """dwtDct"""						) for image in images]

            lowercase														=	torch.from_numpy(np.array(__lowerCAmelCase						)						).permute(0		,       3		,       1		,       2						)

            lowercase														=	torch.clamp(2 * (images / 255 - 0.5)		,       min=-1.0		,       max=1.0						)
            return images




"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCAmelCase    :       List[Any]					     =logging.get_logger(__name__)

__lowerCAmelCase    :       Union[str, Any]					     ={
    """s-JoL/Open-Llama-V1""": """https://huggingface.co/s-JoL/Open-Llama-V1/blob/main/config.json""",
}





class  _A						(       lowerCAmelCase	):
      snake_case__			:   Union[str, Any]							  =	'open-llama'

      def __init__(						self		,       __lowerCAmelCase=10_0000		,       __lowerCAmelCase=4096		,       __lowerCAmelCase=1_1008		,       __lowerCAmelCase=32		,       __lowerCAmelCase=32		,       __lowerCAmelCase="silu"		,       __lowerCAmelCase=2048		,       __lowerCAmelCase=0.0_2		,       __lowerCAmelCase=1E-6		,       __lowerCAmelCase=True		,       __lowerCAmelCase=0		,       __lowerCAmelCase=1		,       __lowerCAmelCase=2		,       __lowerCAmelCase=False		,       __lowerCAmelCase=True		,       __lowerCAmelCase=0.1		,       __lowerCAmelCase=0.1		,       __lowerCAmelCase=True		,       __lowerCAmelCase=True		,       __lowerCAmelCase=None		,       **__lowerCAmelCase		,       ):







            """simple docstring"""



            lowercase														=	vocab_size
            lowercase														=	max_position_embeddings
            lowercase														=	hidden_size
            lowercase														=	intermediate_size
            lowercase														=	num_hidden_layers
            lowercase														=	num_attention_heads
            lowercase														=	hidden_act
            lowercase														=	initializer_range
            lowercase														=	rms_norm_eps
            lowercase														=	use_cache
            lowercase														=	kwargs.pop(
                """use_memorry_efficient_attention"""		,       __lowerCAmelCase						)
            lowercase														=	hidden_dropout_prob
            lowercase														=	attention_dropout_prob
            lowercase														=	use_stable_embedding
            lowercase														=	shared_input_output_embedding
            lowercase														=	rope_scaling
            self._rope_scaling_validation()

            super().__init__(
                pad_token_id=__lowerCAmelCase		,       bos_token_id=__lowerCAmelCase		,       eos_token_id=__lowerCAmelCase		,       tie_word_embeddings=__lowerCAmelCase		,       **__lowerCAmelCase		,       )







      def 				A__       (						self						):







            """simple docstring"""



            if self.rope_scaling is None:
                  return

            if not isinstance(self.rope_scaling		,       __lowerCAmelCase						) or len(self.rope_scaling						) != 2:
                  raise ValueError(
                      """`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, """
                      f'got {self.rope_scaling}'						)
            lowercase														=	self.rope_scaling.get("""type"""		,       __lowerCAmelCase						)
            lowercase														=	self.rope_scaling.get("""factor"""		,       __lowerCAmelCase						)
            if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
                  raise ValueError(
                      f'`rope_scaling`\'s name field must be one of [\'linear\', \'dynamic\'], got {rope_scaling_type}'						)
            if rope_scaling_factor is None or not isinstance(__lowerCAmelCase		,       __lowerCAmelCase						) or rope_scaling_factor <= 1.0:
                  raise ValueError(f'`rope_scaling`\'s factor field must be an float > 1, got {rope_scaling_factor}'						)



