Beispiel #1
0
 def _read_defaults_helper():
     from openpaisdk import LayeredSettings
     from openpaisdk.job import JobResource
     # add default settings
     image_list = LayeredSettings.get('image-list')
     if image_list is None or len(image_list) == 0:
         # add default images here
         default_images = [
             'openpai/pytorch-py36-cu90',
             'openpai/pytorch-py36-cpu',
             'openpai/tensorflow-py36-cu90',
             'openpai/tensorflow-py36-cpu',
         ]
         for image in default_images:
             LayeredSettings.update('global_default', 'image-list',
                                    image)
         image_list = LayeredSettings.get('image-list')
     resource_list = JobResource.parse_list(
         LayeredSettings.get('resource-list'))
     if resource_list is None or len(resource_list) == 0:
         # add default resource here
         default_resources = [
             '1,4,8g',
             '1,8,16g',
             '0,4,8g',
             '2,8,16g',
             '4,16,32g',
         ]
         for resource in default_resources:
             LayeredSettings.update('global_default', 'resource-list',
                                    resource)
         resource_list = JobResource.parse_list(
             LayeredSettings.get('resource-list'))
     return {
         'image-list':
         image_list,
         'resource-list':
         resource_list,
         'web-default-form':
         LayeredSettings.get('web-default-form'),
         'web-default-image':
         LayeredSettings.get('web-default-image'),
         'web-default-resource':
         LayeredSettings.get('web-default-resource'),
     }
Beispiel #2
0
 def test_job_resource_list(self):
     from openpaisdk.job import JobResource
     samples = {
         "3,3,3g": dict(gpu=3, cpu=3, memoryMB=3072, ports={}),
         "3,1, 2g": dict(gpu=3, cpu=1, memoryMB=2048, ports={}),
     }
     keys = list(samples.keys())
     rets = JobResource.parse_list(keys)
     for k, r in zip(keys, rets):
         self.assertDictEqual(r, samples[k])
Beispiel #3
0
 def test_job_resource_parser(self):
     from openpaisdk.job import JobResource
     from openpaisdk import __flags__
     self.assertDictEqual(__flags__.resources_requirements, JobResource(None).as_dict)
     self.assertDictEqual(__flags__.resources_requirements, JobResource().as_dict)
     self.assertDictEqual(__flags__.resources_requirements, JobResource({}).as_dict)
     dic = dict(cpu=-1, gpu=-2, memoryMB=-1024)
     for key, value in dic.items():
         self.assertEqual(value, JobResource(dic).as_dict[key])
     dic['mem'] = '-2gb'
     self.assertEqual(-2048, JobResource(dic).as_dict["memoryMB"])
     dic['mem'] = '-3g'
     self.assertEqual(-3072, JobResource(dic).as_dict["memoryMB"])
     dic['mem'] = 10240
     self.assertEqual(10240, JobResource(dic).as_dict["memoryMB"])
     self.assertEqual({"a": 1}, JobResource(dic).add_port("a").as_dict["ports"])