






'''simple docstring'''

import json
import os
from pathlib import Path

import pytest

from datasets.download.download_config import DownloadConfig
from datasets.download.download_manager import DownloadManager
from datasets.utils.file_utils import hash_url_to_filename


SCREAMING_SNAKE_CASE__											=     "http://www.mocksite.com/file1.txt"
SCREAMING_SNAKE_CASE__											=     "\"text\": [\"foo\", \"foo\"]"
SCREAMING_SNAKE_CASE__											=     "6d8ce9aa78a471c7477201efbeabd3bb01ac2e7d100a6dc024ba1608361f90a8"






class        a_		:
		lowercase  	=   2_00
		lowercase  	=   {'''Content-Length''': '''100'''}
		lowercase  	=   {}

		def 						A__		(   self    ,	**_SCREAMING_SNAKE_CASE   )						->   Dict:



								"""simple docstring"""






								return [bytes(A_    ,	"""utf-8"""   )]







def 					lowercase__				(   *__UpperCamelCase	,		**__UpperCamelCase					)->				Dict:
						return MockResponse()







@pytest.mark.parametrize("""urls_type"""	,		[str, list, dict]					)
def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase	,		__UpperCamelCase					)->				Any:
						import requests

						monkeypatch.setattr(__UpperCamelCase	,		"""request"""	,		__UpperCamelCase					)

						UpperCamelCase       						=      URL
						if issubclass(__UpperCamelCase	,		__UpperCamelCase					):
												UpperCamelCase       						=      url
						elif issubclass(__UpperCamelCase	,		__UpperCamelCase					):
												UpperCamelCase       						=      [url]
						elif issubclass(__UpperCamelCase	,		__UpperCamelCase					):
												UpperCamelCase       						=      {"""train""": url}
						UpperCamelCase       						=      """dummy"""
						UpperCamelCase       						=      """downloads"""
						UpperCamelCase       						=      tmp_path
						UpperCamelCase       						=      DownloadConfig(
						    cache_dir=os.path.join(__UpperCamelCase	,		__UpperCamelCase					)	,		use_etag=__UpperCamelCase	,		)
						UpperCamelCase       						=      DownloadManager(dataset_name=__UpperCamelCase	,		download_config=__UpperCamelCase					)
						UpperCamelCase       						=      dl_manager.download(__UpperCamelCase					)
						UpperCamelCase       						=      urls
						for downloaded_paths in [downloaded_paths]:
												if isinstance(__UpperCamelCase	,		__UpperCamelCase					):
																		UpperCamelCase       						=      [downloaded_paths]
																		UpperCamelCase       						=      [urls]
												elif isinstance(__UpperCamelCase	,		__UpperCamelCase					):
																		assert "train" in downloaded_paths.keys()
																		UpperCamelCase       						=      downloaded_paths.values()
																		UpperCamelCase       						=      urls.values()
												assert downloaded_paths
												for downloaded_path, input_url in zip(__UpperCamelCase	,		__UpperCamelCase					):
																		assert downloaded_path == dl_manager.downloaded_paths[input_url]
																		UpperCamelCase       						=      Path(__UpperCamelCase					)
																		UpperCamelCase       						=      downloaded_path.parts
																		assert parts[-1] == HASH
																		assert parts[-2] == cache_subdir
																		assert downloaded_path.exists()
																		UpperCamelCase       						=      downloaded_path.read_text()
																		assert content == CONTENT
																		UpperCamelCase       						=      downloaded_path.with_suffix(""".json"""					)
																		assert metadata_downloaded_path.exists()
																		UpperCamelCase       						=      json.loads(metadata_downloaded_path.read_text()					)
																		assert metadata_content == {"url": URL, "etag": None}







