def set_job_resources(num_gpus=0, ram=None): """ Specifies the resources to run a job with. The available amount will greatly depend on what is available on the infrastrcture that the Foundations job orchestrator is setup on. Arguments: num_gpus {int} -- The number of GPUs to run the job with. Set to 0 to run with CPU resources instead. By default uses 1 GPU. ram {number} -- The amount of ram in GB to use while running the job. Must be greater than 0 or None. If None, no limit will be set. Returns: - This function doesn't return a value. Raises: ValueError -- If either the RAM or GPU quantity is an invalid value (ex: less than 0) or not specified. Notes: Setting the resources for a job from a given notebook or driver file will cause any additional jobs (ex: hyperparameter search) deployed from the same file and using the same process to use the same resources, unless specified otherwise. To clear specifying resources and use the default, you can pass in set_job_resources(1, None). Set num_gpus=0 to use CPU instead. """ if ram is not None and ram <= 0: raise ValueError( 'Invalid RAM quantity. Please provide a RAM quantity greater than zero.' ) if not isinstance(num_gpus, int) or num_gpus < 0: raise ValueError( 'Invalid GPU quantity. Please provide a non-negative integer GPU quantity.' ) job_resources = JobResources(num_gpus, ram) current_foundations_job().job_resources = job_resources
def set_up(self): self._job_resources = JobResources(self.num_gpus, self.ram)
def _default_job_resources(self): from foundations_internal.job_resources import JobResources return JobResources(1, None)
def test_set_job_resources_ram_defaults_to_none(self): set_job_resources(num_gpus=self.num_gpus) job_resources = current_foundations_job().job_resources self.assertEqual(JobResources(self.num_gpus, None), job_resources)
def test_ram_set_to_none_is_valid_configuration(self): set_job_resources(self.num_gpus, None) expected_job_resources = JobResources(num_gpus=self.num_gpus, ram=None) job_resources = current_foundations_job().job_resources self.assertEqual(expected_job_resources, job_resources)
def default_job_resources(self): return JobResources(1, None)
def job_resources(self): return JobResources(self.num_gpus, self.ram)
def test_set_job_resources_num_gpus_defaults_to_zero(self): set_job_resources(ram=self.ram) job_resources = current_foundations_job().job_resources self.assertEqual(JobResources(0, self.ram), job_resources)
def test_set_job_resources_sets_job_resources_object(self): job_resources = JobResources(self.num_gpus, self.ram) self._context.set_job_resources(job_resources) self.assertIs(job_resources, self._context.job_resources())
def test_reset_job_resources_sets_job_resources_back_to_defaults(self): job_resources = JobResources(self.num_gpus, self.ram) self._context.set_job_resources(job_resources) self._context.reset_job_resources() self.assertEqual(JobResources(1, None), self._context.job_resources())