



'''simple docstring'''





import argparse
import hashlib  # hashlib is only used inside the Test class
import struct


class 				snake_case :



       def __init__(				self     ,UpperCAmelCase_      )  ->							List[str]:
           lowercase__		       =						data
           lowercase__		       =						[0X6_7_4_5_2_3_0_1, 0Xe_f_c_d_a_b_8_9, 0X9_8_b_a_d_c_f_e, 0X1_0_3_2_5_4_7_6, 0Xc_3_d_2_e_1_f_0]



       @staticmethod
       def 							_a      (				UpperCAmelCase_     ,UpperCAmelCase_      )  ->							List[Any]:
           return ((n << b) | (n >> (32 - b))) & 0Xf_f_f_f_f_f_f_f



       def 							_a      (				self      )  ->							Union[str, Any]:
           lowercase__		       =						b"\x80" + b"\x00" * (63 - (len(self.data      ) + 8) % 64)
           lowercase__		       =						self.data + padding + struct.pack(">Q"     ,8 * len(self.data      )      )
           return padded_data



       def 							_a      (				self      )  ->							List[Any]:
           return [
               self.padded_data[i : i + 64] for i in range(0     ,len(self.padded_data      )     ,64      )
           ]



       def 							_a      (				self     ,UpperCAmelCase_      )  ->							int:
           lowercase__		       =						list(struct.unpack(">16L"     ,UpperCAmelCase_      )      ) + [0] * 64
           for i in range(16     ,80      ):
               lowercase__		       =						self.rotate((w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16])     ,1      )
           return w







       def 							_a      (				self      )  ->							int:
           lowercase__		       =						self.padding()
           lowercase__		       =						self.split_blocks()
           for block in self.blocks:
               lowercase__		       =						self.expand_block(UpperCAmelCase_      )
               lowercase__       ,       lowercase__       ,       lowercase__       ,       lowercase__       ,       lowercase__		       =						self.h
               for i in range(0     ,80      ):
                   if 0 <= i < 20:
                       lowercase__		       =						(b & c) | ((~b) & d)
                       lowercase__		       =						0X5_a_8_2_7_9_9_9
                   elif 20 <= i < 40:
                       lowercase__		       =						b ^ c ^ d
                       lowercase__		       =						0X6_e_d_9_e_b_a_1
                   elif 40 <= i < 60:
                       lowercase__		       =						(b & c) | (b & d) | (c & d)
                       lowercase__		       =						0X8_f_1_b_b_c_d_c
                   elif 60 <= i < 80:
                       lowercase__		       =						b ^ c ^ d
                       lowercase__		       =						0Xc_a_6_2_c_1_d_6
                   lowercase__       ,       lowercase__       ,       lowercase__       ,       lowercase__       ,       lowercase__		       =						(
                       self.rotate(UpperCAmelCase_     ,5      ) + f + e + k + expanded_block[i] & 0Xf_f_f_f_f_f_f_f,
                       a,
                       self.rotate(UpperCAmelCase_     ,30      ),
                       c,
                       d,
                   )
               lowercase__		       =						(
                   self.h[0] + a & 0Xf_f_f_f_f_f_f_f,
                   self.h[1] + b & 0Xf_f_f_f_f_f_f_f,
                   self.h[2] + c & 0Xf_f_f_f_f_f_f_f,
                   self.h[3] + d & 0Xf_f_f_f_f_f_f_f,
                   self.h[4] + e & 0Xf_f_f_f_f_f_f_f,
               )
           return ("{:08x}" * 5).format(*self.h      )





def        lowerCamelCase  (				):





    '''simple docstring'''


    lowercase__		       =						B"Test String"
    assert SHAaHash(_snake_case       ).final_hash() == hashlib.shaa(_snake_case       ).hexdigest()  # noqa: S324




