automatic icon indicating copy to clipboard operation
automatic copied to clipboard

[Issue]: Wan txt2img ignores variation seeds on the checkpoint route

Open Jackmeson1 opened this issue 1 month ago • 4 comments

Issue Description

With Wan-AI/Wan2.1-T2V-1.3B-Diffusers loaded through POST /sdapi/v1/checkpoint, changing variation settings in /sdapi/v1/txt2img produces identical JPEG image data, while the response info and infotext report the requested variation settings.

The same three requests with SD 1.5 produce three different image-data hashes. This report covers only the tested Wan checkpoint-loading and txt2img path; variation behavior on other models, loading routes, and the video endpoint was not tested.

To reproduce, use JPEG output (samples_format: jpg, the default), save the script below as repro_varseed.py, and run it after loading each model. Both models must be available to the server. Check that each checkpoint request returns "ok": true.

API=http://127.0.0.1:7860

curl --fail-with-body -sS -X POST -G \
  --data-urlencode 'sd_model_checkpoint=hub/Wan-AI/Wan2.1-T2V-1.3B-Diffusers' \
  --data-urlencode 'force=true' \
  "$API/sdapi/v1/checkpoint"
python3 repro_varseed.py "$API"

curl --fail-with-body -sS -X POST -G \
  --data-urlencode 'sd_model_checkpoint=hub/stable-diffusion-v1-5/stable-diffusion-v1-5' \
  --data-urlencode 'force=true' \
  "$API/sdapi/v1/checkpoint"
python3 repro_varseed.py "$API"

The script sends three requests with seed=42, batch_size=1, and n_iter=1:

  • (a) subseed_strength=0, with subseed omitted.
  • (b) subseed=7, subseed_strength=0.5.
  • (c) subseed=8, subseed_strength=0.5.

image_sha256 hashes the returned JPEG after removing APP0–APP15 and COM metadata segments, retaining its tables, frame header, and scan data. This avoids differences caused solely by embedded infotext. It is an encoded-image-data comparison, not a decoded-pixel hash. The script also prints the unmodified file hash and reported seed settings.

repro_varseed.py — Python standard library only
"""Compare variation seeds using SD.Next JPEG responses; stdlib only.
Usage: python3 repro_varseed.py [API]. Load the model first.
"""
import base64
import hashlib
import json
import struct
import sys
import urllib.request

API = sys.argv[1] if len(sys.argv) > 1 else "http://127.0.0.1:7860"
BASE = {"prompt": "a red fox running in snow", "width": 480, "height": 320, "steps": 6, "seed": 42,
        "batch_size": 1, "n_iter": 1, "send_images": True, "save_images": False}
CASES = [("a", {"subseed_strength": 0}),
         ("b", {"subseed": 7, "subseed_strength": 0.5}),
         ("c", {"subseed": 8, "subseed_strength": 0.5})]


def post(path, payload):
    req = urllib.request.Request(API + path, data=json.dumps(payload).encode(), method="POST",
                                 headers={"Content-Type": "application/json"})
    with urllib.request.urlopen(req, timeout=3600) as r:
        return json.loads(r.read())


def jpeg_data(data):
    """Return the JPEG with APPn/COM metadata segments removed (tables, frame header, scan data kept), or None."""
    if data[:2] != b"\xff\xd8":
        return None
    out, pos = bytearray(b"\xff\xd8"), 2
    while pos < len(data):
        if data[pos] != 0xFF:
            return None
        marker = data[pos + 1]
        if marker == 0xDA:  # start of scan: entropy-coded data runs to EOI
            out += data[pos:]
            return bytes(out)
        length = struct.unpack(">H", data[pos + 2:pos + 4])[0]
        if not (0xE0 <= marker <= 0xEF or marker == 0xFE):
            out += data[pos:pos + 2 + length]
        pos += 2 + length
    return None


def image_hash(data):
    jp = jpeg_data(data)
    if jp:
        return "jpeg-no-metadata", f"{len(jp)} bytes", hashlib.sha256(jp).hexdigest()
    raise ValueError("Expected JPEG; set samples_format to jpg.")


opts = json.loads(urllib.request.urlopen(API + "/sdapi/v1/options", timeout=60).read())
print(f"model: {opts.get('sd_model_checkpoint')}")
for name, extra in CASES:
    res = post("/sdapi/v1/txt2img", dict(BASE, **extra))
    images = res.get("images", [])
    if len(images) != 1:
        raise RuntimeError(f"Expected one image, got {len(images)}")
    info = json.loads(res["info"]) if isinstance(res.get("info"), str) else res.get("info", {})
    data = base64.b64decode(images[0].split(",", 1)[-1])
    kind, shape, data_hash = image_hash(data)
    variation = [t for t in str((info.get("infotexts") or [""])[0]).split(", ") if "ariation" in t or t.startswith("Seed")]
    print(f"({name}) request={json.dumps(extra)} images={len(images)} [{kind} {shape}]")
    print(f"    image_sha256={data_hash}")
    print(f"    file_sha256={hashlib.sha256(data).hexdigest()}")
    print(f"    info: seed={info.get('seed')} subseed={info.get('subseed')} subseed_strength={info.get('subseed_strength')}"
          f" all_seeds={info.get('all_seeds')} all_subseeds={info.get('all_subseeds')}")
    print(f"    infotext: {', '.join(variation)}")

