"""simple docstring"""



import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)






class  snake_case__      (       unittest.TestCase       ):


 def 						a__   ( self						):
        __a       =    ["a", "b", "c"]

        # Defaults to last layer if both are None
        __a ,   __a       =    get_aligned_output_features_output_indices(lowerCamelCase    ,		lowerCamelCase    ,		lowerCamelCase						)
        self.assertEqual(lowerCamelCase    ,		["c"]						)
        self.assertEqual(lowerCamelCase    ,		[2]						)

        # Out indices set to match out features
        __a ,   __a       =    get_aligned_output_features_output_indices(["a", "c"]    ,		lowerCamelCase    ,		lowerCamelCase						)
        self.assertEqual(lowerCamelCase    ,		["a", "c"]						)
        self.assertEqual(lowerCamelCase    ,		[0, 2]						)

        # Out features set to match out indices
        __a ,   __a       =    get_aligned_output_features_output_indices(lowerCamelCase    ,		[0, 2]    ,		lowerCamelCase						)
        self.assertEqual(lowerCamelCase    ,		["a", "c"]						)
        self.assertEqual(lowerCamelCase    ,		[0, 2]						)

        # Out features selected from negative indices
        __a ,   __a       =    get_aligned_output_features_output_indices(lowerCamelCase    ,		[-3, -1]    ,		lowerCamelCase						)
        self.assertEqual(lowerCamelCase    ,		["a", "c"]						)
        self.assertEqual(lowerCamelCase    ,		[-3, -1]						)


 def 						a__   ( self						):
        # Stage names must be set
        with self.assertRaises(lowerCamelCase						):
               verify_out_features_out_indices(["a", "b"]    ,		(0, 1)    ,		lowerCamelCase						)

        # Out features must be a list
        with self.assertRaises(lowerCamelCase						):
               verify_out_features_out_indices(("a", "b")    ,		(0, 1)    ,		["a", "b"]						)

        # Out features must be a subset of stage names
        with self.assertRaises(lowerCamelCase						):
               verify_out_features_out_indices(["a", "b"]    ,		(0, 1)    ,		["a"]						)

        # Out indices must be a list or tuple
        with self.assertRaises(lowerCamelCase						):
               verify_out_features_out_indices(lowerCamelCase    ,		0    ,		["a", "b"]						)

        # Out indices must be a subset of stage names
        with self.assertRaises(lowerCamelCase						):
               verify_out_features_out_indices(lowerCamelCase    ,		(0, 1)    ,		["a"]						)

        # Out features and out indices must be the same length
        with self.assertRaises(lowerCamelCase						):
               verify_out_features_out_indices(["a", "b"]    ,		(0,)    ,		["a", "b", "c"]						)

        # Out features should match out indices
        with self.assertRaises(lowerCamelCase						):
               verify_out_features_out_indices(["a", "b"]    ,		(0, 2)    ,		["a", "b", "c"]						)

        # Out features and out indices should be in order
        with self.assertRaises(lowerCamelCase						):
               verify_out_features_out_indices(["b", "a"]    ,		(0, 1)    ,		["a", "b"]						)

        # Check passes with valid inputs
        verify_out_features_out_indices(["a", "b", "d"]    ,		(0, 1, -1)    ,		["a", "b", "c", "d"]						)






 def 						a__   ( self						):
        __a       =    BackboneMixin()

        __a       =    ["a", "b", "c"]
        __a       =    ["a", "c"]
        __a       =    [0, 2]

        # Check that the output features and indices are set correctly
        self.assertEqual(backbone.out_features    ,		["a", "c"]						)
        self.assertEqual(backbone.out_indices    ,		[0, 2]						)

        # Check out features and indices are updated correctly
        __a       =    ["a", "b"]
        self.assertEqual(backbone.out_features    ,		["a", "b"]						)
        self.assertEqual(backbone.out_indices    ,		[0, 1]						)

        __a       =    [-3, -1]
        self.assertEqual(backbone.out_features    ,		["a", "c"]						)
        self.assertEqual(backbone.out_indices    ,		[-3, -1]						)

"""simple docstring"""



import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible






class  snake_case__      (       unittest.TestCase       ):


 def 						a__   ( self						):
        __a       =    [
            "safety_checker/pytorch_model.bin",
            "safety_checker/model.safetensors",
            "vae/diffusion_pytorch_model.bin",
            "vae/diffusion_pytorch_model.safetensors",
            "text_encoder/pytorch_model.bin",
            "text_encoder/model.safetensors",
            "unet/diffusion_pytorch_model.bin",
            "unet/diffusion_pytorch_model.safetensors",
        ]
        self.assertTrue(is_safetensors_compatible(lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "unet/diffusion_pytorch_model.bin",
            "unet/diffusion_pytorch_model.safetensors",
        ]
        self.assertTrue(is_safetensors_compatible(lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "safety_checker/pytorch_model.bin",
            "safety_checker/model.safetensors",
            "vae/diffusion_pytorch_model.bin",
            "vae/diffusion_pytorch_model.safetensors",
            "text_encoder/pytorch_model.bin",
            "text_encoder/model.safetensors",
            "unet/diffusion_pytorch_model.bin",
            # Removed: 'unet/diffusion_pytorch_model.safetensors',
        ]
        self.assertFalse(is_safetensors_compatible(lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "text_encoder/pytorch_model.bin",
            "text_encoder/model.safetensors",
        ]
        self.assertTrue(is_safetensors_compatible(lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "safety_checker/pytorch_model.bin",
            "safety_checker/model.safetensors",
            "vae/diffusion_pytorch_model.bin",
            "vae/diffusion_pytorch_model.safetensors",
            "text_encoder/pytorch_model.bin",
            # Removed: 'text_encoder/model.safetensors',
            "unet/diffusion_pytorch_model.bin",
            "unet/diffusion_pytorch_model.safetensors",
        ]
        self.assertFalse(is_safetensors_compatible(lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "safety_checker/pytorch_model.fp16.bin",
            "safety_checker/model.fp16.safetensors",
            "vae/diffusion_pytorch_model.fp16.bin",
            "vae/diffusion_pytorch_model.fp16.safetensors",
            "text_encoder/pytorch_model.fp16.bin",
            "text_encoder/model.fp16.safetensors",
            "unet/diffusion_pytorch_model.fp16.bin",
            "unet/diffusion_pytorch_model.fp16.safetensors",
        ]
        __a       =    "fp16"
        self.assertTrue(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "unet/diffusion_pytorch_model.fp16.bin",
            "unet/diffusion_pytorch_model.fp16.safetensors",
        ]
        __a       =    "fp16"
        self.assertTrue(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)


 def 						a__   ( self						):
        # pass variant but use the non-variant filenames
        __a       =    [
            "unet/diffusion_pytorch_model.bin",
            "unet/diffusion_pytorch_model.safetensors",
        ]
        __a       =    "fp16"
        self.assertTrue(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "safety_checker/pytorch_model.fp16.bin",
            "safety_checker/model.fp16.safetensors",
            "vae/diffusion_pytorch_model.fp16.bin",
            "vae/diffusion_pytorch_model.fp16.safetensors",
            "text_encoder/pytorch_model.fp16.bin",
            "text_encoder/model.fp16.safetensors",
            "unet/diffusion_pytorch_model.fp16.bin",
            # Removed: 'unet/diffusion_pytorch_model.fp16.safetensors',
        ]
        __a       =    "fp16"
        self.assertFalse(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)


 def 						a__   ( self						):
        __a       =    [
            "text_encoder/pytorch_model.fp16.bin",
            "text_encoder/model.fp16.safetensors",
        ]
        __a       =    "fp16"
        self.assertTrue(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)


 def 						a__   ( self						):
        # pass variant but use the non-variant filenames
        __a       =    [
            "text_encoder/pytorch_model.bin",
            "text_encoder/model.safetensors",
        ]
        __a       =    "fp16"
        self.assertTrue(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)






 def 						a__   ( self						):
        __a       =    [
            "safety_checker/pytorch_model.fp16.bin",
            "safety_checker/model.fp16.safetensors",
            "vae/diffusion_pytorch_model.fp16.bin",
            "vae/diffusion_pytorch_model.fp16.safetensors",
            "text_encoder/pytorch_model.fp16.bin",
            # 'text_encoder/model.fp16.safetensors',
            "unet/diffusion_pytorch_model.fp16.bin",
            "unet/diffusion_pytorch_model.fp16.safetensors",
        ]
        __a       =    "fp16"
        self.assertFalse(is_safetensors_compatible(lowerCamelCase    ,		variant=lowerCamelCase						)						)