def        lowerCamelCase  (				):





    '''simple docstring'''


    lowercase__		       =						argparse.ArgumentParser(description="Process some strings or files"       )
    parser.add_argument(
        "--string"     ,dest="input_string"     ,default="Hello World!! Welcome to Cryptography"     ,help="Hash the string"     ,)
    parser.add_argument("--file"     ,dest="input_file"     ,help="Hash contents of a file"       )
    lowercase__		       =						parser.parse_args()
    lowercase__		       =						args.input_string
    # In any case hash input should be a bytestring
    if args.input_file:
        with open(args.input_file     ,"rb"       ) as f:
            lowercase__		       =						f.read()
    else:
        lowercase__		       =						bytes(_snake_case     ,"utf-8"       )
    print(SHAaHash(_snake_case       ).final_hash()       )


if __name__ == "__main__":
 main()
 import doctest

 doctest.testmod()









'''simple docstring'''





import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DPMSolverMultistepScheduler,
    TextToVideoSDPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import is_xformers_available, load_numpy, skip_mps, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()


@skip_mps
class 				snake_case (UpperCamelCase		,      unittest.TestCase   ):
       lowerCAmelCase__  :int						   =					TextToVideoSDPipeline
       lowerCAmelCase__  :Union[str, Any]						   =					TEXT_TO_IMAGE_PARAMS
       lowerCAmelCase__  :List[str]						   =					TEXT_TO_IMAGE_BATCH_PARAMS
       # No `output_type`.
       lowerCAmelCase__  :Optional[Any]						   =					frozenset(
           [
               "num_inference_steps",
               "generator",
               "latents",
               "return_dict",
               "callback",
               "callback_steps",
           ]   )



       def 							_a      (				self      )  ->							Optional[int]:
           torch.manual_seed(0      )
           lowercase__		       =						UNetaDConditionModel(
               block_out_channels=(32, 64, 64, 64)     ,layers_per_block=2     ,sample_size=32     ,in_channels=4     ,out_channels=4     ,down_block_types=("CrossAttnDownBlock3D", "CrossAttnDownBlock3D", "CrossAttnDownBlock3D", "DownBlock3D")     ,up_block_types=("UpBlock3D", "CrossAttnUpBlock3D", "CrossAttnUpBlock3D", "CrossAttnUpBlock3D")     ,cross_attention_dim=32     ,attention_head_dim=4     ,)
           lowercase__		       =						DDIMScheduler(
               beta_start=0.0_00_85     ,beta_end=0.0_12     ,beta_schedule="scaled_linear"     ,clip_sample=UpperCAmelCase_     ,set_alpha_to_one=UpperCAmelCase_     ,)
           torch.manual_seed(0      )
           lowercase__		       =						AutoencoderKL(
               block_out_channels=[32, 64]     ,in_channels=3     ,out_channels=3     ,down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]     ,up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]     ,latent_channels=4     ,sample_size=128     ,)
           torch.manual_seed(0      )
           lowercase__		       =						CLIPTextConfig(
               bos_token_id=0     ,eos_token_id=2     ,hidden_size=32     ,intermediate_size=37     ,layer_norm_eps=1E-0_5     ,num_attention_heads=4     ,num_hidden_layers=5     ,pad_token_id=1     ,vocab_size=1_000     ,hidden_act="gelu"     ,projection_dim=512     ,)
           lowercase__		       =						CLIPTextModel(UpperCAmelCase_      )
           lowercase__		       =						CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"      )

           lowercase__		       =						{
               "unet": unet,
               "scheduler": scheduler,
               "vae": vae,
               "text_encoder": text_encoder,
               "tokenizer": tokenizer,
           }
           return components



       def 							_a      (				self     ,UpperCAmelCase_     ,UpperCAmelCase_=0      )  ->							int:
           if str(UpperCAmelCase_      ).startswith("mps"      ):
               lowercase__		       =						torch.manual_seed(UpperCAmelCase_      )
           else:
               lowercase__		       =						torch.Generator(device=UpperCAmelCase_      ).manual_seed(UpperCAmelCase_      )
           lowercase__		       =						{
               "prompt": "A painting of a squirrel eating a burger",
               "generator": generator,
               "num_inference_steps": 2,
               "guidance_scale": 6.0,
               "output_type": "pt",
           }
           return inputs



       def 							_a      (				self      )  ->							Tuple:
           lowercase__		       =						"cpu"  # ensure determinism for the device-dependent torch.Generator
           lowercase__		       =						self.get_dummy_components()
           lowercase__		       =						TextToVideoSDPipeline(**UpperCAmelCase_      )
           lowercase__		       =						sd_pipe.to(UpperCAmelCase_      )
           sd_pipe.set_progress_bar_config(disable=UpperCAmelCase_      )

           lowercase__		       =						self.get_dummy_inputs(UpperCAmelCase_      )
           lowercase__		       =						"np"
           lowercase__		       =						sd_pipe(**UpperCAmelCase_      ).frames
           lowercase__		       =						frames[0][-3:, -3:, -1]

           assert frames[0].shape == (64, 64, 3)
           lowercase__		       =						np.array([1_58.0, 1_60.0, 1_53.0, 1_25.0, 1_00.0, 1_21.0, 1_11.0, 93.0, 1_13.0]      )

           assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1E-2



       def 							_a      (				self      )  ->							List[Any]:
           self._test_attention_slicing_forward_pass(test_mean_pixel_difference=UpperCAmelCase_     ,expected_max_diff=3E-3      )



       @unittest.skipIf(
           torch_device != "cuda" or not is_xformers_available()     ,reason="XFormers attention is only available with CUDA and `xformers` installed"     ,)
       def 							_a      (				self      )  ->							Dict:
           self._test_xformers_attention_forwardGenerator_pass(test_mean_pixel_difference=UpperCAmelCase_     ,expected_max_diff=1E-2      )



       @unittest.skip(reason="Batching needs to be properly figured out first for this pipeline."      )
       def 							_a      (				self      )  ->							Union[str, Any]:
           pass



       @unittest.skip(reason="Batching needs to be properly figured out first for this pipeline."      )
       def 							_a      (				self      )  ->							Union[str, Any]:
           pass



       @unittest.skip(reason="`num_images_per_prompt` argument is not supported for this pipeline."      )
       def 							_a      (				self      )  ->							Union[str, Any]:
           pass







       def 							_a      (				self      )  ->							str:
           return super().test_progress_bar()





