





'''simple docstring'''







import os
import unittest

from transformers.models.bartpho.tokenization_bartpho import VOCAB_FILES_NAMES, BartphoTokenizer
from transformers.testing_utils import get_tests_dir

from ...test_tokenization_common import TokenizerTesterMixin


snake_case_     :       int						=  get_tests_dir("fixtures/test_sentencepiece_bpe.model")


class 					__a      (lowerCamelCase       ,		unittest.TestCase     ):
							__a					:   str									=       BartphoTokenizer
							__a					:   Any									=       False
							__a					:   Dict									=       True

							def     UpperCAmelCase__	(							self							:     str   )					->       Optional[Any]:







													"""simple docstring"""
													super().setUp()

													UpperCAmelCase_			:      Tuple     						=  ['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est''']
													UpperCAmelCase_			:      Optional[int]     						=  dict(zip(__magic_name__       ,     range(len(__magic_name__   )   )   )   )
													UpperCAmelCase_			:      Optional[int]     						=  {'''unk_token''': '''<unk>'''}

													UpperCAmelCase_			:      Dict     						=  os.path.join(self.tmpdirname       ,     VOCAB_FILES_NAMES['''monolingual_vocab_file''']   )
													with open(self.monolingual_vocab_file       ,     '''w'''       ,     encoding='''utf-8'''   ) as fp:
																			for token in vocab_tokens:
																									fp.write(F"""{token} {vocab_tokens[token]}\n"""   )

													UpperCAmelCase_			:      int     						=  BartphoTokenizer(__magic_name__       ,     self.monolingual_vocab_file       ,     **self.special_tokens_map   )
													tokenizer.save_pretrained(self.tmpdirname   )

							def     UpperCAmelCase__	(							self							:     str       ,     **__magic_name__							:     Dict   )					->       Optional[Any]:







													"""simple docstring"""
													kwargs.update(self.special_tokens_map   )
													return BartphoTokenizer.from_pretrained(self.tmpdirname       ,     **__magic_name__   )

							def     UpperCAmelCase__	(							self							:     Dict       ,     __magic_name__							:     Tuple   )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[Any]     						=  '''This is a là test'''
													UpperCAmelCase_			:      List[Any]     						=  '''This is a<unk><unk> test'''
													return input_text, output_text



							def     UpperCAmelCase__	(							self							:     List[Any]   )					->       Any:







													"""simple docstring"""
													UpperCAmelCase_			:      str     						=  BartphoTokenizer(__magic_name__       ,     self.monolingual_vocab_file       ,     **self.special_tokens_map   )
													UpperCAmelCase_			:      str     						=  '''This is a là test'''
													UpperCAmelCase_			:      int     						=  '''▁This ▁is ▁a ▁l à ▁t est'''.split()
													UpperCAmelCase_			:      str     						=  tokenizer.tokenize(__magic_name__   )
													self.assertListEqual(__magic_name__       ,     __magic_name__   )

													UpperCAmelCase_			:      Dict     						=  tokens + [tokenizer.unk_token]
													UpperCAmelCase_			:      Dict     						=  [4, 5, 6, 3, 3, 7, 8, 3]
													self.assertListEqual(tokenizer.convert_tokens_to_ids(__magic_name__   )       ,     __magic_name__   )












'''simple docstring'''







import unittest

import torch
from torch import nn

from diffusers.models.activations import get_activation


class 					__a      (unittest.TestCase     ):

							def     UpperCAmelCase__	(							self							:     Dict   )					->       Dict:







													"""simple docstring"""
													UpperCAmelCase_			:      Dict     						=  get_activation('''swish'''   )

													self.assertIsInstance(__magic_name__       ,     nn.SiLU   )

													self.assertEqual(act(torch.tensor(-1_00       ,     dtype=torch.floataa   )   ).item()       ,     0   )
													self.assertNotEqual(act(torch.tensor(-1       ,     dtype=torch.floataa   )   ).item()       ,     0   )
													self.assertEqual(act(torch.tensor(0       ,     dtype=torch.floataa   )   ).item()       ,     0   )
													self.assertEqual(act(torch.tensor(20       ,     dtype=torch.floataa   )   ).item()       ,     20   )

							def     UpperCAmelCase__	(							self							:     Tuple   )					->       Tuple:







													"""simple docstring"""
													UpperCAmelCase_			:      Union[str, Any]     						=  get_activation('''silu'''   )

													self.assertIsInstance(__magic_name__       ,     nn.SiLU   )

													self.assertEqual(act(torch.tensor(-1_00       ,     dtype=torch.floataa   )   ).item()       ,     0   )
													self.assertNotEqual(act(torch.tensor(-1       ,     dtype=torch.floataa   )   ).item()       ,     0   )
													self.assertEqual(act(torch.tensor(0       ,     dtype=torch.floataa   )   ).item()       ,     0   )
													self.assertEqual(act(torch.tensor(20       ,     dtype=torch.floataa   )   ).item()       ,     20   )

							def     UpperCAmelCase__	(							self							:     Tuple   )					->       Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[int]     						=  get_activation('''mish'''   )

													self.assertIsInstance(__magic_name__       ,     nn.Mish   )

													self.assertEqual(act(torch.tensor(-2_00       ,     dtype=torch.floataa   )   ).item()       ,     0   )
													self.assertNotEqual(act(torch.tensor(-1       ,     dtype=torch.floataa   )   ).item()       ,     0   )
													self.assertEqual(act(torch.tensor(0       ,     dtype=torch.floataa   )   ).item()       ,     0   )
													self.assertEqual(act(torch.tensor(20       ,     dtype=torch.floataa   )   ).item()       ,     20   )



							def     UpperCAmelCase__	(							self							:     str   )					->       Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      List[Any]     						=  get_activation('''gelu'''   )

													self.assertIsInstance(__magic_name__       ,     nn.GELU   )

													self.assertEqual(act(torch.tensor(-1_00       ,     dtype=torch.floataa   )   ).item()       ,     0   )
													self.assertNotEqual(act(torch.tensor(-1       ,     dtype=torch.floataa   )   ).item()       ,     0   )
													self.assertEqual(act(torch.tensor(0       ,     dtype=torch.floataa   )   ).item()       ,     0   )
													self.assertEqual(act(torch.tensor(20       ,     dtype=torch.floataa   )   ).item()       ,     20   )





