From b99d9db8f9653bfd8a3d695c67519e0ef1d1c55e Mon Sep 17 00:00:00 2001 From: JeLuF Date: Sun, 5 Feb 2023 17:09:56 +0100 Subject: [PATCH] Create exactly 'total' images even if 'in parallel' is no factor of 'total' --- ui/media/js/main.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ui/media/js/main.js b/ui/media/js/main.js index d83a8c9d..c6660a57 100644 --- a/ui/media/js/main.js +++ b/ui/media/js/main.js @@ -702,12 +702,18 @@ async function onTaskStart(task) { if (task.batchCount > 1) { // Each output render batch needs it's own task reqBody instance to avoid altering the other runs after they are completed. newTaskReqBody = Object.assign({}, task.reqBody) + if (task.batchesDone == task.batchCount-1) { + // Last batch of the task + // If the number of parallel jobs is no factor of the total number of images, the last batch must create less than "parallel jobs count" images + // E.g. with numOutputsTotal = 6 and num_outputs = 5, the last batch shall only generate 1 image. + newTaskReqBody.num_outputs = task.numOutputsTotal - task.reqBody.num_outputs * (task.batchCount-1) + } } const startSeed = task.seed || newTaskReqBody.seed const genSeeds = Boolean(typeof newTaskReqBody.seed !== 'number' || (newTaskReqBody.seed === task.seed && task.numOutputsTotal > 1)) if (genSeeds) { - newTaskReqBody.seed = parseInt(startSeed) + (task.batchesDone * newTaskReqBody.num_outputs) + newTaskReqBody.seed = parseInt(startSeed) + (task.batchesDone * task.reqBody.num_outputs) } // Update the seed *before* starting the processing so it's retained if user stops the task