Skip to content

Commit

Permalink
perf: generate even faster with one step prediction (#1)
Browse files Browse the repository at this point in the history
* perf: generate even faster with one step prediction

* upscale up to 8x
  • Loading branch information
isidentical authored Feb 22, 2024
1 parent e99137d commit c333129
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const INPUT_DEFAULTS = {
image_size: "square_hd",
sync_mode: true,
num_images: 1,
num_inference_steps: "2",
num_inference_steps: "1",
};

export default function Lightning() {
Expand All @@ -44,22 +44,36 @@ export default function Lightning() {
},
});

const timer = useRef<any | undefined>(undefined);
const timer_2x = useRef<any | undefined>(undefined);
const timer_4x = useRef<any | undefined>(undefined);
const timer_8x = useRef<any | undefined>(undefined);
const timers = {
2: timer_2x,
4: timer_4x,
8: timer_8x,
};

const handleOnChange = async (prompt: string) => {
if (timer.current) {
clearTimeout(timer.current);
}

Object.values(timers).forEach((t) => {
if (t.current) {
clearTimeout(t.current);
}
});
setPrompt(prompt);
const input = {
...INPUT_DEFAULTS,
prompt: prompt,
seed: seed ? Number(seed) : Number(randomSeed()),
};
connection.send(input);
timer.current = setTimeout(() => {
connection.send({ ...input, num_inference_steps: "4" });
}, 500);
// Iterate over the timers and set a timeout for each with
// the inference step count as the key
for (const [key, value] of Object.entries(timers)) {
value.current = setTimeout(() => {
connection.send({ ...input, num_inference_steps: key });
}, 100 * Number(key));
}
};

useEffect(() => {
Expand All @@ -69,7 +83,7 @@ export default function Lightning() {
// initial image
connection.send({
...INPUT_DEFAULTS,
num_inference_steps: "4",
num_inference_steps: "8",
prompt: prompt,
seed: seed ? Number(seed) : Number(randomSeed()),
});
Expand Down

0 comments on commit c333129

Please sign in to comment.