Skip to content

Commit 2c4100c

Browse files
authored
skip init for speed up z image constructor (#228)
* skip init for speed up z image constructor * up * up
1 parent 31dce8f commit 2c4100c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

diffsynth_engine/models/z_image/qwen3.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ def from_state_dict(
5959
device: str = "cuda:0",
6060
dtype: torch.dtype = torch.bfloat16,
6161
):
62-
model = cls(config=config, device="meta", dtype=dtype)
62+
with torch.device("meta"):
63+
model = cls(config=config, device="meta", dtype=dtype)
6364
model.requires_grad_(False)
65+
66+
model.rotary_emb = Qwen3RotaryEmbedding(config=config, device=device)
6467
model.load_state_dict(state_dict, assign=True)
6568
model.to(device=device, dtype=dtype, non_blocking=True)
6669
return model

diffsynth_engine/models/z_image/z_image_dit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ def from_state_dict(
584584
dtype: torch.dtype,
585585
**kwargs,
586586
):
587-
model = cls(device="meta", dtype=dtype, **kwargs)
587+
with torch.device("meta"):
588+
model = cls(device="meta", dtype=dtype, **kwargs)
588589
model = model.requires_grad_(False)
589590
model.load_state_dict(state_dict, assign=True)
590591
model.to(device=device, dtype=dtype, non_blocking=True)

0 commit comments

Comments
 (0)