





'''simple docstring'''






# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
    is_vision_available,
)


__UpperCamelCase										=  {
    "configuration_tvlt": ["TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP", "TvltConfig"],
    "feature_extraction_tvlt": ["TvltFeatureExtractor"],
    "processing_tvlt": ["TvltProcessor"],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__UpperCamelCase										=  [
	    "TVLT_PRETRAINED_MODEL_ARCHIVE_LIST",
	    "TvltModel",
	    "TvltForPreTraining",
	    "TvltForAudioVisualClassification",
	    "TvltPreTrainedModel",
	]

try:
	if not is_vision_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__UpperCamelCase										=  ["TvltImageProcessor"]


if TYPE_CHECKING:
	from .configuration_tvlt import TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP, TvltConfig
	from .processing_tvlt import TvltProcessor
	from .feature_extraction_tvlt import TvltFeatureExtractor

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tvlt import (
		    TVLT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TvltForAudioVisualClassification,
		    TvltForPreTraining,
		    TvltModel,
		    TvltPreTrainedModel,
		)

	try:
		if not is_vision_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .image_processing_tvlt import TvltImageProcessor


else:
	import sys

	__UpperCamelCase										=  _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)









'''simple docstring'''






import torch
from torch import autograd




class    _A   (				autograd.Function		):

		@staticmethod
		def   lowercase__    (      __magic_name__				:      List[Any]     ,			__magic_name__				:      torch.tensor     ,			__magic_name__				:      float     ,			__magic_name__				:      bool )				->						Optional[int]:


					"""simple docstring"""

					__snake_case				:			List[Any]       			=    inputs.numel()
					__snake_case				:			List[Any]       			=    int(0.005 * nb_elems ) + 1
					if sigmoid:
								__snake_case				:			Dict       			=    (torch.sigmoid(__magic_name__ ) > threshold).type(inputs.type() )
					else:
								__snake_case				:			Tuple       			=    (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
								__snake_case				:			Tuple       			=    inputs.flatten().kthvalue(max(nb_elems - nb_min     ,			1 ) ).values
								__snake_case				:			Union[str, Any]       			=    (inputs > k_threshold).type(inputs.type() )
					return mask

		@staticmethod
		def   lowercase__    (      __magic_name__				:      int     ,			__magic_name__				:      Any )				->						Tuple:


					"""simple docstring"""

					return gradOutput, None, None





class    _A   (				autograd.Function		):

		@staticmethod
		def   lowercase__    (      __magic_name__				:      Tuple     ,			__magic_name__				:      torch.tensor     ,			__magic_name__				:      float )				->						int:


					"""simple docstring"""

					__snake_case				:			Tuple       			=    inputs.clone()
					__snake_case			,    __snake_case				:			Dict       			=    inputs.flatten().sort(descending=__magic_name__ )
					__snake_case				:			List[Any]       			=    int(threshold * inputs.numel() )

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

		@staticmethod
		def   lowercase__    (      __magic_name__				:      List[str]     ,			__magic_name__				:      Any )				->						Optional[Any]:


					"""simple docstring"""

					return gradOutput, None





class    _A   (				__lowercase		):

		@staticmethod
		def   lowercase__    (      __magic_name__				:      torch.tensor     ,			__magic_name__				:      float )				->						List[str]:


					"""simple docstring"""

					__snake_case				:			List[str]       			=    inputs.clone()
					__snake_case			,    __snake_case				:			Tuple       			=    inputs.abs().flatten().sort(descending=__magic_name__ )
					__snake_case				:			Any       			=    int(threshold * inputs.numel() )

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


