'''simple docstring'''

import unittest

from transformers import SqueezeBertConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

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


if is_torch_available():
 import torch

 from transformers import (
     SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
     SqueezeBertForMaskedLM,
     SqueezeBertForMultipleChoice,
     SqueezeBertForQuestionAnswering,
     SqueezeBertForSequenceClassification,
     SqueezeBertForTokenClassification,
     SqueezeBertModel,
 )







class 				_lowercase     (				UpperCAmelCase__			):


 '''simple docstring'''






 def __init__(      self   :	Any      ,       SCREAMING_SNAKE_CASE__   :	int      ,       SCREAMING_SNAKE_CASE__   :	Optional[Any]=13      ,       SCREAMING_SNAKE_CASE__   :	List[str]=7      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]=True      ,       SCREAMING_SNAKE_CASE__   :	Optional[int]=True      ,       SCREAMING_SNAKE_CASE__   :	List[str]=False      ,       SCREAMING_SNAKE_CASE__   :	Any=True      ,       SCREAMING_SNAKE_CASE__   :	List[Any]=99      ,       SCREAMING_SNAKE_CASE__   :	int=32      ,       SCREAMING_SNAKE_CASE__   :	List[Any]=5      ,       SCREAMING_SNAKE_CASE__   :	Optional[int]=4      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]=64      ,       SCREAMING_SNAKE_CASE__   :	Dict="gelu"      ,       SCREAMING_SNAKE_CASE__   :	Tuple=0.1      ,       SCREAMING_SNAKE_CASE__   :	Dict=0.1      ,       SCREAMING_SNAKE_CASE__   :	List[str]=5_12      ,       SCREAMING_SNAKE_CASE__   :	Dict=16      ,       SCREAMING_SNAKE_CASE__   :	Optional[int]=2      ,       SCREAMING_SNAKE_CASE__   :	str=0.0_2      ,       SCREAMING_SNAKE_CASE__   :	List[str]=3      ,       SCREAMING_SNAKE_CASE__   :	Optional[Any]=4      ,       SCREAMING_SNAKE_CASE__   :	str=None      ,       SCREAMING_SNAKE_CASE__   :	int=2      ,       SCREAMING_SNAKE_CASE__   :	str=2      ,       SCREAMING_SNAKE_CASE__   :	str=2      ,       SCREAMING_SNAKE_CASE__   :	Any=2      ,       SCREAMING_SNAKE_CASE__   :	List[str]=4      ,       SCREAMING_SNAKE_CASE__   :	Dict=1      ,       )  ->    Optional[int]:
  __lowerCAmelCase											=						parent
  __lowerCAmelCase											=						batch_size
  __lowerCAmelCase											=						seq_length
  __lowerCAmelCase											=						is_training
  __lowerCAmelCase											=						use_input_mask
  __lowerCAmelCase											=						use_token_type_ids
  __lowerCAmelCase											=						use_labels
  __lowerCAmelCase											=						vocab_size
  __lowerCAmelCase											=						hidden_size
  __lowerCAmelCase											=						num_hidden_layers
  __lowerCAmelCase											=						num_attention_heads
  __lowerCAmelCase											=						intermediate_size
  __lowerCAmelCase											=						hidden_act
  __lowerCAmelCase											=						hidden_dropout_prob
  __lowerCAmelCase											=						attention_probs_dropout_prob
  __lowerCAmelCase											=						max_position_embeddings
  __lowerCAmelCase											=						type_vocab_size
  __lowerCAmelCase											=						type_sequence_label_size
  __lowerCAmelCase											=						initializer_range
  __lowerCAmelCase											=						num_labels
  __lowerCAmelCase											=						num_choices
  __lowerCAmelCase											=						scope
  __lowerCAmelCase											=						q_groups
  __lowerCAmelCase											=						k_groups
  __lowerCAmelCase											=						v_groups
  __lowerCAmelCase											=						post_attention_groups
  __lowerCAmelCase											=						intermediate_groups
  __lowerCAmelCase											=						output_groups
 def a					(      self   :	str							)  ->    Any:
  __lowerCAmelCase											=						ids_tensor([self.batch_size, self.seq_length]      ,       self.vocab_size							)

  __lowerCAmelCase											=						None
  if self.use_input_mask:
   __lowerCAmelCase											=						random_attention_mask([self.batch_size, self.seq_length]							)

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

  __lowerCAmelCase											=						self.get_config()

  return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels
 def a					(      self   :	Tuple							)  ->    Tuple:
  return SqueezeBertConfig(
      embedding_size=self.hidden_size      ,       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      ,       attention_probs_dropout_prob=self.hidden_dropout_prob      ,       attention_dropout=self.attention_probs_dropout_prob      ,       max_position_embeddings=self.max_position_embeddings      ,       initializer_range=self.initializer_range      ,       q_groups=self.q_groups      ,       k_groups=self.k_groups      ,       v_groups=self.v_groups      ,       post_attention_groups=self.post_attention_groups      ,       intermediate_groups=self.intermediate_groups      ,       output_groups=self.output_groups      ,       )
 def a					(      self   :	int      ,       SCREAMING_SNAKE_CASE__   :	Any      ,       SCREAMING_SNAKE_CASE__   :	int      ,       SCREAMING_SNAKE_CASE__   :	str      ,       SCREAMING_SNAKE_CASE__   :	List[Any]      ,       SCREAMING_SNAKE_CASE__   :	int      ,       SCREAMING_SNAKE_CASE__   :	List[str]							)  ->    int:
  __lowerCAmelCase											=						SqueezeBertModel(config=UpperCAmelCase__							)
  model.to(UpperCAmelCase__							)
  model.eval()
  __lowerCAmelCase											=						model(UpperCAmelCase__      ,       UpperCAmelCase__							)
  __lowerCAmelCase											=						model(UpperCAmelCase__							)
  self.parent.assertEqual(result.last_hidden_state.shape      ,       (self.batch_size, self.seq_length, self.hidden_size)							)
 def a					(      self   :	int      ,       SCREAMING_SNAKE_CASE__   :	List[Any]      ,       SCREAMING_SNAKE_CASE__   :	List[str]      ,       SCREAMING_SNAKE_CASE__   :	int      ,       SCREAMING_SNAKE_CASE__   :	str      ,       SCREAMING_SNAKE_CASE__   :	Dict      ,       SCREAMING_SNAKE_CASE__   :	Optional[int]							)  ->    Dict:
  __lowerCAmelCase											=						SqueezeBertForMaskedLM(config=UpperCAmelCase__							)
  model.to(UpperCAmelCase__							)
  model.eval()
  __lowerCAmelCase											=						model(UpperCAmelCase__      ,       attention_mask=UpperCAmelCase__      ,       labels=UpperCAmelCase__							)
  self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, self.seq_length, self.vocab_size)							)
 def a					(      self   :	Optional[Any]      ,       SCREAMING_SNAKE_CASE__   :	str      ,       SCREAMING_SNAKE_CASE__   :	Optional[int]      ,       SCREAMING_SNAKE_CASE__   :	Optional[int]      ,       SCREAMING_SNAKE_CASE__   :	str      ,       SCREAMING_SNAKE_CASE__   :	List[Any]      ,       SCREAMING_SNAKE_CASE__   :	List[Any]							)  ->    Dict:
  __lowerCAmelCase											=						SqueezeBertForQuestionAnswering(config=UpperCAmelCase__							)
  model.to(UpperCAmelCase__							)
  model.eval()
  __lowerCAmelCase											=						model(
      UpperCAmelCase__      ,       attention_mask=UpperCAmelCase__      ,       start_positions=UpperCAmelCase__      ,       end_positions=UpperCAmelCase__							)
  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   :	Tuple      ,       SCREAMING_SNAKE_CASE__   :	int      ,       SCREAMING_SNAKE_CASE__   :	List[Any]      ,       SCREAMING_SNAKE_CASE__   :	Optional[Any]      ,       SCREAMING_SNAKE_CASE__   :	Optional[Any]      ,       SCREAMING_SNAKE_CASE__   :	List[str]      ,       SCREAMING_SNAKE_CASE__   :	Dict							)  ->    Any:
  __lowerCAmelCase											=						self.num_labels
  __lowerCAmelCase											=						SqueezeBertForSequenceClassification(UpperCAmelCase__							)
  model.to(UpperCAmelCase__							)
  model.eval()
  __lowerCAmelCase											=						model(UpperCAmelCase__      ,       attention_mask=UpperCAmelCase__      ,       labels=UpperCAmelCase__							)
  self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, self.num_labels)							)
 def a					(      self   :	Dict      ,       SCREAMING_SNAKE_CASE__   :	List[Any]      ,       SCREAMING_SNAKE_CASE__   :	Optional[Any]      ,       SCREAMING_SNAKE_CASE__   :	Optional[Any]      ,       SCREAMING_SNAKE_CASE__   :	Optional[int]      ,       SCREAMING_SNAKE_CASE__   :	List[str]      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]							)  ->    Optional[Any]:
  __lowerCAmelCase											=						self.num_labels
  __lowerCAmelCase											=						SqueezeBertForTokenClassification(config=UpperCAmelCase__							)
  model.to(UpperCAmelCase__							)
  model.eval()

  __lowerCAmelCase											=						model(UpperCAmelCase__      ,       attention_mask=UpperCAmelCase__      ,       labels=UpperCAmelCase__							)
  self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, self.seq_length, self.num_labels)							)
 def a					(      self   :	Tuple      ,       SCREAMING_SNAKE_CASE__   :	Any      ,       SCREAMING_SNAKE_CASE__   :	Tuple      ,       SCREAMING_SNAKE_CASE__   :	Union[str, Any]      ,       SCREAMING_SNAKE_CASE__   :	List[Any]      ,       SCREAMING_SNAKE_CASE__   :	int      ,       SCREAMING_SNAKE_CASE__   :	List[str]							)  ->    Optional[Any]:
  __lowerCAmelCase											=						self.num_choices
  __lowerCAmelCase											=						SqueezeBertForMultipleChoice(config=UpperCAmelCase__							)
  model.to(UpperCAmelCase__							)
  model.eval()
  __lowerCAmelCase											=						input_ids.unsqueeze(1							).expand(-1      ,       self.num_choices      ,       -1							).contiguous()
  __lowerCAmelCase											=						input_mask.unsqueeze(1							).expand(-1      ,       self.num_choices      ,       -1							).contiguous()
  __lowerCAmelCase											=						model(
      UpperCAmelCase__      ,       attention_mask=UpperCAmelCase__      ,       labels=UpperCAmelCase__      ,       )
  self.parent.assertEqual(result.logits.shape      ,       (self.batch_size, self.num_choices)							)





 def a					(      self   :	int							)  ->    Dict:
  __lowerCAmelCase											=						self.prepare_config_and_inputs()
  ((__lowerCAmelCase)							,       (__lowerCAmelCase)							,       (__lowerCAmelCase)							,       (__lowerCAmelCase)							,       (__lowerCAmelCase)							,       (__lowerCAmelCase))											=						config_and_inputs
  __lowerCAmelCase											=						{"""input_ids""": input_ids, """attention_mask""": input_mask}
  return config, inputs_dict







