

'''simple docstring'''




import unittest

import torch
from torch import nn

from accelerate.test_utils import require_cuda
from accelerate.utils.memory import find_executable_batch_size, release_memory


def    lowerCamelCase__		(    ):
  raise RuntimeError('CUDA out of memory.'    )



class 							lowercase_						(		nn.Module			):

  '''simple docstring'''





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


    """simple docstring"""
    super().__init__()
    UpperCAmelCase    				=						nn.Linear(3 ,			4  )
    UpperCAmelCase    				=						nn.BatchNormad(4  )
    UpperCAmelCase    				=						nn.Linear(4 ,			5  )





  def     snake_case_      (  self ,			a_  )				->					Dict:


    """simple docstring"""
    return self.lineara(self.batchnorm(self.lineara(a_  )  )  )




class 							lowercase_						(		unittest.TestCase			):

  '''simple docstring'''





  def     snake_case_      (  self  )				->					Dict:


    """simple docstring"""
    UpperCAmelCase    				=						[]

    @find_executable_batch_size(starting_batch_size=1_2_8  )
    def mock_training_loop_function(a_  ):
      nonlocal batch_sizes
      batch_sizes.append(a_  )
      if batch_size != 8:
        raise_fake_out_of_memory()

    mock_training_loop_function()
    self.assertListEqual(a_ ,			[1_2_8, 6_4, 3_2, 1_6, 8]  )
  def     snake_case_      (  self  )				->					int:


    """simple docstring"""
    UpperCAmelCase    				=						[]

    @find_executable_batch_size(starting_batch_size=1_2_8  )
    def mock_training_loop_function(a_ ,			a_  ):
      nonlocal batch_sizes
      batch_sizes.append(a_  )
      if batch_size != 8:
        raise_fake_out_of_memory()
      return batch_size, arga

    UpperCAmelCase				,   UpperCAmelCase    				=						mock_training_loop_function('hello'  )
    self.assertListEqual(a_ ,			[1_2_8, 6_4, 3_2, 1_6, 8]  )
    self.assertListEqual([bs, arga] ,			[8, 'hello']  )
  def     snake_case_      (  self  )				->					Dict:


    """simple docstring"""
    @find_executable_batch_size(starting_batch_size=0  )
    def mock_training_loop_function(a_  ):
      pass

    with self.assertRaises(a_  ) as cm:
      mock_training_loop_function()
      self.assertIn('No executable batch size found, reached zero.' ,			cm.exception.args[0]  )
  def     snake_case_      (  self  )				->					Optional[Any]:


    """simple docstring"""
    @find_executable_batch_size(starting_batch_size=1_6  )
    def mock_training_loop_function(a_  ):
      if batch_size > 0:
        raise_fake_out_of_memory()
      pass

    with self.assertRaises(a_  ) as cm:
      mock_training_loop_function()
      self.assertIn('No executable batch size found, reached zero.' ,			cm.exception.args[0]  )
  def     snake_case_      (  self  )				->					Optional[int]:


    """simple docstring"""
    @find_executable_batch_size(starting_batch_size=1_2_8  )
    def mock_training_loop_function(a_ ,			a_ ,			a_  ):
      if batch_size != 8:
        raise raise_fake_out_of_memory()

    with self.assertRaises(a_  ) as cm:
      mock_training_loop_function(1_2_8 ,			'hello' ,			'world'  )
      self.assertIn('Batch size was passed into `f`' ,			cm.exception.args[0]  )
      self.assertIn('`f(arg1=\'hello\', arg2=\'world\')' ,			cm.exception.args[0]  )
  def     snake_case_      (  self  )				->					Dict:


    """simple docstring"""
    @find_executable_batch_size(starting_batch_size=1_6  )
    def mock_training_loop_function(a_  ):
      raise ValueError('Oops, we had an error!'  )

    with self.assertRaises(a_  ) as cm:
      mock_training_loop_function()
      self.assertIn('Oops, we had an error!' ,			cm.exception.args[0]  )





  @require_cuda
  def     snake_case_      (  self  )				->					Any:


    """simple docstring"""
    UpperCAmelCase    				=						torch.cuda.memory_allocated()
    UpperCAmelCase    				=						ModelForTest()
    model.cuda()
    self.assertGreater(torch.cuda.memory_allocated() ,			a_  )
    UpperCAmelCase    				=						release_memory(a_  )
    self.assertEqual(torch.cuda.memory_allocated() ,			a_  )





'''simple docstring'''




def    lowerCamelCase__		(    SCREAMING_SNAKE_CASE   : int = 1000    ):
  UpperCAmelCase    				=						-1
  UpperCAmelCase    				=						0
  for a in range(1							, n // 3    ):
    # Solving the two equations a**2+b**2=c**2 and a+b+c=N eliminating c
    UpperCAmelCase    				=						(n * n - 2 * a * n) // (2 * n - 2 * a)
    UpperCAmelCase    				=						n - a - b
    if c * c == (a * a + b * b):
      UpperCAmelCase    				=						a * b * c
      if candidate >= product:
        UpperCAmelCase    				=						candidate
  return product


if __name__ == "__main__":
  print(F'''{solution() = }''')


