

"""simple docstring"""





import unittest
from typing import Tuple

import torch

from diffusers.utils import floats_tensor, randn_tensor, torch_all_close, torch_device
from diffusers.utils.testing_utils import require_torch




@require_torch
class  _lowerCAmelCase  :







 """simple docstring"""







 @property
 def  _lowercase			(      self							:      str     ):
    return self.get_dummy_input()


 @property
 def  _lowercase			(      self							:      str     ):
    if self.block_type == "down":
       return (4, 3_2, 1_6, 1_6)
    elif self.block_type == "mid":
       return (4, 3_2, 3_2, 3_2)
    elif self.block_type == "up":
       return (4, 3_2, 6_4, 6_4)

    raise ValueError(F"""'{self.block_type}' is not a supported block_type. Set it to 'up', 'mid', or 'down'."""     )


 def  _lowercase			(      self							:      int, UpperCAmelCase__							:      int=True, UpperCAmelCase__							:      Tuple=False, UpperCAmelCase__							:      str=False, UpperCAmelCase__							:      Union[str, Any]=False, ):
    __lowercase								=						4
    __lowercase								=						3_2
    __lowercase								=						(3_2, 3_2)

    __lowercase								=						torch.manual_seed(0     )
    __lowercase								=						torch.device(UpperCAmelCase__     )
    __lowercase								=						(batch_size, num_channels) + sizes
    __lowercase								=						randn_tensor(UpperCAmelCase__, generator=UpperCAmelCase__, device=UpperCAmelCase__     )
    __lowercase								=						{"hidden_states": hidden_states}

    if include_temb:
       __lowercase								=						1_2_8
       __lowercase								=						randn_tensor((batch_size, temb_channels), generator=UpperCAmelCase__, device=UpperCAmelCase__     )

    if include_res_hidden_states_tuple:
       __lowercase								=						torch.manual_seed(1     )
       __lowercase								=						(randn_tensor(UpperCAmelCase__, generator=UpperCAmelCase__, device=UpperCAmelCase__     ),)

    if include_encoder_hidden_states:
       __lowercase								=						floats_tensor((batch_size, 3_2, 3_2)     ).to(UpperCAmelCase__     )

    if include_skip_sample:
       __lowercase								=						randn_tensor(((batch_size, 3) + sizes), generator=UpperCAmelCase__, device=UpperCAmelCase__     )

    return dummy_input


 def  _lowercase			(      self							:      int     ):
    __lowercase								=						{
        "in_channels": 3_2,
        "out_channels": 3_2,
        "temb_channels": 1_2_8,
    }
    if self.block_type == "up":
       __lowercase								=						3_2

    if self.block_type == "mid":
       init_dict.pop("out_channels"     )

    __lowercase								=						self.dummy_input
    return init_dict, inputs_dict


 def  _lowercase			(      self							:      List[Any], UpperCAmelCase__							:      Any     ):
    __lowercase		,__lowercase								=						self.prepare_init_args_and_inputs_for_common()
    __lowercase								=						self.block_class(**UpperCAmelCase__     )
    unet_block.to(UpperCAmelCase__     )
    unet_block.eval()

    with torch.no_grad():
       __lowercase								=						unet_block(**UpperCAmelCase__     )

    if isinstance(UpperCAmelCase__, UpperCAmelCase__     ):
       __lowercase								=						output[0]

    self.assertEqual(output.shape, self.output_shape     )

    __lowercase								=						output[0, -1, -3:, -3:]
    __lowercase								=						torch.tensor(UpperCAmelCase__     ).to(UpperCAmelCase__     )
    assert torch_all_close(output_slice.flatten(), UpperCAmelCase__, atol=5E-3     )



 @unittest.skipIf(torch_device == "mps", "Training is not supported in mps"     )
 def  _lowercase			(      self							:      Any     ):
    __lowercase		,__lowercase								=						self.prepare_init_args_and_inputs_for_common()
    __lowercase								=						self.block_class(**UpperCAmelCase__     )
    model.to(UpperCAmelCase__     )
    model.train()
    __lowercase								=						model(**UpperCAmelCase__     )

    if isinstance(UpperCAmelCase__, UpperCAmelCase__     ):
       __lowercase								=						output[0]

    __lowercase								=						torch.device(UpperCAmelCase__     )
    __lowercase								=						randn_tensor(output.shape, device=UpperCAmelCase__     )
    __lowercase								=						torch.nn.functional.mse_loss(UpperCAmelCase__, UpperCAmelCase__     )
    loss.backward()







"""simple docstring"""





from unittest import TestCase

from datasets import Dataset
from minhash_deduplication import deduplicate_dataset, make_duplicate_clusters




def   _A  (  )     ->						Dict:
   '''simple docstring'''


   __lowercase								=						{
       "repo_name": ["test_repo1", "test_repo2", "test_repo3"],
       "path": ["test_1.py", "test_2.py", "unit_test.py"],
       "content": ["a " * 20, "a " * 30, "b " * 7],
   }
   __lowercase								=						Dataset.from_dict(UpperCamelCase_)
   return dataset




class  _lowerCAmelCase  (     lowercase       ):







 """simple docstring"""







 def  _lowercase			(      self							:      int     ):
    __lowercase								=						get_dataset()
    __lowercase								=						make_duplicate_clusters(UpperCAmelCase__, 0.85     )
    self.assertEqual(len(duplicate_clusters[0]     ), 2     )



 def  _lowercase			(      self							:      Any     ):
    __lowercase								=						get_dataset()
    __lowercase		,__lowercase								=						deduplicate_dataset(UpperCAmelCase__     )
    self.assertEqual(len(UpperCAmelCase__     ), 2     )
    print(UpperCAmelCase__     )
    self.assertEqual(duplicate_clusters[0][0]["copies"], 2     )
    self.assertEqual(duplicate_clusters[0][0]["is_extreme"], UpperCAmelCase__     )




