
import unittest

from transformers import JukeboxTokenizer
from transformers.testing_utils import require_torch
class 					lowercase__(							unittest.TestCase				):



	"""simple docstring"""




	a     :str       	=      JukeboxTokenizer
	a     :List[Any]       	=      {
	    'artist': 'Zac Brown Band',
	    'genres': 'Country',
	    'lyrics': 'I met a traveller from an antique land,\n        Who said "Two vast and trunkless legs of stone\n        Stand in the desert. . . . Near them, on the sand,\n        Half sunk a shattered visage lies, whose frown,\n        And wrinkled lip, and sneer of cold command,\n        Tell that its sculptor well those passions read\n        Which yet survive, stamped on these lifeless things,\n        The hand that mocked them, and the heart that fed;\n        And on the pedestal, these words appear:\n        My name is Ozymandias, King of Kings;\n        Look on my Works, ye Mighty, and despair!\n        Nothing beside remains. Round the decay\n        Of that colossal Wreck, boundless and bare\n        The lone and level sands stretch far away\n        ',
	}
	@require_torch
	def 		_lowercase    (			self    :     Dict			)			->	str:
					import torch

					lowercase_	    =   JukeboxTokenizer.from_pretrained('''openai/jukebox-1b-lyrics'''			)
					lowercase_	    =   tokenizer(**self.metas			)['''input_ids''']
					# fmt: off
					lowercase_	    =   [
					    torch.tensor([[
					        0, 0, 0, 7_1_6_9, 5_0_7, 9, 7_6, 3_9, 3_1, 4_6, 7_6, 2_7,
					        7_6, 4_6, 4_4, 2_7, 4_8, 3_1, 3_8, 3_8, 3_1, 4_4, 7_6, 3_2,
					        4_4, 4_1, 3_9, 7_6, 2_7, 4_0, 7_6, 2_7, 4_0, 4_6, 3_5, 4_3,
					        4_7, 3_1, 7_6, 3_8, 2_7, 4_0, 3_0, 6_4, 7_8, 7_6, 7_6, 7_6,
					        7_6, 7_6, 7_6, 7_6, 7_6, 2_3, 3_4, 4_1, 7_6, 4_5, 2_7, 3_5,
					        3_0, 7_6, 7_1, 2_0, 4_9, 4_1, 7_6, 4_8, 2_7, 4_5, 4_6, 7_6,
					        2_7, 4_0, 3_0, 7_6, 4_6, 4_4, 4_7, 4_0, 3_7, 3_8, 3_1, 4_5,
					        4_5, 7_6, 3_8, 3_1, 3_3, 4_5, 7_6, 4_1, 3_2, 7_6, 4_5, 4_6,
					        4_1, 4_0, 3_1, 7_8, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6,
					        1_9, 4_6, 2_7, 4_0, 3_0, 7_6, 3_5, 4_0, 7_6, 4_6, 3_4, 3_1,
					        7_6, 3_0, 3_1, 4_5, 3_1, 4_4, 4_6, 6_3, 7_6, 6_3, 7_6, 6_3,
					        7_6, 6_3, 7_6, 1_4, 3_1, 2_7, 4_4, 7_6, 4_6, 3_4, 3_1, 3_9,
					        6_4, 7_6, 4_1, 4_0, 7_6, 4_6, 3_4, 3_1, 7_6, 4_5, 2_7, 4_0,
					        3_0, 6_4, 7_8, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 8,
					        2_7, 3_8, 3_2, 7_6, 4_5, 4_7, 4_0, 3_7, 7_6, 2_7, 7_6, 4_5,
					        3_4, 2_7, 4_6, 4_6, 3_1, 4_4, 3_1, 3_0, 7_6, 4_8, 3_5, 4_5,
					        2_7, 3_3, 3_1, 7_6, 3_8, 3_5, 3_1, 4_5, 6_4, 7_6, 4_9, 3_4,
					        4_1, 4_5, 3_1, 7_6, 3_2, 4_4, 4_1, 4_9, 4_0, 6_4, 7_8, 7_6,
					        7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 1, 4_0, 3_0, 7_6, 4_9,
					        4_4, 3_5, 4_0, 3_7, 3_8, 3_1, 3_0, 7_6, 3_8, 3_5, 4_2, 6_4,
					        7_6, 2_7, 4_0, 3_0, 7_6, 4_5, 4_0, 3_1, 3_1, 4_4, 7_6, 4_1,
					        3_2, 7_6, 2_9, 4_1, 3_8, 3_0, 7_6, 2_9, 4_1, 3_9, 3_9, 2_7,
					        4_0, 3_0, 6_4, 7_8, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6,
					        2_0, 3_1, 3_8, 3_8, 7_6, 4_6, 3_4, 2_7, 4_6, 7_6, 3_5, 4_6,
					        4_5, 7_6, 4_5, 2_9, 4_7, 3_8, 4_2, 4_6, 4_1, 4_4, 7_6, 4_9,
					        3_1, 3_8, 3_8, 7_6, 4_6, 3_4, 4_1, 4_5, 3_1, 7_6, 4_2, 2_7,
					        4_5, 4_5, 3_5, 4_1, 4_0, 4_5, 7_6, 4_4, 3_1, 2_7, 3_0, 7_8,
					        7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 2_3, 3_4, 3_5, 2_9,
					        3_4, 7_6, 5_1, 3_1, 4_6, 7_6, 4_5, 4_7, 4_4, 4_8, 3_5, 4_8,
					        3_1, 6_4, 7_6, 4_5, 4_6, 2_7, 3_9, 4_2, 3_1, 3_0, 7_6, 4_1,
					        4_0, 7_6, 4_6, 3_4, 3_1, 4_5, 3_1, 7_6, 3_8, 3_5, 3_2, 3_1,
					        3_8, 3_1, 4_5, 4_5, 7_6, 4_6, 3_4, 3_5, 4_0, 3_3, 4_5, 6_4,
					        7_8, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 2_0, 3_4, 3_1,
					        7_6, 3_4, 2_7, 4_0, 3_0, 7_6, 4_6, 3_4, 2_7, 4_6, 7_6, 3_9,
					        4_1, 2_9, 3_7, 3_1, 3_0, 7_6, 4_6, 3_4, 3_1, 3_9, 6_4, 7_6,
					        2_7, 4_0, 3_0, 7_6, 4_6, 3_4, 3_1, 7_6, 3_4, 3_1, 2_7, 4_4,
					        4_6, 7_6, 4_6, 3_4, 2_7, 4_6, 7_6, 3_2, 3_1, 3_0, 6_6, 7_8,
					        7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 1, 4_0, 3_0, 7_6,
					        4_1, 4_0, 7_6, 4_6, 3_4, 3_1, 7_6, 4_2, 3_1, 3_0, 3_1, 4_5,
					        4_6, 2_7, 3_8, 6_4, 7_6, 4_6, 3_4, 3_1, 4_5, 3_1, 7_6, 4_9,
					        4_1, 4_4, 3_0, 4_5, 7_6, 2_7, 4_2, 4_2, 3_1, 2_7, 4_4, 6_5,
					        7_8, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 1_3, 5_1, 7_6,
					        4_0, 2_7, 3_9, 3_1, 7_6, 3_5, 4_5, 7_6, 1_5, 5_2, 5_1, 3_9,
					        2_7, 4_0, 3_0, 3_5, 2_7, 4_5, 6_4, 7_6, 1_1, 3_5, 4_0, 3_3,
					        7_6, 4_1, 3_2, 7_6, 1_1, 3_5, 4_0, 3_3, 4_5, 6_6, 7_8, 7_6,
					        7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 1_2, 4_1, 4_1, 3_7, 7_6,
					        4_1, 4_0, 7_6, 3_9, 5_1, 7_6, 2_3, 4_1, 4_4, 3_7, 4_5, 6_4,
					        7_6, 5_1, 3_1, 7_6, 1_3, 3_5, 3_3, 3_4, 4_6, 5_1, 6_4, 7_6,
					        2_7, 4_0, 3_0, 7_6, 3_0, 3_1, 4_5, 4_2, 2_7, 3_5, 4_4, 6_7,
					        7_8, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 1_4, 4_1, 4_6,
					        3_4, 3_5, 4_0, 3_3, 7_6, 2_8, 3_1, 4_5, 3_5, 3_0, 3_1, 7_6,
					        4_4, 3_1, 3_9, 2_7, 3_5, 4_0, 4_5, 6_3, 7_6, 1_8, 4_1, 4_7,
					        4_0, 3_0, 7_6, 4_6, 3_4, 3_1, 7_6, 3_0, 3_1, 2_9, 2_7, 5_1,
					        7_8, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 1_5, 3_2, 7_6,
					        4_6, 3_4, 2_7, 4_6, 7_6, 2_9, 4_1, 3_8, 4_1, 4_5, 4_5, 2_7,
					        3_8, 7_6, 2_3, 4_4, 3_1, 2_9, 3_7, 6_4, 7_6, 2_8, 4_1, 4_7,
					        4_0, 3_0, 3_8, 3_1, 4_5, 4_5, 7_6, 2_7, 4_0, 3_0, 7_6, 2_8,
					        2_7, 4_4, 3_1, 7_8, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6,
					        2_0, 3_4, 3_1, 7_6, 3_8, 4_1, 4_0, 3_1, 7_6, 2_7, 4_0, 3_0,
					        7_6, 3_8, 3_1, 4_8, 3_1, 3_8, 7_6, 4_5, 2_7, 4_0, 3_0, 4_5,
					        7_6, 4_5, 4_6, 4_4, 3_1, 4_6, 2_9, 3_4, 7_6, 3_2, 2_7, 4_4,
					        7_6, 2_7, 4_9, 2_7, 5_1, 7_8, 7_6, 7_6, 7_6, 7_6, 7_6, 7_6,
					        7_6, 7_6]]			),
					    torch.tensor([[0, 0, 0, 1_0_6_9, 1_1]]			),
					    torch.tensor([[0, 0, 0, 1_0_6_9, 1_1]]			),
					]
					# fmt: on
					self.assertTrue(torch.allclose(tokens[0]			,				EXPECTED_OUTPUT[0]			)			)
					self.assertTrue(torch.allclose(tokens[1]			,				EXPECTED_OUTPUT[1]			)			)
					self.assertTrue(torch.allclose(tokens[2]			,				EXPECTED_OUTPUT[2]			)			)




	@require_torch
	def 		_lowercase    (			self    :     List[Any]			)			->	int:
					import torch

					lowercase_	    =   JukeboxTokenizer.from_pretrained('''openai/jukebox-5b-lyrics'''			)
					lowercase_	    =   tokenizer(**self.metas			)['''input_ids''']
					# fmt: off
					lowercase_	    =   [
					    torch.tensor([[
					        0, 0, 0, 1_0_6_9, 1_1, -1, -1, -1, -1, 9, 7_7, 3_9,
					        3_1, 4_6, 7_7, 2_7, 7_7, 4_6, 4_4, 2_7, 4_8, 3_1, 3_8, 3_8,
					        3_1, 4_4, 7_7, 3_2, 4_4, 4_1, 3_9, 7_7, 2_7, 4_0, 7_7, 2_7,
					        4_0, 4_6, 3_5, 4_3, 4_7, 3_1, 7_7, 3_8, 2_7, 4_0, 3_0, 6_4,
					        7_9, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 2_3, 3_4, 4_1,
					        7_7, 4_5, 2_7, 3_5, 3_0, 7_7, 7_2, 2_0, 4_9, 4_1, 7_7, 4_8,
					        2_7, 4_5, 4_6, 7_7, 2_7, 4_0, 3_0, 7_7, 4_6, 4_4, 4_7, 4_0,
					        3_7, 3_8, 3_1, 4_5, 4_5, 7_7, 3_8, 3_1, 3_3, 4_5, 7_7, 4_1,
					        3_2, 7_7, 4_5, 4_6, 4_1, 4_0, 3_1, 7_9, 7_7, 7_7, 7_7, 7_7,
					        7_7, 7_7, 7_7, 7_7, 1_9, 4_6, 2_7, 4_0, 3_0, 7_7, 3_5, 4_0,
					        7_7, 4_6, 3_4, 3_1, 7_7, 3_0, 3_1, 4_5, 3_1, 4_4, 4_6, 6_3,
					        7_7, 6_3, 7_7, 6_3, 7_7, 6_3, 7_7, 1_4, 3_1, 2_7, 4_4, 7_7,
					        4_6, 3_4, 3_1, 3_9, 6_4, 7_7, 4_1, 4_0, 7_7, 4_6, 3_4, 3_1,
					        7_7, 4_5, 2_7, 4_0, 3_0, 6_4, 7_9, 7_7, 7_7, 7_7, 7_7, 7_7,
					        7_7, 7_7, 7_7, 8, 2_7, 3_8, 3_2, 7_7, 4_5, 4_7, 4_0, 3_7,
					        7_7, 2_7, 7_7, 4_5, 3_4, 2_7, 4_6, 4_6, 3_1, 4_4, 3_1, 3_0,
					        7_7, 4_8, 3_5, 4_5, 2_7, 3_3, 3_1, 7_7, 3_8, 3_5, 3_1, 4_5,
					        6_4, 7_7, 4_9, 3_4, 4_1, 4_5, 3_1, 7_7, 3_2, 4_4, 4_1, 4_9,
					        4_0, 6_4, 7_9, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 1,
					        4_0, 3_0, 7_7, 4_9, 4_4, 3_5, 4_0, 3_7, 3_8, 3_1, 3_0, 7_7,
					        3_8, 3_5, 4_2, 6_4, 7_7, 2_7, 4_0, 3_0, 7_7, 4_5, 4_0, 3_1,
					        3_1, 4_4, 7_7, 4_1, 3_2, 7_7, 2_9, 4_1, 3_8, 3_0, 7_7, 2_9,
					        4_1, 3_9, 3_9, 2_7, 4_0, 3_0, 6_4, 7_9, 7_7, 7_7, 7_7, 7_7,
					        7_7, 7_7, 7_7, 7_7, 2_0, 3_1, 3_8, 3_8, 7_7, 4_6, 3_4, 2_7,
					        4_6, 7_7, 3_5, 4_6, 4_5, 7_7, 4_5, 2_9, 4_7, 3_8, 4_2, 4_6,
					        4_1, 4_4, 7_7, 4_9, 3_1, 3_8, 3_8, 7_7, 4_6, 3_4, 4_1, 4_5,
					        3_1, 7_7, 4_2, 2_7, 4_5, 4_5, 3_5, 4_1, 4_0, 4_5, 7_7, 4_4,
					        3_1, 2_7, 3_0, 7_9, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7,
					        2_3, 3_4, 3_5, 2_9, 3_4, 7_7, 5_1, 3_1, 4_6, 7_7, 4_5, 4_7,
					        4_4, 4_8, 3_5, 4_8, 3_1, 6_4, 7_7, 4_5, 4_6, 2_7, 3_9, 4_2,
					        3_1, 3_0, 7_7, 4_1, 4_0, 7_7, 4_6, 3_4, 3_1, 4_5, 3_1, 7_7,
					        3_8, 3_5, 3_2, 3_1, 3_8, 3_1, 4_5, 4_5, 7_7, 4_6, 3_4, 3_5,
					        4_0, 3_3, 4_5, 6_4, 7_9, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7,
					        7_7, 2_0, 3_4, 3_1, 7_7, 3_4, 2_7, 4_0, 3_0, 7_7, 4_6, 3_4,
					        2_7, 4_6, 7_7, 3_9, 4_1, 2_9, 3_7, 3_1, 3_0, 7_7, 4_6, 3_4,
					        3_1, 3_9, 6_4, 7_7, 2_7, 4_0, 3_0, 7_7, 4_6, 3_4, 3_1, 7_7,
					        3_4, 3_1, 2_7, 4_4, 4_6, 7_7, 4_6, 3_4, 2_7, 4_6, 7_7, 3_2,
					        3_1, 3_0, 6_6, 7_9, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7,
					        1, 4_0, 3_0, 7_7, 4_1, 4_0, 7_7, 4_6, 3_4, 3_1, 7_7, 4_2,
					        3_1, 3_0, 3_1, 4_5, 4_6, 2_7, 3_8, 6_4, 7_7, 4_6, 3_4, 3_1,
					        4_5, 3_1, 7_7, 4_9, 4_1, 4_4, 3_0, 4_5, 7_7, 2_7, 4_2, 4_2,
					        3_1, 2_7, 4_4, 6_5, 7_9, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7,
					        7_7, 1_3, 5_1, 7_7, 4_0, 2_7, 3_9, 3_1, 7_7, 3_5, 4_5, 7_7,
					        1_5, 5_2, 5_1, 3_9, 2_7, 4_0, 3_0, 3_5, 2_7, 4_5, 6_4, 7_7,
					        1_1, 3_5, 4_0, 3_3, 7_7, 4_1, 3_2, 7_7, 1_1, 3_5, 4_0, 3_3,
					        4_5, 6_6, 7_9, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 1_2,
					        4_1, 4_1, 3_7, 7_7, 4_1, 4_0, 7_7, 3_9, 5_1, 7_7, 2_3, 4_1,
					        4_4, 3_7, 4_5, 6_4, 7_7, 5_1, 3_1, 7_7, 1_3, 3_5, 3_3, 3_4,
					        4_6, 5_1, 6_4, 7_7, 2_7, 4_0, 3_0, 7_7, 3_0, 3_1, 4_5, 4_2,
					        2_7, 3_5, 4_4, 6_7, 7_9, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7,
					        7_7, 1_4, 4_1, 4_6, 3_4, 3_5, 4_0, 3_3, 7_7, 2_8, 3_1, 4_5,
					        3_5, 3_0, 3_1, 7_7, 4_4, 3_1, 3_9, 2_7, 3_5, 4_0, 4_5, 6_3,
					        7_7, 1_8, 4_1, 4_7, 4_0, 3_0, 7_7, 4_6, 3_4, 3_1, 7_7, 3_0,
					        3_1, 2_9, 2_7, 5_1, 7_9, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7, 7_7,
					        7_7, 1_5, 3_2, 7_7, 4_6, 3_4, 2_7, 4_6, 7_7, 2_9, 4_1, 3_8,
					        4_1, 4_5, 4_5, 2_7, 3_8, 7_7, 2_3, 4_4, 3_1, 2_9, 3_7, 6_4,
					        7_7, 2_8, 4_1, 4_7, 4_0, 3_0, 3_8, 3_1, 4_5, 4_5, 7_7, 2_7,
					        4_0, 3_0, 7_7, 2_8, 2_7, 4_4, 3_1, 7_9, 7_7, 7_7, 7_7, 7_7,
					        7_7, 7_7, 7_7, 7_7, 2_0, 3_4, 3_1, 7_7, 3_8, 4_1, 4_0, 3_1,
					        7_7, 2_7, 4_0, 3_0, 7_7, 3_8, 3_1, 4_8, 3_1, 3_8, 7_7, 4_5,
					        2_7, 4_0, 3_0, 4_5, 7_7, 4_5, 4_6, 4_4, 3_1, 4_6, 2_9, 3_4,
					        7_7, 3_2, 2_7, 4_4, 7_7, 2_7, 4_9, 2_7, 5_1, 7_9, 7_7, 7_7,
					        7_7, 7_7, 7_7, 7_7, 7_7, 7_7]]			),
					    torch.tensor([[0, 0, 0, 1_0_6_9, 1_1, -1, -1, -1, -1]]			),
					    torch.tensor([[0, 0, 0, 1_0_6_9, 1_1, -1, -1, -1, -1]]			),
					]
					# fmt: on
					self.assertTrue(torch.allclose(tokens[0]			,				EXPECTED_OUTPUT[0]			)			)
					self.assertTrue(torch.allclose(tokens[1]			,				EXPECTED_OUTPUT[1]			)			)
					self.assertTrue(torch.allclose(tokens[2]			,				EXPECTED_OUTPUT[2]			)			)






