


'''simple docstring'''


import torch
from torch import nn





class     lowercase__  (						nn.Module					):





							'''simple docstring'''


							def __init__(    self    ,					__snake_case    ,					__snake_case    ,					__snake_case    ,					__snake_case    ,					__snake_case=1    ,					__snake_case=False  ):
											super().__init__()

											_SCREAMING_SNAKE_CASE :       Tuple     		=      n_token
											_SCREAMING_SNAKE_CASE :       str     		=      d_embed
											_SCREAMING_SNAKE_CASE :       Any     		=      d_proj

											_SCREAMING_SNAKE_CASE :       Any     		=      cutoffs + [n_token]
											_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      [0] + self.cutoffs
											_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      div_val

											_SCREAMING_SNAKE_CASE :       Tuple     		=      self.cutoffs[0]
											_SCREAMING_SNAKE_CASE :       int     		=      len(self.cutoffs  ) - 1
											_SCREAMING_SNAKE_CASE :       str     		=      self.shortlist_size + self.n_clusters

											if self.n_clusters > 0:
															_SCREAMING_SNAKE_CASE :       List[Any]     		=      nn.Parameter(torch.zeros(self.n_clusters    ,					self.d_embed  )  )
															_SCREAMING_SNAKE_CASE :       int     		=      nn.Parameter(torch.zeros(self.n_clusters  )  )

											_SCREAMING_SNAKE_CASE :       int     		=      nn.ModuleList()
											_SCREAMING_SNAKE_CASE :       str     		=      nn.ParameterList()

											if div_val == 1:
															for i in range(len(self.cutoffs  )  ):
																			if d_proj != d_embed:
																							self.out_projs.append(nn.Parameter(torch.FloatTensor(__snake_case    ,					__snake_case  )  )  )
																			else:
																							self.out_projs.append(__snake_case  )

															self.out_layers.append(nn.Linear(__snake_case    ,					__snake_case  )  )
											else:
															for i in range(len(self.cutoffs  )  ):
																			_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE :       str     		=      self.cutoff_ends[i], self.cutoff_ends[i + 1]
																			_SCREAMING_SNAKE_CASE :       int     		=      d_embed // (div_val**i)

																			self.out_projs.append(nn.Parameter(torch.FloatTensor(__snake_case    ,					__snake_case  )  )  )

																			self.out_layers.append(nn.Linear(__snake_case    ,					r_idx - l_idx  )  )

											_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      keep_order






							def UpperCAmelCase_	(    self    ,					__snake_case    ,					__snake_case    ,					__snake_case    ,					__snake_case  ):
											if proj is None:
															_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      nn.functional.linear(__snake_case    ,					__snake_case    ,					bias=__snake_case  )
											else:
															# if CUDA_MAJOR <= 9 and CUDA_MINOR <= 1:
															_SCREAMING_SNAKE_CASE :       Dict     		=      nn.functional.linear(__snake_case    ,					proj.t().contiguous()  )
															_SCREAMING_SNAKE_CASE :       Optional[int]     		=      nn.functional.linear(__snake_case    ,					__snake_case    ,					bias=__snake_case  )
															# else:
															#     logit = torch.einsum('bd,de,ev->bv', (hidden, proj, weight.t()))
															#     if bias is not None:
															#         logit = logit + bias

											return logit






							def UpperCAmelCase_	(    self    ,					__snake_case    ,					__snake_case=None    ,					__snake_case=False  ):

											if labels is not None:
															# Shift so that tokens < n predict n
															_SCREAMING_SNAKE_CASE :       Tuple     		=      hidden[..., :-1, :].contiguous()
															_SCREAMING_SNAKE_CASE :       Tuple     		=      labels[..., 1:].contiguous()
															_SCREAMING_SNAKE_CASE :       List[Any]     		=      hidden.view(-1    ,					hidden.size(-1  )  )
															_SCREAMING_SNAKE_CASE :       str     		=      labels.view(-1  )
															if hidden.size(0  ) != labels.size(0  ):
																			raise RuntimeError("""Input and labels should have the same size in the batch dimension."""  )
											else:
															_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      hidden.view(-1    ,					hidden.size(-1  )  )

											if self.n_clusters == 0:
															_SCREAMING_SNAKE_CASE :       int     		=      self._compute_logit(__snake_case    ,					self.out_layers[0].weight    ,					self.out_layers[0].bias    ,					self.out_projs[0]  )
															if labels is not None:
																			_SCREAMING_SNAKE_CASE :       Optional[int]     		=      labels != -100
																			_SCREAMING_SNAKE_CASE :       str     		=      torch.zeros_like(__snake_case    ,					dtype=hidden.dtype    ,					device=hidden.device  )
																			_SCREAMING_SNAKE_CASE :       Any     		=      (
																			    -nn.functional.log_softmax(__snake_case    ,					dim=-1  )[mask].gather(1    ,					labels[mask].unsqueeze(1  )  ).squeeze(1  )
																			)
															else:
																			_SCREAMING_SNAKE_CASE :       List[str]     		=      nn.functional.log_softmax(__snake_case    ,					dim=-1  )
											else:
															# construct weights and biases
															_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE :       List[Any]     		=      [], []
															for i in range(len(self.cutoffs  )  ):
																			if self.div_val == 1:
																							_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE :       int     		=      self.cutoff_ends[i], self.cutoff_ends[i + 1]
																							_SCREAMING_SNAKE_CASE :       Optional[int]     		=      self.out_layers[0].weight[l_idx:r_idx]
																							_SCREAMING_SNAKE_CASE :       int     		=      self.out_layers[0].bias[l_idx:r_idx]
																			else:
																							_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      self.out_layers[i].weight
																							_SCREAMING_SNAKE_CASE :       Optional[int]     		=      self.out_layers[i].bias

																			if i == 0:
																							_SCREAMING_SNAKE_CASE :       Any     		=      torch.cat([weight_i, self.cluster_weight]    ,					dim=0  )
																							_SCREAMING_SNAKE_CASE :       str     		=      torch.cat([bias_i, self.cluster_bias]    ,					dim=0  )

																			weights.append(__snake_case  )
																			biases.append(__snake_case  )

															_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE :       List[Any]     		=      weights[0], biases[0], self.out_projs[0]

															_SCREAMING_SNAKE_CASE :       Optional[int]     		=      self._compute_logit(__snake_case    ,					__snake_case    ,					__snake_case    ,					__snake_case  )
															_SCREAMING_SNAKE_CASE :       Dict     		=      nn.functional.log_softmax(__snake_case    ,					dim=1  )

															if labels is None:
																			_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      hidden.new_empty((head_logit.size(0  ), self.n_token)  )
															else:
																			_SCREAMING_SNAKE_CASE :       Any     		=      torch.zeros_like(__snake_case    ,					dtype=hidden.dtype    ,					device=hidden.device  )

															_SCREAMING_SNAKE_CASE :       Tuple     		=      0
															_SCREAMING_SNAKE_CASE :       Any     		=      [0] + self.cutoffs
															for i in range(len(__snake_case  ) - 1  ):
																			_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE :       Optional[Any]     		=      cutoff_values[i], cutoff_values[i + 1]

																			if labels is not None:
																							_SCREAMING_SNAKE_CASE :       Optional[int]     		=      (labels >= l_idx) & (labels < r_idx)
																							_SCREAMING_SNAKE_CASE :       Any     		=      mask_i.nonzero().squeeze()

																							if indices_i.numel() == 0:
																											continue

																							_SCREAMING_SNAKE_CASE :       Dict     		=      labels.index_select(0    ,					__snake_case  ) - l_idx
																							_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      head_logprob.index_select(0    ,					__snake_case  )
																							_SCREAMING_SNAKE_CASE :       str     		=      hidden.index_select(0    ,					__snake_case  )
																			else:
																							_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      hidden

																			if i == 0:
																							if labels is not None:
																											_SCREAMING_SNAKE_CASE :       Dict     		=      head_logprob_i.gather(1    ,					target_i[:, None]  ).squeeze(1  )
																							else:
																											_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      head_logprob[:, : self.cutoffs[0]]
																			else:
																							_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE :       Optional[int]     		=      weights[i], biases[i], self.out_projs[i]

																							_SCREAMING_SNAKE_CASE :       Tuple     		=      self._compute_logit(__snake_case    ,					__snake_case    ,					__snake_case    ,					__snake_case  )
																							_SCREAMING_SNAKE_CASE :       Optional[int]     		=      nn.functional.log_softmax(__snake_case    ,					dim=1  )
																							_SCREAMING_SNAKE_CASE :       Any     		=      self.cutoffs[0] + i - 1  # No probability for the head cluster
																							if labels is not None:
																											_SCREAMING_SNAKE_CASE :       int     		=      head_logprob_i[:, cluster_prob_idx] + tail_logprob_i.gather(
																											    1    ,					target_i[:, None]  ).squeeze(1  )
																							else:
																											_SCREAMING_SNAKE_CASE :       str     		=      head_logprob[:, cluster_prob_idx, None] + tail_logprob_i
																											_SCREAMING_SNAKE_CASE :       Tuple     		=      logprob_i

																			if labels is not None:
																							if (hasattr(self    ,					"""keep_order"""  ) and self.keep_order) or keep_order:
																											out.index_copy_(0    ,					__snake_case    ,					-logprob_i  )
																							else:
																											out[offset : offset + logprob_i.size(0  )].copy_(-logprob_i  )
																							offset += logprob_i.size(0  )

											return out






							def UpperCAmelCase_	(    self    ,					__snake_case  ):
											if self.n_clusters == 0:
															_SCREAMING_SNAKE_CASE :       Tuple     		=      self._compute_logit(__snake_case    ,					self.out_layers[0].weight    ,					self.out_layers[0].bias    ,					self.out_projs[0]  )
															return nn.functional.log_softmax(__snake_case    ,					dim=-1  )
											else:
															# construct weights and biases
															_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE :       List[str]     		=      [], []
															for i in range(len(self.cutoffs  )  ):
																			if self.div_val == 1:
																							_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE :       Optional[int]     		=      self.cutoff_ends[i], self.cutoff_ends[i + 1]
																							_SCREAMING_SNAKE_CASE :       Any     		=      self.out_layers[0].weight[l_idx:r_idx]
																							_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      self.out_layers[0].bias[l_idx:r_idx]
																			else:
																							_SCREAMING_SNAKE_CASE :       int     		=      self.out_layers[i].weight
																							_SCREAMING_SNAKE_CASE :       Any     		=      self.out_layers[i].bias

																			if i == 0:
																							_SCREAMING_SNAKE_CASE :       List[str]     		=      torch.cat([weight_i, self.cluster_weight]    ,					dim=0  )
																							_SCREAMING_SNAKE_CASE :       Optional[int]     		=      torch.cat([bias_i, self.cluster_bias]    ,					dim=0  )

																			weights.append(__snake_case  )
																			biases.append(__snake_case  )

															_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE :       Dict     		=      weights[0], biases[0], self.out_projs[0]
															_SCREAMING_SNAKE_CASE :       Optional[int]     		=      self._compute_logit(__snake_case    ,					__snake_case    ,					__snake_case    ,					__snake_case  )

															_SCREAMING_SNAKE_CASE :       Any     		=      hidden.new_empty((head_logit.size(0  ), self.n_token)  )
															_SCREAMING_SNAKE_CASE :       List[Any]     		=      nn.functional.log_softmax(__snake_case    ,					dim=1  )

															_SCREAMING_SNAKE_CASE :       Tuple     		=      [0] + self.cutoffs
															for i in range(len(__snake_case  ) - 1  ):
																			_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE :       Optional[Any]     		=      cutoff_values[i], cutoff_values[i + 1]

																			if i == 0:
																							_SCREAMING_SNAKE_CASE :       Dict     		=      head_logprob[:, : self.cutoffs[0]]
																			else:
																							_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE :       List[Any]     		=      weights[i], biases[i], self.out_projs[i]

																							_SCREAMING_SNAKE_CASE :       int     		=      self._compute_logit(__snake_case    ,					__snake_case    ,					__snake_case    ,					__snake_case  )
																							_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      nn.functional.log_softmax(__snake_case    ,					dim=1  )

																							_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      head_logprob[:, -i] + tail_logprob_i
																							_SCREAMING_SNAKE_CASE :       List[Any]     		=      logprob_i

															return out








'''simple docstring'''


def 			snake_case_   (  SCREAMING_SNAKE_CASE__							,      SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				return int((input_a, input_a).count(0     ) != 0     )







def 			snake_case_   (  ):







				"""simple docstring"""





				assert nand_gate(0							,      0     ) == 1
				assert nand_gate(0							,      1     ) == 1
				assert nand_gate(1							,      0     ) == 1
				assert nand_gate(1							,      1     ) == 0


if __name__ == "__main__":
				print(nand_gate(0, 0))
				print(nand_gate(0, 1))
				print(nand_gate(1, 0))
				print(nand_gate(1, 1))