Results from my final run of the script and commands above, showing the first eight hexadecimal characters of image_sha256:

Model (a) strength 0 (b) subseed 7, strength 0.5 (c) subseed 8, strength 0.5
Wan2.1-T2V-1.3B 761b9985… 761b9985… 761b9985…
SD 1.5 7c84d95e… c191b26a… 171d2cf8…

All three Wan responses contain one image and the same full image-data SHA-256:

761b9985be114dc798a9aa651ee762f885b1239e76e84f60c01bb6b2d1c07202

Their raw file hashes differ. In cases (b) and (c), info reports the requested subseed and strength, and the infotext contains respectively:

Seed: 42, Variation seed: 7, Variation strength: 0.5
Seed: 42, Variation seed: 8, Variation strength: 0.5

Case (a) reports strength zero and a server-selected subseed; its infotext contains only Seed: 42 among these fields. Compare equality within a run rather than requiring these exact hashes on another setup.

The code appears to explain the result: scripts/init_latents.py:33 returns before variation-noise creation when the pipeline has no unet, as with the tested Wan pipeline. The applicable generator path uses only p.seeds (modules/processing_helpers.py:571), and no blended latents reach Wan. Nevertheless, modules/processing_info.py:104-105 includes the variation seed and strength in txt2img infotext.

Expected: applying variation settings should change the result. If this feature is unsupported on this Wan path, please report that clearly and avoid presenting ignored variation settings as applied generation parameters.

Version Platform Description

SD.Next dev commit b0bd587b, tested in a detached checkout. Linux, kernel 6.6.122+; NVIDIA RTX PRO 6000 Blackwell Server Edition; Python 3.13.15; torch 2.14.1+cu130; diffusers 0.41.0.dev0. Interface: API; no browser involved.

Models loaded through /sdapi/v1/checkpoint:

  • Wan-AI/Wan2.1-T2V-1.3B-Diffusers — [0fad780a53]
  • stable-diffusion-v1-5/stable-diffusion-v1-5 — [451f4fe161], used as a control

Relevant log output

Excerpts from the same run; console wrapping removed and ... marks omitted fields. All three complete Wan argument dictionaries lack a latents entry.

14:23:23-942160 INFO Base: pipeline=WanPipeline task=TEXT_2_IMAGE batch=1/1x1 set={'prompt': 1, 'negative_prompt': 1, 'guidance_scale': 6.0, 'generator': 'cuda:[42]', 'num_inference_steps': 6, 'num_frames': 1, 'output_type': 'np', 'width': 480, 'height': 320, 'parser': 'fixed', 'ref': False}
14:23:26-158303 INFO Base: pipeline=WanPipeline task=TEXT_2_IMAGE batch=1/1x1 set={'prompt': 1, 'negative_prompt': 1, 'guidance_scale': 6.0, 'generator': 'cuda:[42]', 'num_inference_steps': 6, 'num_frames': 1, 'output_type': 'np', 'width': 480, 'height': 320, 'parser': 'fixed', 'ref': False}
14:23:26-410227 INFO Base: pipeline=WanPipeline task=TEXT_2_IMAGE batch=1/1x1 set={'prompt': 1, 'negative_prompt': 1, 'guidance_scale': 6.0, 'generator': 'cuda:[42]', 'num_inference_steps': 6, 'num_frames': 1, 'output_type': 'np', 'width': 480, 'height': 320, 'parser': 'fixed', 'ref': False}
14:23:45-384661 DEBUG Latent: seed=[42] subseed=[7] strength=0.5 tensor=[1, 4, 40, 60]
14:23:45-395091 INFO Base: pipeline=StableDiffusionPipeline ... 'generator': 'cuda:[42]', 'latents': torch.Size([1, 4, 40, 60]) ...
14:23:45-538000 DEBUG Latent: seed=[42] subseed=[8] strength=0.5 tensor=[1, 4, 40, 60]

Related to #5168 (Wan loading-route defaults) but separate: the fix linked there leaves variation-seed handling unchanged. A search of open and closed issues found no existing report.

Found and reproduced with AI assistance; the repro above was run by me.

Jackmeson1 avatar Oct 21 '26 07:10 Jackmeson1

note that subseed parameter is not valid/relevant for most of modern models, it was used in the past when manually constructing initial noise.

vladmandic avatar Oct 21 '26 09:10 vladmandic

Thanks, that matches the code path I saw: scripts/init_latents.py returns before creating variation noise when the pipeline has no unet, so Wan never uses it. The only visible effect left is that info and the infotext still list the variation seed and strength for these models. If that's expected, feel free to close this.

Jackmeson1 avatar Oct 21 '26 09:10 Jackmeson1

its one of the legacy items from a1111 days. i'll remove subseed altogether.

vladmandic avatar Oct 21 '26 09:10 vladmandic

update; subseed and resize-seed have been removed

vladmandic avatar Oct 21 '26 10:10 vladmandic