




"""simple docstring"""

import unittest

from transformers import MarkupLMConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    MarkupLMForQuestionAnswering,
		    MarkupLMForSequenceClassification,
		    MarkupLMForTokenClassification,
		    MarkupLMModel,
		)

# TODO check dependencies
from transformers import MarkupLMFeatureExtractor, MarkupLMProcessor, MarkupLMTokenizer
class     A__      :




	def __init__(   self  :	str      ,    lowercase  :	Optional[int]      ,    lowercase  :	Union[str, Any]=13      ,    lowercase  :	str=7      ,    lowercase  :	str=True      ,    lowercase  :	Optional[int]=True      ,    lowercase  :	Optional[int]=True      ,    lowercase  :	Any=True      ,    lowercase  :	List[Any]=99      ,    lowercase  :	Dict=32      ,    lowercase  :	str=5      ,    lowercase  :	str=4      ,    lowercase  :	List[str]=37      ,    lowercase  :	List[str]="gelu"      ,    lowercase  :	Optional[Any]=0.1      ,    lowercase  :	Tuple=0.1      ,    lowercase  :	List[str]=512      ,    lowercase  :	Optional[int]=16      ,    lowercase  :	Optional[Any]=2      ,    lowercase  :	List[str]=0.02      ,    lowercase  :	List[Any]=3      ,    lowercase  :	List[Any]=None      ,    lowercase  :	int=20      ,    lowercase  :	List[Any]=30      ,    lowercase  :	Union[str, Any]=2      ,    lowercase  :	Union[str, Any]=2      ,    lowercase  :	Union[str, Any]=10      ,    )					-> Union[str, Any]:
						__snake_case          =	parent
						__snake_case          =	batch_size
						__snake_case          =	seq_length
						__snake_case          =	is_training
						__snake_case          =	use_input_mask
						__snake_case          =	use_token_type_ids
						__snake_case          =	use_labels
						__snake_case          =	vocab_size
						__snake_case          =	hidden_size
						__snake_case          =	num_hidden_layers
						__snake_case          =	num_attention_heads
						__snake_case          =	intermediate_size
						__snake_case          =	hidden_act
						__snake_case          =	hidden_dropout_prob
						__snake_case          =	attention_probs_dropout_prob
						__snake_case          =	max_position_embeddings
						__snake_case          =	type_vocab_size
						__snake_case          =	type_sequence_label_size
						__snake_case          =	initializer_range
						__snake_case          =	num_labels
						__snake_case          =	scope
						__snake_case          =	max_xpath_tag_unit_embeddings
						__snake_case          =	max_xpath_subs_unit_embeddings
						__snake_case          =	tag_pad_id
						__snake_case          =	subs_pad_id
						__snake_case          =	max_depth




	def 							a_		(   self  :	List[str]	)					-> Union[str, Any]:
						__snake_case          =	ids_tensor([self.batch_size, self.seq_length]      ,    self.vocab_size	)

						__snake_case          =	ids_tensor(
						    [self.batch_size, self.seq_length, self.max_depth]      ,    self.max_xpath_tag_unit_embeddings	)

						__snake_case          =	ids_tensor(
						    [self.batch_size, self.seq_length, self.max_depth]      ,    self.max_xpath_subs_unit_embeddings	)

						__snake_case          =	None
						if self.use_input_mask:
											__snake_case          =	ids_tensor([self.batch_size, self.seq_length]      ,    vocab_size=2	)

						__snake_case          =	None
						if self.use_token_type_ids:
											__snake_case          =	ids_tensor([self.batch_size, self.seq_length]      ,    self.type_vocab_size	)

						__snake_case          =	None
						__snake_case          =	None
						if self.use_labels:
											__snake_case          =	ids_tensor([self.batch_size]      ,    self.type_sequence_label_size	)
											__snake_case          =	ids_tensor([self.batch_size, self.seq_length]      ,    self.num_labels	)

						__snake_case          =	self.get_config()

						return (
						    config,
						    input_ids,
						    xpath_tags_seq,
						    xpath_subs_seq,
						    token_type_ids,
						    input_mask,
						    sequence_labels,
						    token_labels,
						)




	def 							a_		(   self  :	Tuple	)					-> str:
						return MarkupLMConfig(
						    vocab_size=self.vocab_size      ,    hidden_size=self.hidden_size      ,    num_hidden_layers=self.num_hidden_layers      ,    num_attention_heads=self.num_attention_heads      ,    intermediate_size=self.intermediate_size      ,    hidden_act=self.hidden_act      ,    hidden_dropout_prob=self.hidden_dropout_prob      ,    attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,    max_position_embeddings=self.max_position_embeddings      ,    type_vocab_size=self.type_vocab_size      ,    initializer_range=self.initializer_range      ,    max_xpath_tag_unit_embeddings=self.max_xpath_tag_unit_embeddings      ,    max_xpath_subs_unit_embeddings=self.max_xpath_subs_unit_embeddings      ,    tag_pad_id=self.tag_pad_id      ,    subs_pad_id=self.subs_pad_id      ,    max_depth=self.max_depth      ,    )




	def 							a_		(   self  :	str      ,    lowercase  :	Optional[Any]      ,    lowercase  :	List[str]      ,    lowercase  :	Tuple      ,    lowercase  :	List[str]      ,    lowercase  :	Union[str, Any]      ,    lowercase  :	Optional[Any]      ,    lowercase  :	List[str]      ,    lowercase  :	Tuple      ,    )					-> int:
						__snake_case          =	MarkupLMModel(config=lowercase	)
						model.to(lowercase	)
						model.eval()
						print("""Configs:"""      ,    model.config.tag_pad_id      ,    model.config.subs_pad_id	)
						__snake_case          =	model(lowercase      ,    attention_mask=lowercase      ,    token_type_ids=lowercase	)
						__snake_case          =	model(lowercase      ,    token_type_ids=lowercase	)
						__snake_case          =	model(lowercase	)
						self.parent.assertEqual(result.last_hidden_state.shape      ,    (self.batch_size, self.seq_length, self.hidden_size)	)
						self.parent.assertEqual(result.pooler_output.shape      ,    (self.batch_size, self.hidden_size)	)




	def 							a_		(   self  :	Any      ,    lowercase  :	Union[str, Any]      ,    lowercase  :	Optional[Any]      ,    lowercase  :	List[Any]      ,    lowercase  :	List[str]      ,    lowercase  :	Any      ,    lowercase  :	int      ,    lowercase  :	List[Any]      ,    lowercase  :	Any      ,    )					-> List[Any]:
						__snake_case          =	self.num_labels
						__snake_case          =	MarkupLMForSequenceClassification(lowercase	)
						model.to(lowercase	)
						model.eval()
						__snake_case          =	model(
						    lowercase      ,    xpath_tags_seq=lowercase      ,    xpath_subs_seq=lowercase      ,    attention_mask=lowercase      ,    token_type_ids=lowercase      ,    labels=lowercase      ,    )
						self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.num_labels)	)




	def 							a_		(   self  :	Optional[Any]      ,    lowercase  :	List[Any]      ,    lowercase  :	str      ,    lowercase  :	List[str]      ,    lowercase  :	Union[str, Any]      ,    lowercase  :	Tuple      ,    lowercase  :	List[str]      ,    lowercase  :	int      ,    lowercase  :	Optional[Any]      ,    )					-> Union[str, Any]:
						__snake_case          =	self.num_labels
						__snake_case          =	MarkupLMForTokenClassification(config=lowercase	)
						model.to(lowercase	)
						model.eval()
						__snake_case          =	model(
						    lowercase      ,    xpath_tags_seq=lowercase      ,    xpath_subs_seq=lowercase      ,    attention_mask=lowercase      ,    token_type_ids=lowercase      ,    labels=lowercase      ,    )
						self.parent.assertEqual(result.logits.shape      ,    (self.batch_size, self.seq_length, self.num_labels)	)




	def 							a_		(   self  :	Dict      ,    lowercase  :	Tuple      ,    lowercase  :	List[Any]      ,    lowercase  :	Optional[int]      ,    lowercase  :	int      ,    lowercase  :	Union[str, Any]      ,    lowercase  :	Optional[int]      ,    lowercase  :	Optional[Any]      ,    lowercase  :	Dict      ,    )					-> Optional[Any]:
						__snake_case          =	MarkupLMForQuestionAnswering(config=lowercase	)
						model.to(lowercase	)
						model.eval()
						__snake_case          =	model(
						    lowercase      ,    xpath_tags_seq=lowercase      ,    xpath_subs_seq=lowercase      ,    attention_mask=lowercase      ,    token_type_ids=lowercase      ,    start_positions=lowercase      ,    end_positions=lowercase      ,    )
						self.parent.assertEqual(result.start_logits.shape      ,    (self.batch_size, self.seq_length)	)
						self.parent.assertEqual(result.end_logits.shape      ,    (self.batch_size, self.seq_length)	)




	def 							a_		(   self  :	List[Any]	)					-> str:
						__snake_case          =	self.prepare_config_and_inputs()
						(
						    (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      (
						    __snake_case
						)      ,      
						)          =	config_and_inputs
						__snake_case          =	{
						    """input_ids""": input_ids,
						    """xpath_tags_seq""": xpath_tags_seq,
						    """xpath_subs_seq""": xpath_subs_seq,
						    """token_type_ids""": token_type_ids,
						    """attention_mask""": input_mask,
						}
						return config, inputs_dict

@require_torch
class     A__      (      lowercase_     ,	lowercase_     ,	unittest.TestCase     ):
	A_							:				int						     =      (
	    (
	        MarkupLMModel,
	        MarkupLMForSequenceClassification,
	        MarkupLMForTokenClassification,
	        MarkupLMForQuestionAnswering,
	    )
	    if is_torch_available()
	    else None
	)
	A_							:				Optional[int]						     =      (
	    {
	        """feature-extraction""": MarkupLMModel,
	        """question-answering""": MarkupLMForQuestionAnswering,
	        """text-classification""": MarkupLMForSequenceClassification,
	        """token-classification""": MarkupLMForTokenClassification,
	        """zero-shot""": MarkupLMForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)




	def 							a_		(   self  :	Optional[Any]      ,    lowercase  :	Union[str, Any]      ,    lowercase  :	str      ,    lowercase  :	Optional[Any]      ,    lowercase  :	Optional[int]      ,    lowercase  :	Union[str, Any]	)					-> Any:
						# ValueError: Nodes must be of type `List[str]` (single pretokenized example), or `List[List[str]]`
						# (batch of pretokenized examples).
						return True




	def 							a_		(   self  :	Optional[Any]	)					-> Dict:
						__snake_case          =	MarkupLMModelTester(self	)
						__snake_case          =	ConfigTester(self      ,    config_class=lowercase      ,    hidden_size=37	)




	def 							a_		(   self  :	Any	)					-> List[Any]:
						self.config_tester.run_common_tests()




	def 							a_		(   self  :	str	)					-> List[str]:
						__snake_case          =	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*lowercase	)




	def 							a_		(   self  :	Dict	)					-> Optional[Any]:
						__snake_case          =	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*lowercase	)




	def 							a_		(   self  :	Dict	)					-> Tuple:
						__snake_case          =	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*lowercase	)




	def 							a_		(   self  :	Optional[int]	)					-> Tuple:
						__snake_case          =	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*lowercase	)