@slow
@skip_mps
class 				snake_case (unittest.TestCase   ):



       def 							_a      (				self      )  ->							Optional[int]:
           lowercase__		       =						load_numpy(
               "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text_to_video/video.npy"      )

           lowercase__		       =						TextToVideoSDPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b"      )
           lowercase__		       =						DPMSolverMultistepScheduler.from_config(pipe.scheduler.config      )
           lowercase__		       =						pipe.to("cuda"      )

           lowercase__		       =						"Spiderman is surfing"
           lowercase__		       =						torch.Generator(device="cpu"      ).manual_seed(0      )

           lowercase__		       =						pipe(UpperCAmelCase_     ,generator=UpperCAmelCase_     ,num_inference_steps=25     ,output_type="pt"      ).frames
           lowercase__		       =						video_frames.cpu().numpy()

           assert np.abs(expected_video - video      ).mean() < 5E-2







       def 							_a      (				self      )  ->							Optional[int]:
           lowercase__		       =						load_numpy(
               "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text_to_video/video_2step.npy"      )

           lowercase__		       =						TextToVideoSDPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b"      )
           lowercase__		       =						pipe.to("cuda"      )

           lowercase__		       =						"Spiderman is surfing"
           lowercase__		       =						torch.Generator(device="cpu"      ).manual_seed(0      )

           lowercase__		       =						pipe(UpperCAmelCase_     ,generator=UpperCAmelCase_     ,num_inference_steps=2     ,output_type="pt"      ).frames
           lowercase__		       =						video_frames.cpu().numpy()

           assert np.abs(expected_video - video      ).mean() < 5E-2




