Fix the broken 'time remaining' counter

This commit is contained in:
cmdr2 2022-10-18 16:12:17 +05:30
parent b23bc4a5b6
commit 83d6c3ba88
2 changed files with 8 additions and 6 deletions

View File

@ -609,7 +609,6 @@ async function doMakeImage(task) {
let reader = res.body.getReader() let reader = res.body.getReader()
let textDecoder = new TextDecoder() let textDecoder = new TextDecoder()
let finalJSON = '' let finalJSON = ''
let prevTime = -1
let readComplete = false let readComplete = false
while (!readComplete || finalJSON.length > 0) { while (!readComplete || finalJSON.length > 0) {
let t = Date.now() let t = Date.now()
@ -664,11 +663,11 @@ async function doMakeImage(task) {
let percent = 100 * (overallStepCount / totalSteps) let percent = 100 * (overallStepCount / totalSteps)
percent = (percent > 100 ? 100 : percent) percent = (percent > 100 ? 100 : percent)
percent = percent.toFixed(0) percent = percent.toFixed(0)
let timeTaken = (prevTime === -1 ? -1 : t - prevTime) let timeTaken = stepUpdate.step_time // sec
let stepsRemaining = totalSteps - overallStepCount let stepsRemaining = totalSteps - overallStepCount
stepsRemaining = (stepsRemaining < 0 ? 0 : stepsRemaining) stepsRemaining = (stepsRemaining < 0 ? 0 : stepsRemaining)
let timeRemaining = (timeTaken === -1 ? '' : stepsRemaining * timeTaken) // ms let timeRemaining = (timeTaken === -1 ? '' : stepsRemaining * timeTaken * 1000) // ms
outputMsg.innerHTML = `Batch ${task.batchesDone+1} of ${batchCount}` outputMsg.innerHTML = `Batch ${task.batchesDone+1} of ${batchCount}`
outputMsg.innerHTML += `. Generating image(s): ${percent}%` outputMsg.innerHTML += `. Generating image(s): ${percent}%`
@ -698,7 +697,6 @@ async function doMakeImage(task) {
console.log('Stream stopped: ', res) console.log('Stream stopped: ', res)
} }
} }
prevTime = t
} }
if (typeof stepUpdate === 'object' && stepUpdate.status !== 'succeeded') { if (typeof stepUpdate === 'object' && stepUpdate.status !== 'succeeded') {

View File

@ -405,14 +405,18 @@ def do_mk_img(req: Request):
modelFS.to(device) modelFS.to(device)
partial_x_samples = None partial_x_samples = None
last_callback_time = -1
def img_callback(x_samples, i): def img_callback(x_samples, i):
nonlocal partial_x_samples nonlocal partial_x_samples, last_callback_time
partial_x_samples = x_samples partial_x_samples = x_samples
if req.stream_progress_updates: if req.stream_progress_updates:
n_steps = req.num_inference_steps if req.init_image is None else t_enc n_steps = req.num_inference_steps if req.init_image is None else t_enc
progress = {"step": i, "total_steps": n_steps} step_time = time.time() - last_callback_time if last_callback_time != -1 else -1
last_callback_time = time.time()
progress = {"step": i, "total_steps": n_steps, "step_time": step_time}
if req.stream_image_progress and i % 5 == 0: if req.stream_image_progress and i % 5 == 0:
partial_images = [] partial_images = []