def       snake_case__	(       ):
					__snake_case          =	"""
    <!DOCTYPE html>
    <html>
    <head>
    <title>Page Title</title>
    </head>
    <body>

    <h1>This is a Heading</h1>
    <p>This is a paragraph.</p>

    </body>
    </html>
    """

					return html_string

@require_torch
class     A__      (      unittest.TestCase     ):




	@cached_property
	def 							a_		(   self  :	List[str]	)					-> int:
						# TODO use from_pretrained here
						__snake_case          =	MarkupLMFeatureExtractor()
						__snake_case          =	MarkupLMTokenizer.from_pretrained("""microsoft/markuplm-base"""	)

						return MarkupLMProcessor(lowercase      ,    lowercase	)




	@slow
	def 							a_		(   self  :	int	)					-> List[Any]:
						__snake_case          =	MarkupLMModel.from_pretrained("""microsoft/markuplm-base"""	).to(lowercase	)

						__snake_case          =	self.default_processor

						__snake_case          =	processor(prepare_html_string()      ,    return_tensors="""pt"""	)
						__snake_case          =	inputs.to(lowercase	)

						# forward pass
						with torch.no_grad():
											__snake_case          =	model(**lowercase	)

						# verify the last hidden states
						__snake_case          =	torch.Size([1, 14, 768]	)
						self.assertEqual(outputs.last_hidden_state.shape      ,    lowercase	)

						__snake_case          =	torch.tensor(
						    [[0.06_75, -0.00_52, 0.50_01], [-0.22_81, 0.08_02, 0.21_92], [-0.05_83, -0.33_11, 0.11_85]]	).to(lowercase	)

						self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3]      ,    lowercase      ,    atol=1e-4	)	)








"""simple docstring"""

from functools import lru_cache




@lru_cache
def       snake_case__	(       lowerCAmelCase   :		int		):
					if not isinstance(lowerCAmelCase				,					lowerCAmelCase		):
										raise TypeError("""k must be an integer."""		)
					if k < 0:
										raise ValueError("""k integer must be greater or equal to zero."""		)
					if k == 0:
										return 0
					elif k == 1:
										return 1
					else:
										return fibonacci(k - 1		) + fibonacci(k - 2		)




def       snake_case__	(       lowerCAmelCase   :		list				,					lowerCAmelCase   :		int		):
					__snake_case          =	len(lowerCAmelCase		)
					# Find m such that F_m >= n where F_i is the i_th fibonacci number.
					__snake_case          =	0
					while True:
										if fibonacci(lowerCAmelCase		) >= len_list:
															__snake_case          =	i
															break
										i += 1
					__snake_case          =	0
					while fibb_k > 0:
										__snake_case          =	min(
										    offset + fibonacci(fibb_k - 1		)				,					len_list - 1		)  # Prevent out of range
										__snake_case          =	arr[index_k]
										if item_k_1 == val:
															return index_k
										elif val < item_k_1:
															fibb_k -= 1
										elif val > item_k_1:
															offset += fibonacci(fibb_k - 1		)
															fibb_k -= 2
					else:
										return -1


if __name__ == "__main__":
		import doctest

		doctest.testmod()


