



'''simple docstring'''





from math import ceil





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase		)		-> Optional[int]:
      snake_case__  :    int    						=      list(range(0     ,   _lowerCAmelCase		)		)

      snake_case__  :    str    						=      [item for sublist in list(device_map.values()		) for item in sublist]

      # Duplicate check
      snake_case__  :    str    						=      []
      for i in device_map_blocks:
            if device_map_blocks.count(_lowerCAmelCase		) > 1 and i not in duplicate_blocks:
                  duplicate_blocks.append(_lowerCAmelCase		)
    # Missing blocks
      snake_case__  :    Union[str, Any]    						=      [i for i in blocks if i not in device_map_blocks]
      snake_case__  :    Dict    						=      [i for i in device_map_blocks if i not in blocks]

      if len(_lowerCAmelCase		) != 0:
            raise ValueError(
                """Duplicate attention blocks specified in device_map. Attention blocks must be specified to one device."""
                """ These attention blocks were specified more than once: """ + str(_lowerCAmelCase		)		)
      if len(_lowerCAmelCase		) != 0:
            raise ValueError(
                """There are attention blocks for this model that are not specified in the device_map. Add these attention """
                """blocks to a device on the device_map: """ + str(_lowerCAmelCase		)		)
      if len(_lowerCAmelCase		) != 0:
            raise ValueError(
                """The device_map contains more attention blocks than this model has. Remove these from the device_map:"""
                + str(_lowerCAmelCase		)		)





def 						__snake_case(				_lowerCAmelCase     ,   _lowerCAmelCase		)		-> Optional[Any]:
      snake_case__  :    str    						=      list(range(_lowerCAmelCase		)		)
      snake_case__  :    Dict    						=      int(ceil(n_layers / len(_lowerCAmelCase		)		)		)
      snake_case__  :    Optional[int]    						=      [layers[i : i + n_blocks] for i in range(0     ,   _lowerCAmelCase     ,   _lowerCAmelCase		)]

      return dict(zip(_lowerCAmelCase     ,   _lowerCAmelCase		)		)





'''simple docstring'''





import numpy as np

from transformers import Pipeline





def 						__snake_case(				_lowerCAmelCase		)		-> Optional[int]:
      snake_case__  :    Optional[Any]    						=      np.max(_lowerCAmelCase     ,   axis=-1     ,   keepdims=_lowerCAmelCase		)
      snake_case__  :    List[str]    						=      np.exp(outputs - maxes		)
      return shifted_exp / shifted_exp.sum(axis=-1     ,   keepdims=_lowerCAmelCase		)







class     UpperCAmelCase_       (       _a	):
    """simple docstring"""







    def lowerCamelCase       (    self					:     Optional[Any] ,     **snake_case_					:     int						):
          snake_case__  :    Optional[int]    						=      {}
          if "second_text" in kwargs:
                snake_case__  :    Union[str, Any]    						=      kwargs["""second_text"""]
          return preprocess_kwargs, {}, {}




    def lowerCamelCase       (    self					:     str ,     snake_case_					:     Tuple ,     snake_case_					:     Union[str, Any]=None						):
          return self.tokenizer(snake_case_ ,     text_pair=snake_case_ ,     return_tensors=self.framework						)




    def lowerCamelCase       (    self					:     List[Any] ,     snake_case_					:     Dict						):
          return self.model(**snake_case_						)




    def lowerCamelCase       (    self					:     int ,     snake_case_					:     List[Any]						):
          snake_case__  :    Union[str, Any]    						=      model_outputs.logits[0].numpy()
          snake_case__  :    List[str]    						=      softmax(snake_case_						)

          snake_case__  :    List[str]    						=      np.argmax(snake_case_						)
          snake_case__  :    List[str]    						=      self.model.config.idalabel[best_class]
          snake_case__  :    Optional[int]    						=      probabilities[best_class].item()
          snake_case__  :    str    						=      logits.tolist()
          return {"label": label, "score": score, "logits": logits}
