|
20 | 20 | _kv_storage_contract, |
21 | 21 | _static_cache_ports, |
22 | 22 | _validate_attention_alias_layer_sets, |
| 23 | + build_diffusion_workflow_metadata, |
| 24 | + build_image_edit_workflow_metadata, |
23 | 25 | build_language_diffusion_pipeline_metadata, |
24 | 26 | build_speculative_workflow_metadata, |
25 | 27 | build_video_diffusion_workflow_metadata, |
@@ -592,6 +594,105 @@ def test_video_diffusion_requires_paired_conv_caches(): |
592 | 594 | ) |
593 | 595 |
|
594 | 596 |
|
| 597 | +def _diffusion_package() -> ModelPackage: |
| 598 | + """Minimal rank-4 denoiser/VAE pair shaped for ``build_diffusion_workflow_metadata``.""" |
| 599 | + latent_shape: list[int | str] = ["batch", 4, "height", "width"] |
| 600 | + denoiser = _model( |
| 601 | + "denoiser", |
| 602 | + [ |
| 603 | + _value("sample", ir.DataType.FLOAT, latent_shape), |
| 604 | + _value("timestep", ir.DataType.FLOAT, ["batch"]), |
| 605 | + ], |
| 606 | + [("noise_pred", ir.DataType.FLOAT, latent_shape)], |
| 607 | + ) |
| 608 | + vae_decoder = _model( |
| 609 | + "vae_decoder", |
| 610 | + [_value("latent", ir.DataType.FLOAT, latent_shape)], |
| 611 | + [("image", ir.DataType.FLOAT, ["batch", 3, "height", "width"])], |
| 612 | + ) |
| 613 | + return ModelPackage({"denoiser": denoiser, "vae_decoder": vae_decoder}) |
| 614 | + |
| 615 | + |
| 616 | +def _image_edit_package() -> ModelPackage: |
| 617 | + """Qwen-Image-Edit-shaped package for ``build_image_edit_workflow_metadata``. |
| 618 | +
|
| 619 | + Rank-3 packed latents, a ``target_sequence_length`` slice port, separate |
| 620 | + image/text rotary tables, and a VAE encoder/decoder pair -- the port shape |
| 621 | + the real Qwen Image Edit export produces. |
| 622 | + """ |
| 623 | + tokens = ["batch", "image_sequence_length", 64] |
| 624 | + transformer = _model( |
| 625 | + "transformer", |
| 626 | + [ |
| 627 | + _value("sample", ir.DataType.FLOAT, tokens), |
| 628 | + _value("timestep", ir.DataType.FLOAT, ["batch"]), |
| 629 | + _value( |
| 630 | + "encoder_hidden_states", |
| 631 | + ir.DataType.FLOAT, |
| 632 | + ["batch", "text_sequence_length", 32], |
| 633 | + ), |
| 634 | + _value( |
| 635 | + "encoder_hidden_states_mask", |
| 636 | + ir.DataType.BOOL, |
| 637 | + ["batch", "text_sequence_length"], |
| 638 | + ), |
| 639 | + _value("image_rotary_cos", ir.DataType.FLOAT, ["image_sequence_length", 8]), |
| 640 | + _value("image_rotary_sin", ir.DataType.FLOAT, ["image_sequence_length", 8]), |
| 641 | + _value("text_rotary_cos", ir.DataType.FLOAT, ["text_sequence_length", 8]), |
| 642 | + _value("text_rotary_sin", ir.DataType.FLOAT, ["text_sequence_length", 8]), |
| 643 | + _value("target_sequence_length", ir.DataType.INT64, [1]), |
| 644 | + ], |
| 645 | + [("noise_pred", ir.DataType.FLOAT, tokens)], |
| 646 | + ) |
| 647 | + vae_encoder = _model( |
| 648 | + "vae_encoder", |
| 649 | + [_value("pixel_values", ir.DataType.FLOAT, ["batch", 3, 1, "height", "width"])], |
| 650 | + [("latent_sample", ir.DataType.FLOAT, ["batch", 16, 1, "lheight", "lwidth"])], |
| 651 | + ) |
| 652 | + vae_decoder = _model( |
| 653 | + "vae_decoder", |
| 654 | + [_value("latent_sample", ir.DataType.FLOAT, ["batch", 16, 1, "lheight", "lwidth"])], |
| 655 | + [("image", ir.DataType.FLOAT, ["batch", 3, 1, "height", "width"])], |
| 656 | + ) |
| 657 | + return ModelPackage( |
| 658 | + { |
| 659 | + "transformer": transformer, |
| 660 | + "vae_encoder": vae_encoder, |
| 661 | + "vae_decoder": vae_decoder, |
| 662 | + } |
| 663 | + ) |
| 664 | + |
| 665 | + |
| 666 | +def test_diffusion_workflow_declares_image_value_range(): |
| 667 | + """Assert value_range directly on the built metadata dict. |
| 668 | +
|
| 669 | + Producer conformance requires every ``role: image`` output to declare |
| 670 | + an explicit ``value_range``; check this directly rather than through a |
| 671 | + committed fixture snapshot. |
| 672 | + """ |
| 673 | + metadata = build_diffusion_workflow_metadata(_diffusion_package(), num_inference_steps=2) |
| 674 | + published = metadata["pipeline"]["workflow"]["outputs"]["image"] |
| 675 | + assert published["role"] == "image" |
| 676 | + assert published["value_range"] == "negative_one_to_one" |
| 677 | + |
| 678 | + |
| 679 | +def test_image_edit_workflow_declares_image_value_range(): |
| 680 | + """Same producer-conformance contract as the diffusion workflow. |
| 681 | +
|
| 682 | + The image-edit workflow's ``image`` output must also declare its range. |
| 683 | + """ |
| 684 | + metadata = build_image_edit_workflow_metadata( |
| 685 | + _image_edit_package(), |
| 686 | + num_inference_steps=2, |
| 687 | + schedule=[1.0, 0.5, 0.0], |
| 688 | + timesteps=[1.0, 0.5], |
| 689 | + guidance_scale=4.0, |
| 690 | + ) |
| 691 | + published = metadata["pipeline"]["workflow"]["outputs"]["image"] |
| 692 | + assert published["role"] == "image" |
| 693 | + assert published["value_range"] == "negative_one_to_one" |
| 694 | + |
| 695 | + |
595 | 696 | def test_language_diffusion_rejects_zero_steps(): |
596 | 697 | with pytest.raises(ValueError, match="num_inference_steps"): |
597 | 698 | build_language_diffusion_pipeline_metadata( |
|
0 commit comments