in cluster-trace-gpu-v2023/pod_csv_to_yaml.py [0:0]
def output_pod(dfp, outfile='pod.yaml', node_select=False):
num_pod = len(dfp)
for index, row in dfp.iterrows():
if 'name' in row:
workload_name = row['name']
elif 'job_id' in row:
workload_name = f"job-{row['job_id']:04}" # float is not allowed
else:
exit("neither name nor job_id in row")
container_requests = {}
if 'cpu_milli' in row:
container_requests['cpu'] = "%dm" % (row['cpu_milli'])
elif 'cpu' in row:
container_requests['cpu'] = "%dm" % (row['cpu'] * MILLI)
elif 'num_cpu' in row:
container_requests['num_cpu'] = "%dm" % (row['num_cpu'] * MILLI)
else:
exit("neither cpu_milli nor cpu in row")
if 'memory_mib' in row:
container_requests['memory'] = "%dMi" % row['memory_mib']
container_limits = container_requests.copy()
host_node_ip = row['ip'] if node_select else ""
annotations = {}
if int(row['num_gpu']) != 0:
if node_select:
annotations[DeviceIndex] = row['gpu_index'] if type(row['gpu_index']) == str else ""
if 'gpu_milli' not in row:
annotations[ResourceName] = 1000
else:
annotations[ResourceName] = "%d" % (int(row['gpu_milli'])) if 0 < row['gpu_milli'] <= 1000 else "1000" if row['gpu_milli'] > 1000 else "0"
annotations[CountName] = "%d" % (int(row['num_gpu']))
if 'gpu_spec' in row:
gpu_req_val = [x for x in row['gpu_spec'].split('|') if len(x) > 0]
gpu_req_out = "|".join(x for x in gpu_req_val)
if len(gpu_req_out) > 0:
annotations[ModelName] = gpu_req_out
# annotations[CreationTime] = "%s" % row[DATA_CREATION_TIME] if DATA_CREATION_TIME in row else None
# annotations[DeletionTime] = "%s" % row[DATA_DELETION_TIME] if DATA_DELETION_TIME in row else None
pod_yaml = generate_pod_yaml(workload_name=workload_name, container_requests=container_requests,
container_limits=container_limits, node_selector_node_ip=host_node_ip,
annotations=annotations)
if index == 0:
with open(outfile, 'w') as file:
yaml.dump(pod_yaml, file)
else:
with open(outfile, 'a') as file:
file.writelines(['\n---\n\n'])
yaml.dump(pod_yaml, file)