@require_torch
class 				_lowercase     (				UpperCAmelCase__  ,							UpperCAmelCase__  ,							unittest.TestCase			):


 '''simple docstring'''






 _SCREAMING_SNAKE_CASE     :       Optional[Any]      	=					(
     (
         SqueezeBertModel,
         SqueezeBertForMaskedLM,
         SqueezeBertForMultipleChoice,
         SqueezeBertForQuestionAnswering,
         SqueezeBertForSequenceClassification,
         SqueezeBertForTokenClassification,
     )
     if is_torch_available()
     else None
 )
 _SCREAMING_SNAKE_CASE     :       Tuple      	=					(
     {
         "feature-extraction": SqueezeBertModel,
         "fill-mask": SqueezeBertForMaskedLM,
         "question-answering": SqueezeBertForQuestionAnswering,
         "text-classification": SqueezeBertForSequenceClassification,
         "token-classification": SqueezeBertForTokenClassification,
         "zero-shot": SqueezeBertForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 _SCREAMING_SNAKE_CASE     :       Tuple      	=					False
 _SCREAMING_SNAKE_CASE     :       List[str]      	=					True
 _SCREAMING_SNAKE_CASE     :       Dict      	=					False
 def a					(      self   :	int							)  ->    Optional[int]:
  __lowerCAmelCase											=						SqueezeBertModelTester(self							)
  __lowerCAmelCase											=						ConfigTester(self      ,       config_class=UpperCAmelCase__      ,       dim=37							)
 def a					(      self   :	List[Any]							)  ->    str:
  self.config_tester.run_common_tests()
 def a					(      self   :	Any							)  ->    Any:
  __lowerCAmelCase											=						self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_squeezebert_model(*UpperCAmelCase__							)
 def a					(      self   :	Union[str, Any]							)  ->    int:
  __lowerCAmelCase											=						self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_squeezebert_for_masked_lm(*UpperCAmelCase__							)
 def a					(      self   :	Any							)  ->    int:
  __lowerCAmelCase											=						self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_squeezebert_for_question_answering(*UpperCAmelCase__							)
 def a					(      self   :	Dict							)  ->    Dict:
  __lowerCAmelCase											=						self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_squeezebert_for_sequence_classification(*UpperCAmelCase__							)
 def a					(      self   :	Optional[Any]							)  ->    Tuple:
  __lowerCAmelCase											=						self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_squeezebert_for_token_classification(*UpperCAmelCase__							)
 def a					(      self   :	Optional[int]							)  ->    List[str]:
  __lowerCAmelCase											=						self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_squeezebert_for_multiple_choice(*UpperCAmelCase__							)





 @slow
 def a					(      self   :	Optional[Any]							)  ->    str:
  for model_name in SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
   __lowerCAmelCase											=						SqueezeBertModel.from_pretrained(UpperCAmelCase__							)
   self.assertIsNotNone(UpperCAmelCase__							)







@require_sentencepiece
@require_tokenizers
@require_torch
class 				_lowercase     (				unittest.TestCase			):


 '''simple docstring'''






 @slow
 def a					(      self   :	Optional[Any]							)  ->    Union[str, Any]:
  __lowerCAmelCase											=						SqueezeBertForSequenceClassification.from_pretrained("""squeezebert/squeezebert-mnli"""							)

  __lowerCAmelCase											=						torch.tensor([[1, 2_94_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 13, 15_88, 2]]							)
  __lowerCAmelCase											=						model(UpperCAmelCase__							)[0]
  __lowerCAmelCase											=						torch.Size((1, 3)							)
  self.assertEqual(output.shape      ,       UpperCAmelCase__							)
  __lowerCAmelCase											=						torch.tensor([[0.6_4_0_1, -0.0_3_4_9, -0.6_0_4_1]]							)
  self.assertTrue(torch.allclose(UpperCAmelCase__      ,       UpperCAmelCase__      ,       atol=1e-4							)							)










"""simple docstring"""







from collections import defaultdict
from math import ceil, sqrt




def    UpperCAmelCase__       (lowerCAmelCase_ = 100_0000  ,						lowerCAmelCase_ = 10   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				defaultdict(lowerCAmelCase_   )

					for outer_width in range(3  ,						(t_limit // 4) + 2   ):
										if outer_width * outer_width > t_limit:
															__SCREAMING_SNAKE_CASE						   =				max(
															    ceil(sqrt(outer_width * outer_width - t_limit   )   )  ,						1   )
										else:
															__SCREAMING_SNAKE_CASE						   =				1

										hole_width_lower_bound += (outer_width - hole_width_lower_bound) % 2

										for hole_width in range(lowerCAmelCase_  ,						outer_width - 1  ,						2   ):
															count[outer_width * outer_width - hole_width * hole_width] += 1

					return sum(1 for n in count.values() if 1 <= n <= 10   )


if __name__ == "__main__":
		print(F"{solution() = }")