@pytest.mark.parametrize("""paths_type"""	,		[str, list, dict]					)
def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase	,		__UpperCamelCase					)->				Optional[Any]:
						UpperCamelCase       						=      str(__UpperCamelCase					)
						if issubclass(__UpperCamelCase	,		__UpperCamelCase					):
												UpperCamelCase       						=      filename
						elif issubclass(__UpperCamelCase	,		__UpperCamelCase					):
												UpperCamelCase       						=      [filename]
						elif issubclass(__UpperCamelCase	,		__UpperCamelCase					):
												UpperCamelCase       						=      {"""train""": filename}
						UpperCamelCase       						=      """dummy"""
						UpperCamelCase       						=      xz_file.parent
						UpperCamelCase       						=      """extracted"""
						UpperCamelCase       						=      DownloadConfig(
						    cache_dir=__UpperCamelCase	,		use_etag=__UpperCamelCase	,		)
						UpperCamelCase       						=      DownloadManager(dataset_name=__UpperCamelCase	,		download_config=__UpperCamelCase					)
						UpperCamelCase       						=      dl_manager.extract(__UpperCamelCase					)
						UpperCamelCase       						=      paths
						for extracted_paths in [extracted_paths]:
												if isinstance(__UpperCamelCase	,		__UpperCamelCase					):
																		UpperCamelCase       						=      [extracted_paths]
																		UpperCamelCase       						=      [paths]
												elif isinstance(__UpperCamelCase	,		__UpperCamelCase					):
																		assert "train" in extracted_paths.keys()
																		UpperCamelCase       						=      extracted_paths.values()
																		UpperCamelCase       						=      paths.values()
												assert extracted_paths
												for extracted_path, input_path in zip(__UpperCamelCase	,		__UpperCamelCase					):
																		assert extracted_path == dl_manager.extracted_paths[input_path]
																		UpperCamelCase       						=      Path(__UpperCamelCase					)
																		UpperCamelCase       						=      extracted_path.parts
																		assert parts[-1] == hash_url_to_filename(__UpperCamelCase	,		etag=__UpperCamelCase					)
																		assert parts[-2] == extracted_subdir
																		assert extracted_path.exists()
																		UpperCamelCase       						=      extracted_path.read_text()
																		UpperCamelCase       						=      text_file.read_text()
																		assert extracted_file_content == expected_file_content







def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase					)->				int:
						assert path.endswith(""".jsonl"""					)
						for num_items, line in enumerate(__UpperCamelCase	,		start=1					):
												UpperCamelCase       						=      json.loads(line.decode("""utf-8"""					)					)
												assert item.keys() == {"col_1", "col_2", "col_3"}
						assert num_items == 4







@pytest.mark.parametrize("""archive_jsonl"""	,		["""tar_jsonl_path""", """zip_jsonl_path"""]					)
def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase					)->				Optional[int]:
						UpperCamelCase       						=      request.getfixturevalue(__UpperCamelCase					)
						UpperCamelCase       						=      DownloadManager()
						for num_jsonl, (path, file) in enumerate(dl_manager.iter_archive(__UpperCamelCase					)	,		start=1					):
												_test_jsonl(__UpperCamelCase	,		__UpperCamelCase					)
						assert num_jsonl == 2







@pytest.mark.parametrize("""archive_nested_jsonl"""	,		["""tar_nested_jsonl_path""", """zip_nested_jsonl_path"""]					)
def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase					)->				Union[str, Any]:
						UpperCamelCase       						=      request.getfixturevalue(__UpperCamelCase					)
						UpperCamelCase       						=      DownloadManager()
						for num_tar, (path, file) in enumerate(dl_manager.iter_archive(__UpperCamelCase					)	,		start=1					):
												for num_jsonl, (subpath, subfile) in enumerate(dl_manager.iter_archive(__UpperCamelCase					)	,		start=1					):
																		_test_jsonl(__UpperCamelCase	,		__UpperCamelCase					)
						assert num_tar == 1
						assert num_jsonl == 2







def 					lowercase__				(   __UpperCamelCase					)->				Any:
						UpperCamelCase       						=      DownloadManager()
						for num_file, file in enumerate(dl_manager.iter_files(__UpperCamelCase					)	,		start=1					):
												assert os.path.basename(__UpperCamelCase					) == ("test.txt" if num_file == 1 else "train.txt")
						assert num_file == 2








'''simple docstring'''

import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


SCREAMING_SNAKE_CASE__											=     logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__											=     {
    'SenseTime/deformable-detr': 'https://huggingface.co/sensetime/deformable-detr/resolve/main/config.json',
    # See all Deformable DETR models at https://huggingface.co/models?filter=deformable-detr
}






class        a_		(    lowerCamelCase       ):
  lowercase  	=   """deformable_detr"""
  lowercase  	=   {
      """hidden_size""": """d_model""",
      """num_attention_heads""": """encoder_attention_heads""",
  }

  def __init__(   self    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=None    ,	_SCREAMING_SNAKE_CASE=3    ,	_SCREAMING_SNAKE_CASE=300    ,	_SCREAMING_SNAKE_CASE=1024    ,	_SCREAMING_SNAKE_CASE=6    ,	_SCREAMING_SNAKE_CASE=1024    ,	_SCREAMING_SNAKE_CASE=8    ,	_SCREAMING_SNAKE_CASE=6    ,	_SCREAMING_SNAKE_CASE=1024    ,	_SCREAMING_SNAKE_CASE=8    ,	_SCREAMING_SNAKE_CASE=0.0    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE="relu"    ,	_SCREAMING_SNAKE_CASE=256    ,	_SCREAMING_SNAKE_CASE=0.1    ,	_SCREAMING_SNAKE_CASE=0.0    ,	_SCREAMING_SNAKE_CASE=0.0    ,	_SCREAMING_SNAKE_CASE=0.0_2    ,	_SCREAMING_SNAKE_CASE=1.0    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=False    ,	_SCREAMING_SNAKE_CASE="sine"    ,	_SCREAMING_SNAKE_CASE="resnet50"    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=False    ,	_SCREAMING_SNAKE_CASE=4    ,	_SCREAMING_SNAKE_CASE=4    ,	_SCREAMING_SNAKE_CASE=4    ,	_SCREAMING_SNAKE_CASE=False    ,	_SCREAMING_SNAKE_CASE=300    ,	_SCREAMING_SNAKE_CASE=False    ,	_SCREAMING_SNAKE_CASE=1    ,	_SCREAMING_SNAKE_CASE=5    ,	_SCREAMING_SNAKE_CASE=2    ,	_SCREAMING_SNAKE_CASE=1    ,	_SCREAMING_SNAKE_CASE=1    ,	_SCREAMING_SNAKE_CASE=5    ,	_SCREAMING_SNAKE_CASE=2    ,	_SCREAMING_SNAKE_CASE=0.1    ,	_SCREAMING_SNAKE_CASE=0.2_5    ,	_SCREAMING_SNAKE_CASE=False    ,	**_SCREAMING_SNAKE_CASE    ,	)						->   List[str]:



        """simple docstring"""






        if backbone_config is not None and use_timm_backbone:
              raise ValueError("""You can't specify both `backbone_config` and `use_timm_backbone`."""   )

        if not use_timm_backbone:
              if backbone_config is None:
                    logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""   )
                    UpperCamelCase       						=      CONFIG_MAPPING["""resnet"""](out_features=["""stage4"""]   )
              elif isinstance(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   ):
                    UpperCamelCase       						=      backbone_config.get("""model_type"""   )
                    UpperCamelCase       						=      CONFIG_MAPPING[backbone_model_type]
                    UpperCamelCase       						=      config_class.from_dict(_SCREAMING_SNAKE_CASE   )
        UpperCamelCase       						=      use_timm_backbone
        UpperCamelCase       						=      backbone_config
        UpperCamelCase       						=      num_channels
        UpperCamelCase       						=      num_queries
        UpperCamelCase       						=      max_position_embeddings
        UpperCamelCase       						=      d_model
        UpperCamelCase       						=      encoder_ffn_dim
        UpperCamelCase       						=      encoder_layers
        UpperCamelCase       						=      encoder_attention_heads
        UpperCamelCase       						=      decoder_ffn_dim
        UpperCamelCase       						=      decoder_layers
        UpperCamelCase       						=      decoder_attention_heads
        UpperCamelCase       						=      dropout
        UpperCamelCase       						=      attention_dropout
        UpperCamelCase       						=      activation_dropout
        UpperCamelCase       						=      activation_function
        UpperCamelCase       						=      init_std
        UpperCamelCase       						=      init_xavier_std
        UpperCamelCase       						=      encoder_layerdrop
        UpperCamelCase       						=      auxiliary_loss
        UpperCamelCase       						=      position_embedding_type
        UpperCamelCase       						=      backbone
        UpperCamelCase       						=      use_pretrained_backbone
        UpperCamelCase       						=      dilation
        # deformable attributes
        UpperCamelCase       						=      num_feature_levels
        UpperCamelCase       						=      encoder_n_points
        UpperCamelCase       						=      decoder_n_points
        UpperCamelCase       						=      two_stage
        UpperCamelCase       						=      two_stage_num_proposals
        UpperCamelCase       						=      with_box_refine
        if two_stage is True and with_box_refine is False:
              raise ValueError("""If two_stage is True, with_box_refine must be True."""   )
        # Hungarian matcher
        UpperCamelCase       						=      class_cost
        UpperCamelCase       						=      bbox_cost
        UpperCamelCase       						=      giou_cost
        # Loss coefficients
        UpperCamelCase       						=      mask_loss_coefficient
        UpperCamelCase       						=      dice_loss_coefficient
        UpperCamelCase       						=      bbox_loss_coefficient
        UpperCamelCase       						=      giou_loss_coefficient
        UpperCamelCase       						=      eos_coefficient
        UpperCamelCase       						=      focal_alpha
        UpperCamelCase       						=      disable_custom_kernels
        super().__init__(is_encoder_decoder=_SCREAMING_SNAKE_CASE    ,	**_SCREAMING_SNAKE_CASE   )

  @property
  def 						A__		(   self   )						->   int:



        """simple docstring"""






        return self.encoder_attention_heads

  @property
  def 						A__		(   self   )						->   int:



        """simple docstring"""






        return self.d_model


  def 						A__		(   self   )						->   Tuple:



        """simple docstring"""






        UpperCamelCase       						=      copy.deepcopy(self.__dict__   )
        if self.backbone_config is not None:
              UpperCamelCase       						=      self.backbone_config.to_dict()
        UpperCamelCase       						=      self.__class__.model_type
        return output
