Skip to content

TextEncodeCached disk cache keyed only on prompt — stale embeds after switching model/precision/quantization #2046

Description

@NubeBuster

WanVideoTextEncodeCached.process() (nodes.py) writes/reads text-embedding tensors to a disk cache under text_embed_cache/, keyed only on the prompt string:

def get_cache_path(prompt):
    cache_key = prompt.strip()
    cache_hash = hashlib.sha256(cache_key.encode('utf-8')).hexdigest()
    return os.path.join(cache_dir, f"{cache_hash}.pt")

(nodes.py, get_cache_path, ~lines 156-159, called from get_cached_text_embeds/process around line 258)

process() also takes model_name, precision (fp32/bf16), and quantization (disabled/fp8_e4m3fn) as inputs — all of which affect the embedding tensor that gets produced — but none of them are part of the cache key. Practical effect: encode a prompt once with encoder A, then switch to encoder B (or just change precision/quantization) while reusing the same prompt text, and the node silently serves the embeddings computed with the old model/precision from disk instead of re-encoding. No error, no warning — and since the cache is on disk, this persists across ComfyUI restarts, not just within a session.

Suggested fix: fold model_name, precision, and quantization into the hashed key, e.g.

cache_key = f"{model_name}|{precision}|{quantization}|{prompt.strip()}"

Existing cache files would simply go unused and get regenerated under new hashes — no migration needed.

Minor/secondary, same mechanism: the in-memory _extender_cache a few lines up (keyed on (orig_prompt, str(extender_args))) similarly doesn't include the device/precision args passed to the prompt-extender's generate() call. Lower severity since it's LLM-generated prompt text rather than embeddings, but flagging it here since it's the same pattern in the same function.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions