﻿# SDXL prompt caching: preserve both encoder paths and pooled conditioning

Build SDXL text-conditioning caches that retain paired prompt paths, sequence embeddings, pooled vectors, and matching negative conditioning.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-sdxl-dual-text-pooled-conditioning-cache/
Language: en

## Identify the complete conditioning bundle

SDXL uses an architecture with multiple text-conditioning components rather than a single generic prompt vector. The [paper](https://arxiv.org/abs/2307.01952) describes its text encoders and additional conditioning. A serving optimization that precomputes prompt features must preserve the inputs expected by the loaded pipeline. Start by naming the bundle's components and their provenance; a tensor with a familiar shape does not establish that every required text signal has been retained.

## Keep the prompt paths distinct

The [Diffusers SDXL reference](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/stable_diffusion_xl) exposes prompt and prompt_2 for its text-encoder paths. Applications can intentionally supply different text to those paths. A cache indexed only by the first prompt can therefore return stale conditioning when the other changes. Include the actual texts, tokenizer and encoder revisions, and relevant encoding choices in the cache identity rather than assuming the second path always receives an immutable copy.

## Preserve pooled and sequence representations together

The integration accepts both prompt_embeds and pooled_prompt_embeds, with corresponding negative-conditioning inputs. These representations serve different parts of the conditioning interface. Saving only sequence embeddings and inventing a pooled replacement later is not equivalent to the original encoding. Keep positive and negative bundles matched as well. A batch reorder must carry all components together, otherwise a valid sequence tensor can be combined with the pooled information or negative prompt from another request.

## Distinguish encoding reuse from generation reuse

Consider a catalog-image workflow that repeatedly uses the same style prompt while changing object descriptions. Reuse is valid only for the parts of conditioning that actually remain unchanged under the selected encoder path. The [base checkpoint card](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) identifies a concrete model artifact; adapted weights can change the encoding contract too. A fixed random seed does not make different conditioning bundles identical, and identical text does not remove the need to record model and processor versions.

## Compare cached and uncached execution

Use a fixed, documented generation setup to compare full text encoding with the cached bundle, including negative prompts and different prompt_2 values. Inspect batching and component association before timing the optimization. Existing guides on [artifact validation](/journal/safetensors-artifact-validation/) and [diffusion benchmarking](/journal/stable-diffusion-gpu-benchmark/) provide context. SDXL's distinctive caching obligation is preserving the complete dual-path conditioning object; the optimization should avoid repeated computation without silently replacing the trained interface with a partial representation.
