1
0
Fork 0

fix(api): default to first available device when there are no other jobs

This commit is contained in:
Sean Sube 2023-02-04 16:37:36 -06:00
parent efee374c16
commit bf3f227d66
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
2 changed files with 22 additions and 1 deletions

View File

@ -135,8 +135,15 @@ class DevicePoolExecutor:
return (None, 0)
def get_next_device(self):
# use the first/default device if there are no jobs
if len(self.jobs) == 0:
return 0
job_devices = [job.context.device_index.value for job in self.jobs]
queued = Counter(job_devices).most_common()
job_counts = Counter(range(len(self.devices)))
job_counts.update(job_devices)
queued = job_counts.most_common()
logger.debug('jobs queued by device: %s', queued)
return queued[-1]

View File

@ -15,6 +15,7 @@ from diffusers import (
)
from flask import Flask, jsonify, make_response, request, send_from_directory, url_for
from flask_cors import CORS
from functools import cmp_to_key
from glob import glob
from io import BytesIO
from jsonschema import validate
@ -333,6 +334,19 @@ def load_platforms():
available_platforms.append(DeviceParams(
potential, platform_providers[potential]))
# make sure CPU is last on the list
def cpu_last(a: DeviceParams, b: DeviceParams):
if a.device == 'cpu' and b.device == 'cpu':
return 0
if a.device == 'cpu':
return 1
return -1
available_platforms = sorted(available_platforms, key=cmp_to_key(cpu_last))
logger.info('available acceleration platforms: %s',
', '.join([str(p) for p in available_platforms]))