import unittest

from transformers import (
    MODEL_FOR_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
    TextGenerationPipeline,
    logging,
    pipeline,
)
from transformers.testing_utils import (
    CaptureLogger,
    is_pipeline_test,
    require_accelerate,
    require_tf,
    require_torch,
    require_torch_gpu,
    require_torch_or_tf,
)

from .test_pipelines_common import ANY
@is_pipeline_test
@require_torch_or_tf
class 					lowercase__(							unittest.TestCase				):



	"""simple docstring"""




	a     :List[Any]       	=      MODEL_FOR_CAUSAL_LM_MAPPING
	a     :Tuple       	=      TF_MODEL_FOR_CAUSAL_LM_MAPPING
	@require_torch
	def 		_lowercase    (			self    :     Tuple			)			->	Dict:
					lowercase_	    =   pipeline(task='''text-generation'''			,				model='''sshleifer/tiny-ctrl'''			,				framework='''pt'''			)
					# Using `do_sample=False` to force deterministic output
					lowercase_	    =   text_generator('''This is a test'''			,				do_sample=SCREAMING_SNAKE_CASE_			)
					self.assertEqual(
					    SCREAMING_SNAKE_CASE_			,				[
					        {
					            '''generated_text''': (
					                '''This is a test ☃ ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy oscope.'''
					                ''' oscope. FiliFili@@'''
					            )
					        }
					    ]			,				)

					lowercase_	    =   text_generator(['''This is a test''', '''This is a second test''']			)
					self.assertEqual(
					    SCREAMING_SNAKE_CASE_			,				[
					        [
					            {
					                '''generated_text''': (
					                    '''This is a test ☃ ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy oscope.'''
					                    ''' oscope. FiliFili@@'''
					                )
					            }
					        ],
					        [
					            {
					                '''generated_text''': (
					                    '''This is a second test ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy'''
					                    ''' oscope. oscope. FiliFili@@'''
					                )
					            }
					        ],
					    ]			,				)

					lowercase_	    =   text_generator('''This is a test'''			,				do_sample=SCREAMING_SNAKE_CASE_			,				num_return_sequences=2			,				return_tensors=SCREAMING_SNAKE_CASE_			)
					self.assertEqual(
					    SCREAMING_SNAKE_CASE_			,				[
					        {'''generated_token_ids''': ANY(SCREAMING_SNAKE_CASE_			)},
					        {'''generated_token_ids''': ANY(SCREAMING_SNAKE_CASE_			)},
					    ]			,				)
					lowercase_	    =   text_generator.model.config.eos_token_id
					lowercase_	    =   '''<pad>'''
					lowercase_	    =   text_generator(
					    ['''This is a test''', '''This is a second test''']			,				do_sample=SCREAMING_SNAKE_CASE_			,				num_return_sequences=2			,				batch_size=2			,				return_tensors=SCREAMING_SNAKE_CASE_			,				)
					self.assertEqual(
					    SCREAMING_SNAKE_CASE_			,				[
					        [
					            {'''generated_token_ids''': ANY(SCREAMING_SNAKE_CASE_			)},
					            {'''generated_token_ids''': ANY(SCREAMING_SNAKE_CASE_			)},
					        ],
					        [
					            {'''generated_token_ids''': ANY(SCREAMING_SNAKE_CASE_			)},
					            {'''generated_token_ids''': ANY(SCREAMING_SNAKE_CASE_			)},
					        ],
					    ]			,				)
	@require_tf
	def 		_lowercase    (			self    :     str			)			->	Optional[int]:
					lowercase_	    =   pipeline(task='''text-generation'''			,				model='''sshleifer/tiny-ctrl'''			,				framework='''tf'''			)

					# Using `do_sample=False` to force deterministic output
					lowercase_	    =   text_generator('''This is a test'''			,				do_sample=SCREAMING_SNAKE_CASE_			)
					self.assertEqual(
					    SCREAMING_SNAKE_CASE_			,				[
					        {
					            '''generated_text''': (
					                '''This is a test FeyFeyFey(Croatis.), s.), Cannes Cannes Cannes 閲閲Cannes Cannes Cannes 攵'''
					                ''' please,'''
					            )
					        }
					    ]			,				)

					lowercase_	    =   text_generator(['''This is a test''', '''This is a second test''']			,				do_sample=SCREAMING_SNAKE_CASE_			)
					self.assertEqual(
					    SCREAMING_SNAKE_CASE_			,				[
					        [
					            {
					                '''generated_text''': (
					                    '''This is a test FeyFeyFey(Croatis.), s.), Cannes Cannes Cannes 閲閲Cannes Cannes Cannes 攵'''
					                    ''' please,'''
					                )
					            }
					        ],
					        [
					            {
					                '''generated_text''': (
					                    '''This is a second test Chieftain Chieftain prefecture prefecture prefecture Cannes Cannes'''
					                    ''' Cannes 閲閲Cannes Cannes Cannes 攵 please,'''
					                )
					            }
					        ],
					    ]			,				)
	def 		_lowercase    (			self    :     Optional[Any]			,				SCREAMING_SNAKE_CASE_    :     int			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]			,				SCREAMING_SNAKE_CASE_    :     List[str]			)			->	Union[str, Any]:
					lowercase_	    =   TextGenerationPipeline(model=SCREAMING_SNAKE_CASE_			,				tokenizer=SCREAMING_SNAKE_CASE_			)
					return text_generator, ["This is a test", "Another test"]
	def 		_lowercase    (			self    :     List[Any]			)			->	Optional[int]:
					lowercase_	    =   '''Hello I believe in'''
					lowercase_	    =   pipeline('''text-generation'''			,				model='''hf-internal-testing/tiny-random-gpt2'''			)
					lowercase_	    =   text_generator(SCREAMING_SNAKE_CASE_			)
					self.assertEqual(
					    SCREAMING_SNAKE_CASE_			,				[{'''generated_text''': '''Hello I believe in fe fe fe fe fe fe fe fe fe fe fe fe'''}]			,				)

					lowercase_	    =   text_generator(SCREAMING_SNAKE_CASE_			,				stop_sequence=''' fe'''			)
					self.assertEqual(SCREAMING_SNAKE_CASE_			,				[{'''generated_text''': '''Hello I believe in fe'''}]			)
	def 		_lowercase    (			self    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     Tuple			,				SCREAMING_SNAKE_CASE_    :     List[str]			)			->	str:
					lowercase_	    =   text_generator.model
					lowercase_	    =   text_generator.tokenizer

					lowercase_	    =   text_generator('''This is a test'''			)
					self.assertEqual(SCREAMING_SNAKE_CASE_			,				[{'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}]			)
					self.assertTrue(outputs[0]['''generated_text'''].startswith('''This is a test'''			)			)

					lowercase_	    =   text_generator('''This is a test'''			,				return_full_text=SCREAMING_SNAKE_CASE_			)
					self.assertEqual(SCREAMING_SNAKE_CASE_			,				[{'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}]			)
					self.assertNotIn('''This is a test'''			,				outputs[0]['''generated_text''']			)

					lowercase_	    =   pipeline(task='''text-generation'''			,				model=SCREAMING_SNAKE_CASE_			,				tokenizer=SCREAMING_SNAKE_CASE_			,				return_full_text=SCREAMING_SNAKE_CASE_			)
					lowercase_	    =   text_generator('''This is a test'''			)
					self.assertEqual(SCREAMING_SNAKE_CASE_			,				[{'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}]			)
					self.assertNotIn('''This is a test'''			,				outputs[0]['''generated_text''']			)

					lowercase_	    =   text_generator('''This is a test'''			,				return_full_text=SCREAMING_SNAKE_CASE_			)
					self.assertEqual(SCREAMING_SNAKE_CASE_			,				[{'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}]			)
					self.assertTrue(outputs[0]['''generated_text'''].startswith('''This is a test'''			)			)

					lowercase_	    =   text_generator(['''This is great !''', '''Something else''']			,				num_return_sequences=2			,				do_sample=SCREAMING_SNAKE_CASE_			)
					self.assertEqual(
					    SCREAMING_SNAKE_CASE_			,				[
					        [{'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}, {'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}],
					        [{'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}, {'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}],
					    ]			,				)

					if text_generator.tokenizer.pad_token is not None:
									lowercase_	    =   text_generator(
									    ['''This is great !''', '''Something else''']			,				num_return_sequences=2			,				batch_size=2			,				do_sample=SCREAMING_SNAKE_CASE_			)
									self.assertEqual(
									    SCREAMING_SNAKE_CASE_			,				[
									        [{'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}, {'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}],
									        [{'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}, {'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}],
									    ]			,				)

					with self.assertRaises(SCREAMING_SNAKE_CASE_			):
									lowercase_	    =   text_generator('''test'''			,				return_full_text=SCREAMING_SNAKE_CASE_			,				return_text=SCREAMING_SNAKE_CASE_			)
					with self.assertRaises(SCREAMING_SNAKE_CASE_			):
									lowercase_	    =   text_generator('''test'''			,				return_full_text=SCREAMING_SNAKE_CASE_			,				return_tensors=SCREAMING_SNAKE_CASE_			)
					with self.assertRaises(SCREAMING_SNAKE_CASE_			):
									lowercase_	    =   text_generator('''test'''			,				return_text=SCREAMING_SNAKE_CASE_			,				return_tensors=SCREAMING_SNAKE_CASE_			)

					# Empty prompt is slighly special
					# it requires BOS token to exist.
					# Special case for Pegasus which will always append EOS so will
					# work even without BOS.
					if (
					    text_generator.tokenizer.bos_token_id is not None
					    or "Pegasus" in tokenizer.__class__.__name__
					    or "Git" in model.__class__.__name__
					):
									lowercase_	    =   text_generator(''''''			)
									self.assertEqual(SCREAMING_SNAKE_CASE_			,				[{'''generated_text''': ANY(SCREAMING_SNAKE_CASE_			)}]			)
					else:
									with self.assertRaises((ValueError, AssertionError)			):
													lowercase_	    =   text_generator(''''''			)

					if text_generator.framework == "tf":
									# TF generation does not support max_new_tokens, and it's impossible
									# to control long generation with only max_length without
									# fancy calculation, dismissing tests for now.
									return
					# We don't care about infinite range models.
					# They already work.
					# Skip this test for XGLM, since it uses sinusoidal positional embeddings which are resized on-the-fly.
					lowercase_	    =   ['''RwkvForCausalLM''', '''XGLMForCausalLM''', '''GPTNeoXForCausalLM''']
					if (
					    tokenizer.model_max_length < 1_0_0_0_0
					    and text_generator.model.__class__.__name__ not in EXTRA_MODELS_CAN_HANDLE_LONG_INPUTS
					):
									# Handling of large generations
									with self.assertRaises((RuntimeError, IndexError, ValueError, AssertionError)			):
													text_generator('''This is a test''' * 5_0_0			,				max_new_tokens=2_0			)

									lowercase_	    =   text_generator('''This is a test''' * 5_0_0			,				handle_long_generation='''hole'''			,				max_new_tokens=2_0			)
									# Hole strategy cannot work
									with self.assertRaises(SCREAMING_SNAKE_CASE_			):
													text_generator(
													    '''This is a test''' * 5_0_0			,				handle_long_generation='''hole'''			,				max_new_tokens=tokenizer.model_max_length + 1_0			,				)
	@require_torch
	@require_accelerate
	@require_torch_gpu
	def 		_lowercase    (			self    :     Union[str, Any]			)			->	Tuple:
					import torch

					# Classic `model_kwargs`
					lowercase_	    =   pipeline(
					    model='''hf-internal-testing/tiny-random-bloom'''			,				model_kwargs={'''device_map''': '''auto''', '''torch_dtype''': torch.bfloataa}			,				)
					self.assertEqual(pipe.model.device			,				torch.device(0			)			)
					self.assertEqual(pipe.model.lm_head.weight.dtype			,				torch.bfloataa			)
					lowercase_	    =   pipe('''This is a test'''			)
					self.assertEqual(
					    SCREAMING_SNAKE_CASE_			,				[
					        {
					            '''generated_text''': (
					                '''This is a test test test test test test test test test test test test test test test test'''
					                ''' test'''
					            )
					        }
					    ]			,				)

					# Upgraded those two to real pipeline arguments (they just get sent for the model as they're unlikely to mean anything else.)
					lowercase_	    =   pipeline(model='''hf-internal-testing/tiny-random-bloom'''			,				device_map='''auto'''			,				torch_dtype=torch.bfloataa			)
					self.assertEqual(pipe.model.device			,				torch.device(0			)			)
					self.assertEqual(pipe.model.lm_head.weight.dtype			,				torch.bfloataa			)
					lowercase_	    =   pipe('''This is a test'''			)
					self.assertEqual(
					    SCREAMING_SNAKE_CASE_			,				[
					        {
					            '''generated_text''': (
					                '''This is a test test test test test test test test test test test test test test test test'''
					                ''' test'''
					            )
					        }
					    ]			,				)

					# torch_dtype will be automatically set to float32 if not provided - check: https://github.com/huggingface/transformers/pull/20602
					lowercase_	    =   pipeline(model='''hf-internal-testing/tiny-random-bloom'''			,				device_map='''auto'''			)
					self.assertEqual(pipe.model.device			,				torch.device(0			)			)
					self.assertEqual(pipe.model.lm_head.weight.dtype			,				torch.floataa			)
					lowercase_	    =   pipe('''This is a test'''			)
					self.assertEqual(
					    SCREAMING_SNAKE_CASE_			,				[
					        {
					            '''generated_text''': (
					                '''This is a test test test test test test test test test test test test test test test test'''
					                ''' test'''
					            )
					        }
					    ]			,				)
	@require_torch
	@require_torch_gpu
	def 		_lowercase    (			self    :     Optional[int]			)			->	List[Any]:
					import torch

					lowercase_	    =   pipeline(model='''hf-internal-testing/tiny-random-bloom'''			,				device=0			,				torch_dtype=torch.floataa			)
					pipe('''This is a test'''			)
	@require_torch
	@require_accelerate
	@require_torch_gpu
	def 		_lowercase    (			self    :     int			)			->	Dict:
					import torch

					lowercase_	    =   pipeline(model='''hf-internal-testing/tiny-random-bloom'''			,				device_map='''auto'''			,				torch_dtype=torch.floataa			)
					pipe('''This is a test'''			,				do_sample=SCREAMING_SNAKE_CASE_			,				top_p=0.5			)




	def 		_lowercase    (			self    :     List[Any]			)			->	int:
					lowercase_	    =   '''Hello world'''
					lowercase_	    =   pipeline('''text-generation'''			,				model='''hf-internal-testing/tiny-random-gpt2'''			)
					if text_generator.model.framework == "tf":
									lowercase_	    =   logging.get_logger('''transformers.generation.tf_utils'''			)
					else:
									lowercase_	    =   logging.get_logger('''transformers.generation.utils'''			)
					lowercase_	    =   '''Both `max_new_tokens`'''  # The beggining of the message to be checked in this test

					# Both are set by the user -> log warning
					with CaptureLogger(SCREAMING_SNAKE_CASE_			) as cl:
									lowercase_	    =   text_generator(SCREAMING_SNAKE_CASE_			,				max_length=1_0			,				max_new_tokens=1			)
					self.assertIn(SCREAMING_SNAKE_CASE_			,				cl.out			)

					# The user only sets one -> no warning
					with CaptureLogger(SCREAMING_SNAKE_CASE_			) as cl:
									lowercase_	    =   text_generator(SCREAMING_SNAKE_CASE_			,				max_new_tokens=1			)
					self.assertNotIn(SCREAMING_SNAKE_CASE_			,				cl.out			)

					with CaptureLogger(SCREAMING_SNAKE_CASE_			) as cl:
									lowercase_	    =   text_generator(SCREAMING_SNAKE_CASE_			,				max_length=1_0			)
					self.assertNotIn(SCREAMING_SNAKE_CASE_			,				cl.out			)




