






import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase  							=					logging.get_logger(__name__)

lowercase  							=					{
    "microsoft/wavlm-base": "https://huggingface.co/microsoft/wavlm-base/resolve/main/config.json",
    # See all WavLM models at https://huggingface.co/models?filter=wavlm
}




class  UpperCamelCase_      (			snake_case_				):



	'''simple docstring'''




	lowerCAmelCase													= '''wavlm'''




	def __init__(       self       ,			a=32       ,			a=7_68       ,			a=12       ,			a=12       ,			a=30_72       ,			a="gelu"       ,			a=0.1       ,			a=0.1       ,			a=0.1       ,			a=0.0       ,			a=0.1       ,			a=0.1       ,			a=0.02       ,			a=1E-5       ,			a="group"       ,			a="gelu"       ,			a=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)       ,			a=(5, 2, 2, 2, 2, 2, 2)       ,			a=(10, 3, 3, 3, 3, 2, 2)       ,			a=False       ,			a=1_28       ,			a=16       ,			a=3_20       ,			a=8_00       ,			a=False       ,			a=True       ,			a=0.05       ,			a=10       ,			a=2       ,			a=0.0       ,			a=10       ,			a=3_20       ,			a=2       ,			a=0.1       ,			a=1_00       ,			a=2_56       ,			a=2_56       ,			a=0.1       ,			a="mean"       ,			a=False       ,			a=False       ,			a=2_56       ,			a=(5_12, 5_12, 5_12, 5_12, 15_00)       ,			a=(5, 3, 3, 1, 1)       ,			a=(1, 2, 3, 1, 1)       ,			a=5_12       ,			a=80       ,			a=0       ,			a=1       ,			a=2       ,			a=False       ,			a=3       ,			a=2       ,			a=3       ,			a=None       ,			**a       ,			)       ->    Any:
								super().__init__(**a       ,			pad_token_id=a       ,			bos_token_id=a       ,			eos_token_id=a					)
								snake_case_				=							hidden_size
								snake_case_				=							feat_extract_norm
								snake_case_				=							feat_extract_activation
								snake_case_				=							list(a					)
								snake_case_				=							list(a					)
								snake_case_				=							list(a					)
								snake_case_				=							conv_bias
								snake_case_				=							num_buckets
								snake_case_				=							max_bucket_distance
								snake_case_				=							num_conv_pos_embeddings
								snake_case_				=							num_conv_pos_embedding_groups
								snake_case_				=							len(self.conv_dim					)
								snake_case_				=							num_hidden_layers
								snake_case_				=							intermediate_size
								snake_case_				=							hidden_act
								snake_case_				=							num_attention_heads
								snake_case_				=							hidden_dropout
								snake_case_				=							attention_dropout
								snake_case_				=							activation_dropout
								snake_case_				=							feat_proj_dropout
								snake_case_				=							final_dropout
								snake_case_				=							layerdrop
								snake_case_				=							layer_norm_eps
								snake_case_				=							initializer_range
								snake_case_				=							num_ctc_classes
								snake_case_				=							vocab_size
								snake_case_				=							do_stable_layer_norm
								snake_case_				=							use_weighted_layer_sum
								snake_case_				=							classifier_proj_size

								if (
								    (len(self.conv_stride					) != self.num_feat_extract_layers)
								    or (len(self.conv_kernel					) != self.num_feat_extract_layers)
								    or (len(self.conv_dim					) != self.num_feat_extract_layers)
								):
															raise ValueError(
															    'Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='
															    ' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='
															    F''' {len(self.conv_dim					)}`, `len(config.conv_stride) = {len(self.conv_stride					)}`,'''
															    F''' `len(config.conv_kernel) = {len(self.conv_kernel					)}`.'''					)

								# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
								snake_case_				=							apply_spec_augment
								snake_case_				=							mask_time_prob
								snake_case_				=							mask_time_length
								snake_case_				=							mask_time_min_masks
								snake_case_				=							mask_feature_prob
								snake_case_				=							mask_feature_length

								# parameters for pretraining with codevector quantized representations
								snake_case_				=							num_codevectors_per_group
								snake_case_				=							num_codevector_groups
								snake_case_				=							contrastive_logits_temperature
								snake_case_				=							num_negatives
								snake_case_				=							codevector_dim
								snake_case_				=							proj_codevector_dim
								snake_case_				=							diversity_loss_weight

								# ctc loss
								snake_case_				=							ctc_loss_reduction
								snake_case_				=							ctc_zero_infinity

								# adapter
								snake_case_				=							add_adapter
								snake_case_				=							adapter_kernel_size
								snake_case_				=							adapter_stride
								snake_case_				=							num_adapter_layers
								snake_case_				=							output_hidden_size or hidden_size

								# SequenceClassification-specific parameter. Feel free to ignore for other classes.
								snake_case_				=							classifier_proj_size

								# XVector-specific parameters. Feel free to ignore for other classes.
								snake_case_				=							list(a					)
								snake_case_				=							list(a					)
								snake_case_				=							list(a					)
								snake_case_				=							xvector_output_dim






	@property
	def 							_UpperCamelCase			(       self					)       ->    Optional[int]:
								return functools.reduce(operator.mul       ,			self.conv_stride       ,			1					)













