diff --git a/xmanager/cloud/vertex.py b/xmanager/cloud/vertex.py index 81499ff..d410e9a 100644 --- a/xmanager/cloud/vertex.py +++ b/xmanager/cloud/vertex.py @@ -341,7 +341,9 @@ def launch(experiment_title: str, work_unit_name: str, def cpu_ram_to_machine_type(cpu: Optional[int], ram: Optional[int]) -> str: """Convert a cpu and memory spec into a machine type.""" - if cpu is None or ram is None: + cpu = cpu or 0 + ram = ram or 0 + if cpu + ram == 0: return 'n1-standard-4' optimal_machine_type = '' diff --git a/xmanager/cloud/vertex_test.py b/xmanager/cloud/vertex_test.py index 556470e..be2d277 100644 --- a/xmanager/cloud/vertex_test.py +++ b/xmanager/cloud/vertex_test.py @@ -170,10 +170,17 @@ def test_cpu_ram_to_machine_type_highmem(self): self.assertEqual('n1-highmem-64', vertex.cpu_ram_to_machine_type(1, 415 * xm.GiB)) + def test_cpu_ram_to_machine_type_mem_only(self): + self.assertEqual('n1-highmem-64', + vertex.cpu_ram_to_machine_type(None, 415 * xm.GiB)) + def test_cpu_ram_to_machine_type_highcpu(self): self.assertEqual('n1-highcpu-64', vertex.cpu_ram_to_machine_type(63, 1 * xm.GiB)) + def test_cpu_ram_to_machine_type_cpu_only(self): + self.assertEqual('n1-highcpu-64', vertex.cpu_ram_to_machine_type(63, None)) + def test_cpu_ram_to_machine_type_too_high(self): with self.assertRaises(ValueError): vertex.cpu_ram_to_machine_type(1000, 1000)