



import torch
from torch import autograd


class 	lowerCamelCase__ (		autograd.Function   ):


						@staticmethod
						def   _lowerCamelCase			( _a						:  Tuple      ,       _a						:  torch.tensor      ,       _a						:  float      ,       _a						:  bool			):
													a__:       List[str]											=inputs.numel()
													a__:       str											=int(0.0_0_5 * nb_elems			) + 1
													if sigmoid:
																				a__:       Any											=(torch.sigmoid(_a			) > threshold).type(inputs.type()			)
													else:
																				a__:       Any											=(inputs > threshold).type(inputs.type()			)
													if mask.sum() < nb_min:
																				# We limit the pruning so that at least 0.5% (half a percent) of the weights are remaining
																				a__:       Optional[int]											=inputs.flatten().kthvalue(max(nb_elems - nb_min      ,       1			)			).values
																				a__:       Dict											=(inputs > k_threshold).type(inputs.type()			)
													return mask







						@staticmethod
						def   _lowerCamelCase			( _a						:  Optional[Any]      ,       _a						:  Optional[Any]			):
													return gradOutput, None, None


class 	lowerCamelCase__ (		autograd.Function   ):


						@staticmethod
						def   _lowerCamelCase			( _a						:  Union[str, Any]      ,       _a						:  torch.tensor      ,       _a						:  float			):
													a__:       List[Any]											=inputs.clone()
													a__							,			a__:       str											=inputs.flatten().sort(descending=_a			)
													a__:       List[str]											=int(threshold * inputs.numel()			)

													# flat_out and mask access the same memory.
													a__:       Optional[int]											=mask.flatten()
													a__:       Optional[Any]											=0
													a__:       int											=1
													return mask







						@staticmethod
						def   _lowerCamelCase			( _a						:  Any      ,       _a						:  Any			):
													return gradOutput, None


class 	lowerCamelCase__ (		_a   ):


						@staticmethod
						def   _lowerCamelCase			( _a						:  torch.tensor      ,       _a						:  float			):
													a__:       List[str]											=inputs.clone()
													a__							,			a__:       Dict											=inputs.abs().flatten().sort(descending=_a			)
													a__:       Optional[int]											=int(threshold * inputs.numel()			)

													# flat_out and mask access the same memory.
													a__:       List[Any]											=mask.flatten()
													a__:       Union[str, Any]											=0
													a__:       Union[str, Any]											=1
													return mask










from ...utils import is_transformers_available
from .pipeline_latent_diffusion_superresolution import LDMSuperResolutionPipeline


if is_transformers_available():
		from .pipeline_latent_diffusion import LDMBertModel, LDMTextToImagePipeline





