[Core] Supports stage abstraction in the diffusion model (#391)

Signed-off-by: Chenguang ZHENG <645327136@qq.com>
Signed-off-by: yinpeiqi <yinpeiqi809@gmail.com>
Co-authored-by: yinpeiqi <yinpeiqi809@gmail.com>
Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
authored and GitHub committed 2025-12-27 01:59:33 +13:00
1 parent 1f875f06d9
commit 595e7c0032
41 files changed
+2473 -1242

No files matched your search

+3 -3
View File
@@ -69,7 +69,7 @@ class OmniRunner:
Returns:
List of SamplingParams with default decoding for each stage
"""
return [st.default_sampling_params for st in self.omni.instance.stage_list]
return [st.default_sampling_params for st in self.omni.stage_list]
def get_omni_inputs(
self,
@@ -337,8 +337,8 @@ class OmniRunner:
def close(self):
"""Close and cleanup the Omni instance."""
if hasattr(self.omni.instance, "close"):
self.omni.instance.close()
if hasattr(self.omni, "close"):
self.omni.close()
@pytest.fixture(scope="session")
@@ -81,6 +81,7 @@ stage_args:
engine_output_type: audio # Final output: audio waveform
gpu_memory_utilization: 0.1
distributed_executor_backend: "mp"
max_num_seqs: 1
max_num_batched_tokens: 1000000
hf_config_name: thinker_config
load_format: dummy
+14 -1
View File
@@ -51,7 +51,7 @@ def test_cache_dit(model_name: str):
width = 256
num_inference_steps = 4 # Minimal steps for fast test
images = m.generate(
outputs = m.generate(
"a photo of a cat sitting on a laptop keyboard",
height=height,
width=width,
@@ -60,6 +60,17 @@ def test_cache_dit(model_name: str):
generator=torch.Generator("cuda").manual_seed(42),
num_outputs_per_prompt=1, # Single output for speed
)
# Extract images from request_output[0]['images']
first_output = outputs[0]
assert first_output.final_output_type == "image"
if not hasattr(first_output, "request_output") or not first_output.request_output:
raise ValueError("No request_output found in OmniRequestOutput")
req_out = first_output.request_output[0]
if not isinstance(req_out, dict) or "images" not in req_out:
raise ValueError("Invalid request_output structure or missing 'images' key")
images = req_out["images"]
# Verify generation succeeded
assert images is not None
@@ -67,3 +78,5 @@ def test_cache_dit(model_name: str):
# Check image size
assert images[0].width == width
assert images[0].height == height
# manually close the Omni instance
m.close()
@@ -78,7 +78,7 @@ def test_sequence_parallel(model_name: str, ulysses_degree: int, ring_degree: in
dtype=dtype,
)
try:
baseline_images = baseline.generate(
outputs = baseline.generate(
PROMPT,
height=height,
width=width,
@@ -87,6 +87,7 @@ def test_sequence_parallel(model_name: str, ulysses_degree: int, ring_degree: in
generator=torch.Generator(get_device_name()).manual_seed(seed),
num_outputs_per_prompt=1,
)
baseline_images = outputs[0].request_output[0]["images"]
finally:
baseline.close()
@@ -103,7 +104,7 @@ def test_sequence_parallel(model_name: str, ulysses_degree: int, ring_degree: in
dtype=dtype,
)
try:
sp_images = sp.generate(
outputs = sp.generate(
PROMPT,
height=height,
width=width,
@@ -112,6 +113,7 @@ def test_sequence_parallel(model_name: str, ulysses_degree: int, ring_degree: in
generator=torch.Generator(get_device_name()).manual_seed(seed),
num_outputs_per_prompt=1,
)
sp_images = outputs[0].request_output[0]["images"]
finally:
sp.close()
+15 -1
View File
@@ -37,7 +37,7 @@ def test_diffusion_model(model_name: str):
# high resolution may cause OOM on L4
height = 256
width = 256
images = m.generate(
outputs = m.generate(
"a photo of a cat sitting on a laptop keyboard",
height=height,
width=width,
@@ -46,8 +46,22 @@ def test_diffusion_model(model_name: str):
generator=torch.Generator("cuda").manual_seed(42),
num_outputs_per_prompt=2,
)
# Extract images from request_output[0]['images']
first_output = outputs[0]
assert first_output.final_output_type == "image"
if not hasattr(first_output, "request_output") or not first_output.request_output:
raise ValueError("No request_output found in OmniRequestOutput")
req_out = first_output.request_output[0]
if not isinstance(req_out, dict) or "images" not in req_out:
raise ValueError("Invalid request_output structure or missing 'images' key")
images = req_out["images"]
assert len(images) == 2
# check image size
assert images[0].width == width
assert images[0].height == height
images[0].save("image_output.png")
# manually close the Omni instance
m.close()
+13 -1
View File
@@ -30,7 +30,7 @@ def test_video_diffusion_model(model_name: str):
height = 480
width = 640
num_frames = 5
frames = m.generate(
outputs = m.generate(
"A cat sitting on a table",
height=height,
width=width,
@@ -39,6 +39,16 @@ def test_video_diffusion_model(model_name: str):
guidance_scale=1.0,
generator=torch.Generator("cuda").manual_seed(42),
)
first_output = outputs[0]
assert first_output.final_output_type == "image"
if not hasattr(first_output, "request_output") or not first_output.request_output:
raise ValueError("No request_output found in OmniRequestOutput")
req_out = first_output.request_output[0]
if not isinstance(req_out, dict) or "images" not in req_out:
raise ValueError("Invalid request_output structure or missing 'images' key")
frames = req_out["images"][0]
assert frames is not None
assert hasattr(frames, "shape")
@@ -46,3 +56,5 @@ def test_video_diffusion_model(model_name: str):
assert frames.shape[1] == num_frames
assert frames.shape[2] == height
assert frames.shape[3] == width
# manually close the Omni instance
m.close()
+14 -1
View File
@@ -47,7 +47,7 @@ def test_teacache(model_name: str):
width = 256
num_inference_steps = 4 # Minimal steps for fast test
images = m.generate(
outputs = m.generate(
"a photo of a cat sitting on a laptop keyboard",
height=height,
width=width,
@@ -56,6 +56,17 @@ def test_teacache(model_name: str):
generator=torch.Generator("cuda").manual_seed(42),
num_outputs_per_prompt=1, # Single output for speed
)
# Extract images from request_output[0]['images']
first_output = outputs[0]
assert first_output.final_output_type == "image"
if not hasattr(first_output, "request_output") or not first_output.request_output:
raise ValueError("No request_output found in OmniRequestOutput")
req_out = first_output.request_output[0]
if not isinstance(req_out, dict) or "images" not in req_out:
raise ValueError("Invalid request_output structure or missing 'images' key")
images = req_out["images"]
# Verify generation succeeded
assert images is not None
@@ -63,3 +74,5 @@ def test_teacache(model_name: str):
# Check image size
assert images[0].width == width
assert images[0].height == height
# manually close the Omni instance
m.close()