def setUpModule(): # Parse flags (for `pytest`). if not FLAGS.is_parsed(): FLAGS(sys.argv, known_only=True) fake.set_n_cpu_devices(FLAGS.chex_n_cpu_devices) asserts.assert_devices_available(FLAGS.chex_n_cpu_devices, 'cpu', backend='cpu')
def test_set_n_cpu_devices(self): # Should not initialize backends. fake.set_n_cpu_devices(4) # Hence, this one does not fail. fake.set_n_cpu_devices(6) # This assert initializes backends. asserts.assert_devices_available(6, 'cpu', backend='cpu') # Which means that next call must fail. with self.assertRaisesRegex( RuntimeError, 'Attempted to set 8 devices, but 6 CPUs.+'): fake.set_n_cpu_devices(8)
def test_set_n_cpu_devices(self): try: # Should not initialize backends. fake.set_n_cpu_devices(4) except RuntimeError as set_cpu_exception: raise unittest.SkipTest( "set_n_cpu_devices: backend's already been initialized. " 'Run this test in isolation from others.') from set_cpu_exception # Hence, this one does not fail. fake.set_n_cpu_devices(6) # This assert initializes backends. asserts.assert_devices_available(6, 'cpu', backend='cpu') # Which means that next call must fail. with self.assertRaisesRegex(RuntimeError, 'Attempted to set 8 devices, but 6 CPUs.+'): fake.set_n_cpu_devices(8)
def setUpModule(): fake.set_n_cpu_devices() asserts.assert_devices_available(FLAGS['chex_n_cpu_devices'].value, 'cpu', backend='cpu')
def setUpModule(): fake.set_n_cpu_devices()
def setUpModule(): # Has the same effect as `fake.set_n_cpu_devices(FLAGS.chex_n_cpu_devices)`. fake.set_n_cpu_devices() asserts.assert_devices_available(FLAGS.chex_n_cpu_devices, 'cpu', backend='cpu')