def create_job(job_uuid, experiment, role=None, k8s_replica=None, sequence=None, resources=None, node_selector=None, affinity=None, tolerations=None): job = ExperimentJob(uuid=uuid.UUID(job_uuid), experiment=experiment, definition={}) k8s_replica = k8s_replica or role if role: job.role = role if k8s_replica: job.k8s_replica = k8s_replica if sequence: job.sequence = sequence if node_selector: job.node_selector = node_selector if affinity: job.affinity = affinity if tolerations: job.tolerations = tolerations def set_resources(): job_resources = {} if resources.memory: _resources = resources.memory.to_dict() if any(_resources.values()): job_resources['memory'] = _resources if resources.cpu: _resources = resources.cpu.to_dict() if any(_resources.values()): job_resources['cpu'] = _resources if resources.gpu: _resources = resources.gpu.to_dict() if any(_resources.values()): job_resources['gpu'] = _resources if resources.tpu: _resources = resources.tpu.to_dict() if any(_resources.values()): job_resources['tpu'] = _resources if job_resources: job.resources = JobResources.objects.create(**job_resources) if resources: set_resources() job.save()
def create_job(job_uuid, experiment, definition, role=None, resources=None, node_selector=None, affinity=None, tolerations=None): job = ExperimentJob(uuid=job_uuid, experiment=experiment, definition=definition) if role: job.role = role if node_selector: job.node_selector = node_selector if affinity: job.affinity = affinity if tolerations: job.tolerations = tolerations def set_resources(): job_resources = {} if resources.memory: _resources = resources.memory.to_dict() if any(_resources.values()): job_resources['memory'] = _resources if resources.cpu: _resources = resources.cpu.to_dict() if any(_resources.values()): job_resources['cpu'] = _resources if resources.gpu: _resources = resources.gpu.to_dict() if any(_resources.values()): job_resources['gpu'] = _resources if job_resources: job.resources = JobResources.objects.create(**job_resources) if resources: set_resources() job.save()