Skip to content

Commit 84a2a3a

Browse files
authored
SDXL app: move await device to fix empty results (#975)
The output array was coming out empty. We discovered that the `await device` needs to be moved after the transfer to host but before the device array's `items` is read.
1 parent ab42f0c commit 84a2a3a

File tree

1 file changed

+10
-3
lines changed
  • shortfin/python/shortfin_apps/sd/components

1 file changed

+10
-3
lines changed

shortfin/python/shortfin_apps/sd/components/service.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,11 @@ async def run(self):
386386
await self._denoise(device=device)
387387
if phases[InferencePhase.DECODE]["required"]:
388388
await self._decode(device=device)
389-
# Postprocessing needs the output data to be on the host. Even
390-
# without postprocessing, we're done with the GPU, so we wait for
391-
# it to finish here.
389+
else:
390+
# Decode and postprocess both need the output data to be on the host.
391+
# With decode enabled, decode itself will wait for the data.
392+
# With decode disabled, whether or not we're postprocessing,
393+
# we're done with the GPU, so we wait for it to finish here.
392394
await device
393395
if phases[InferencePhase.POSTPROCESS]["required"]:
394396
await self._postprocess(device=device)
@@ -546,6 +548,11 @@ async def _decode(self, device):
546548
)
547549
(cb.images,) = await fn(cb.latents, fiber=self.fiber)
548550
cb.images_host.copy_from(cb.images)
551+
552+
# Wait for the device-to-host transfer, so that we can read the
553+
# data with .items.
554+
await device
555+
549556
image_array = cb.images_host.items
550557
dtype = image_array.typecode
551558
if cb.images_host.dtype == sfnp.float16:

0 commit comments

Comments
 (0)