





def      _lowercase					(						_UpperCAmelCase				)						->  Tuple:
				if not head:
								return True
				# split the list to two parts
				lowerCamelCase	 =head.next, head
				while fast and fast.next:
								lowerCamelCase	 =fast.next.next
								lowerCamelCase	 =slow.next
				lowerCamelCase	 =slow.next
				lowerCamelCase	 =None  # Don't forget here! But forget still works!
				# reverse the second part
				lowerCamelCase	 =None
				while second:
								lowerCamelCase	 =second.next
								lowerCamelCase	 =node
								lowerCamelCase	 =second
								lowerCamelCase	 =nxt
				# compare two parts
				# second part has the same or one less node
				while node:
								if node.val != head.val:
												return False
								lowerCamelCase	 =node.next
								lowerCamelCase	 =head.next
				return True





def      _lowercase					(						_UpperCAmelCase				)						->  str:
				if not head or not head.next:
								return True

				# 1. Get the midpoint (slow)
				lowerCamelCase	 =head
				while fast and fast.next:
								lowerCamelCase	 =fast.next.next, slow.next

				# 2. Push the second half into the stack
				lowerCamelCase	 =[slow.val]
				while slow.next:
								lowerCamelCase	 =slow.next
								stack.append(slow.val				)

				# 3. Comparison
				while stack:
								if stack.pop() != cur.val:
												return False
								lowerCamelCase	 =cur.next

				return True





def      _lowercase					(						_UpperCAmelCase				)						->  Any:
				if not head or not head.next:
								return True
				lowerCamelCase	 ={}
				lowerCamelCase	 =0
				while head:
								if head.val in d:
												d[head.val].append(snake_case_				)
								else:
												lowerCamelCase	 =[pos]
								lowerCamelCase	 =head.next
								pos += 1
				lowerCamelCase	 =pos - 1
				lowerCamelCase	 =0
				for v in d.values():
								if len(snake_case_				) % 2 != 0:
												middle += 1
								else:
												lowerCamelCase	 =0
												for i in range(0			,      len(snake_case_				)				):
																if v[i] + v[len(snake_case_				) - 1 - step] != checksum:
																				return False
																step += 1
								if middle > 1:
												return False
				return True












from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch

@require_torch
@require_tf
class       __A     (						a    ):


				def _snake_case       (		self							):
								lowerCamelCase	 =SMALL_MODEL_IDENTIFIER
								lowerCamelCase	 ="""pt"""
								lowerCamelCase	 ="""tf"""


				def _snake_case       (		self   , UpperCAmelCase_							):
								lowerCamelCase	 =AutoModel.from_pretrained(self.test_model							)
								model_pt.save_pretrained(UpperCAmelCase_							)


				def _snake_case       (		self   , UpperCAmelCase_							):
								lowerCamelCase	 =TFAutoModel.from_pretrained(self.test_model   , from_pt=UpperCAmelCase_							)
								model_tf.save_pretrained(UpperCAmelCase_							)


				def _snake_case       (		self							):
								lowerCamelCase	 ="""mock_framework"""

								# Framework provided - return whatever the user provides
								lowerCamelCase	 =FeaturesManager.determine_framework(self.test_model   , UpperCAmelCase_							)
								self.assertEqual(UpperCAmelCase_   , UpperCAmelCase_							)

								# Local checkpoint and framework provided - return provided framework
								# PyTorch checkpoint
								with TemporaryDirectory() as local_pt_ckpt:
												self._setup_pt_ckpt(UpperCAmelCase_							)
												lowerCamelCase	 =FeaturesManager.determine_framework(UpperCAmelCase_   , UpperCAmelCase_							)
												self.assertEqual(UpperCAmelCase_   , UpperCAmelCase_							)

								# TensorFlow checkpoint
								with TemporaryDirectory() as local_tf_ckpt:
												self._setup_tf_ckpt(UpperCAmelCase_							)
												lowerCamelCase	 =FeaturesManager.determine_framework(UpperCAmelCase_   , UpperCAmelCase_							)
												self.assertEqual(UpperCAmelCase_   , UpperCAmelCase_							)


				def _snake_case       (		self							):
								# PyTorch checkpoint
								with TemporaryDirectory() as local_pt_ckpt:
												self._setup_pt_ckpt(UpperCAmelCase_							)
												lowerCamelCase	 =FeaturesManager.determine_framework(UpperCAmelCase_							)
												self.assertEqual(UpperCAmelCase_   , self.framework_pt							)

								# TensorFlow checkpoint
								with TemporaryDirectory() as local_tf_ckpt:
												self._setup_tf_ckpt(UpperCAmelCase_							)
												lowerCamelCase	 =FeaturesManager.determine_framework(UpperCAmelCase_							)
												self.assertEqual(UpperCAmelCase_   , self.framework_tf							)

								# Invalid local checkpoint
								with TemporaryDirectory() as local_invalid_ckpt:
												with self.assertRaises(UpperCAmelCase_							):
																lowerCamelCase	 =FeaturesManager.determine_framework(UpperCAmelCase_							)


				def _snake_case       (		self							):
								lowerCamelCase	 =MagicMock(return_value=UpperCAmelCase_							)
								with patch("""transformers.onnx.features.is_tf_available"""   , UpperCAmelCase_							):
												lowerCamelCase	 =FeaturesManager.determine_framework(self.test_model							)
												self.assertEqual(UpperCAmelCase_   , self.framework_pt							)

								# PyTorch not in environment -> use TensorFlow
								lowerCamelCase	 =MagicMock(return_value=UpperCAmelCase_							)
								with patch("""transformers.onnx.features.is_torch_available"""   , UpperCAmelCase_							):
												lowerCamelCase	 =FeaturesManager.determine_framework(self.test_model							)
												self.assertEqual(UpperCAmelCase_   , self.framework_tf							)

								# Both in environment -> use PyTorch
								lowerCamelCase	 =MagicMock(return_value=UpperCAmelCase_							)
								lowerCamelCase	 =MagicMock(return_value=UpperCAmelCase_							)
								with patch("""transformers.onnx.features.is_tf_available"""   , UpperCAmelCase_							), patch(
								    """transformers.onnx.features.is_torch_available"""   , UpperCAmelCase_							):
												lowerCamelCase	 =FeaturesManager.determine_framework(self.test_model							)
												self.assertEqual(UpperCAmelCase_   , self.framework_pt							)

								# Both not in environment -> raise error
								lowerCamelCase	 =MagicMock(return_value=UpperCAmelCase_							)
								lowerCamelCase	 =MagicMock(return_value=UpperCAmelCase_							)
								with patch("""transformers.onnx.features.is_tf_available"""   , UpperCAmelCase_							), patch(
								    """transformers.onnx.features.is_torch_available"""   , UpperCAmelCase_							):
												with self.assertRaises(UpperCAmelCase_							):
																lowerCamelCase	 =FeaturesManager.determine_framework(self.test_model							)