import os
from pathlib import Path
from unittest.mock import patch

import pytest
import zstandard as zstd

from datasets.download.download_config import DownloadConfig
from datasets.utils.file_utils import (
    OfflineModeIsEnabled,
    cached_path,
    fsspec_get,
    fsspec_head,
    ftp_get,
    ftp_head,
    get_from_cache,
    http_get,
    http_head,
)


lowercase  							=					"\\n    Text data.\n    Second line of data."

lowercase  							=					"file"





@pytest.fixture(scope='session')
def 						__UpperCAmelCase			(     a_):
							snake_case_				=							tmp_path_factory.mktemp('data') / (FILE_PATH + '.zstd')
							snake_case_				=							bytes(a_							,     'utf-8')
							with zstd.open(a_							,     'wb') as f:
														f.write(a_)
							return path





@pytest.fixture
def 						__UpperCAmelCase			(     a_):
							with open(os.path.join(tmpfs.local_root_dir							,     a_)							,     'w') as f:
														f.write(a_)
							return FILE_PATH





@pytest.mark.parametrize('compression_format'							,     ['gzip', 'xz', 'zstd'])
def 						__UpperCAmelCase			(     a_							,     a_							,     a_							,     a_							,     a_							,     a_):
							snake_case_				=							{'gzip': gz_file, 'xz': xz_file, 'zstd': zstd_path}
							snake_case_				=							input_paths[compression_format]
							snake_case_				=							tmp_path / 'cache'
							snake_case_				=							DownloadConfig(cache_dir=a_							,     extract_compressed_file=a_)
							snake_case_				=							cached_path(a_							,     download_config=a_)
							with open(a_) as f:
														snake_case_				=							f.read()
							with open(a_) as f:
														snake_case_				=							f.read()
							assert extracted_file_content == expected_file_content





@pytest.mark.parametrize('default_extracted'							,     [True, False])
@pytest.mark.parametrize('default_cache_dir'							,     [True, False])
def 						__UpperCAmelCase			(     a_							,     a_							,     a_							,     a_							,     a_):
							snake_case_				=							'custom_cache'
							snake_case_				=							'custom_extracted_dir'
							snake_case_				=							tmp_path / 'custom_extracted_path'
							if default_extracted:
														snake_case_				=							('downloads' if default_cache_dir else custom_cache_dir, 'extracted')
							else:
														monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_DIR'							,     a_)
														monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_PATH'							,     str(a_))
														snake_case_				=							custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

							snake_case_				=							xz_file
							snake_case_				=							(
							    DownloadConfig(extract_compressed_file=a_)
							    if default_cache_dir
							    else DownloadConfig(cache_dir=tmp_path / custom_cache_dir							,     extract_compressed_file=a_)
							)
							snake_case_				=							cached_path(a_							,     download_config=a_)
							assert Path(a_).parent.parts[-2:] == expected





def 						__UpperCAmelCase			(     a_):
							# absolute path
							snake_case_				=							str(Path(a_).resolve())
							assert cached_path(a_) == text_file
							# relative path
							snake_case_				=							str(Path(a_).resolve().relative_to(Path(os.getcwd())))
							assert cached_path(a_) == text_file





def 						__UpperCAmelCase			(     a_):
							# absolute path
							snake_case_				=							str(tmp_path.resolve() / '__missing_file__.txt')
							with pytest.raises(a_):
														cached_path(a_)
							# relative path
							snake_case_				=							'./__missing_file__.txt'
							with pytest.raises(a_):
														cached_path(a_)





def 						__UpperCAmelCase			(     a_):
							snake_case_				=							get_from_cache(f'''tmp://{tmpfs_file}''')
							with open(a_) as f:
														snake_case_				=							f.read()
							assert output_file_content == FILE_CONTENT





@patch('datasets.config.HF_DATASETS_OFFLINE'							,     a_)
def 						__UpperCAmelCase			(     ):
							with pytest.raises(a_):
														cached_path('https://huggingface.co')





@patch('datasets.config.HF_DATASETS_OFFLINE'							,     a_)
def 						__UpperCAmelCase			(     a_):
							snake_case_				=							tmp_path_factory.mktemp('data') / 'file.html'
							with pytest.raises(a_):
														http_get('https://huggingface.co'							,     temp_file=a_)
							with pytest.raises(a_):
														http_head('https://huggingface.co')





@patch('datasets.config.HF_DATASETS_OFFLINE'							,     a_)
def 						__UpperCAmelCase			(     a_):
							snake_case_				=							tmp_path_factory.mktemp('data') / 'file.html'
							with pytest.raises(a_):
														ftp_get('ftp://huggingface.co'							,     temp_file=a_)
							with pytest.raises(a_):
														ftp_head('ftp://huggingface.co')





@patch('datasets.config.HF_DATASETS_OFFLINE'							,     a_)
def 						__UpperCAmelCase			(     a_):
							snake_case_				=							tmp_path_factory.mktemp('data') / 'file.html'
							with pytest.raises(a_):
														fsspec_get('s3://huggingface.co'							,     temp_file=a_)
							with pytest.raises(a_):
														fsspec_head('s3://huggingface.co')





