Support LLaDa-Image - #14815
Open
lucasruan1618 wants to merge 3 commits into
Open
Support LLaDa-Image#14815lucasruan1618 wants to merge 3 commits into
lucasruan1618 wants to merge 3 commits into
Conversation
Contributor
|
Hi @lucasruan1618, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Please note that PRs without a linked issue are likely to be automatically closed 10 days after this notice. Once the PR links an issue (or gets the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR adds native LLaDA-Image support to Diffusers. It introduces
LLaDAImagePipeline, a single pipeline for text-to-image generation, VQ-conditioned generation, and instruction-guided image editing.The implementation ports the published LLaDA-Image inference architecture while using Diffusers' standard component registration, serialization, device placement, CPU offloading, group offloading, attention processor, and pipeline loading interfaces.
Pipeline architecture
LLaDAImagePipelineregisters the eight components already described by the publishedmodel_index.json:text_encoderandtokenizerqueryformertext_projectionsigvqtransformervaeschedulerThe pipeline is loaded with the usual
DiffusionPipeline.from_pretrainedpath. The published LLaDA2 text encoder is custom remote code, so users must passtrust_remote_code=Truewhen loading the official checkpoint.text_encoderremains resident because the pipeline directly calls its embedding layer and language backbone; the QueryFormer output must be inserted between those calls. The remaining model components participate in the normal offloading sequence: QueryFormer, text projection, SigVQ, denoising transformer, and VAE.Supported inference modes
Text-to-image
generation_mode="text"is the default path. The pipeline encodes the positive prompt and, whenguidance_scale > 1, an empty or supplied negative prompt. It then denoises random Flux2 latent patches using classifier-free guidance.VQ-conditioned generation
generation_mode="vq"asks the LLaDA2 image-generation head for VQ token IDs. The pipeline converts those IDs to SigVQ semantic features and supplies them to the denoising transformer alongside prompt features. The frontend VQ grid is capped at 512 pixels on its longest side, matching the reference implementation.Image editing
generation_mode="editing"requires an inputimage. The pipeline normalizes and encodes that image twice: SigVQ produces semantic image features, and the Flux2 VAE produces source latents. The denoising transformer receives both forms of conditioning with the text instruction.The pipeline validates mode-specific inputs before inference. Text and VQ modes reject
image; editing requires it; VQ dimensions must be divisible by 16; and all output dimensions must match the Flux2 VAE and latent-patch scaling requirements.New public model components
The PR adds and exports four serializable Diffusers models:
LLaDAImageTransformer2DModel, the variable-resolution denoising transformer.LLaDAImageQueryFormerModel, which refines learned generation queries against token embeddings.LLaDAImageTextProjectionModel, which connects LLaDA2 hidden states to transformer caption features.LLaDAImageSigVQModel, which supports both image-to-VQ encoding and VQ-token-to-semantic-feature lookup.The transformer preserves the reference model's list-valued output so a batch may contain samples with different spatial shapes. Its RoPE cache is bypassed only while
torch.compiletraces the model, avoiding module-state mutation during export while retaining the normal eager-mode cache.Diffusers integration details
from_pretrainedoverride.defaultRoPE registry entry required by the checkpoint's custom text encoder when Transformers 5 omits it.save_pretrained/from_pretrained, dtype loading, device maps, CPU/disk offload, model CPU offload, group offload, callbacks, batching, and supported image output types.Tests
tests/models/transformers/test_models_transformer_llada_image.py: model serialization, deterministic outputs, dtype loading, CPU/disk/group offload, gradient checkpointing, attention processor behavior, compilation, and direct QueryFormer, projection, and SigVQ forward coverage.tests/pipelines/llada_image/test_pipeline_llada_image.py: shared pipeline contracts for loading, batching, callbacks, serialization, dtype handling, accelerator integration, and offloading; plus focused VQ and image-editing tests.Validation performed:
pytest tests/models/transformers/test_models_transformer_llada_image.py -q: 43 passed, 12 skipped.pytest tests/pipelines/llada_image/test_pipeline_llada_image.py -q: 38 passed, 1 skipped.make quality,utils/check_dummies.py,utils/check_copies.py, andgit diff --check: passed.llada_image_text_to_image.png.llada_image_vq_transformers_5.png.llada_image_edit.png.The skips cover generic test utilities that cannot operate on the transformer's intentionally list-valued input/output interface, plus AOT package loading, which currently cannot deserialize list-valued inputs. The standard eager, dynamic-shape, and repeated-block
torch.compiletests pass.Self-review
Verdict: READY
No blocking or non-blocking issues remain. The Transformers 5.15.1 VQ failure was traced to the official remote text encoder's non-persistent RoPE buffer being initialized on the meta device during sharded loading. The corrected buffer reproduces the Transformers 4.57.6 reference tokens exactly in the reduced comparison, and the full 512×512 Transformers 5 output is byte-identical to the reference-runtime output.
No likely-dead inference paths were found. The text, VQ, and editing paths are all traced from
LLaDAImagePipeline.__call__and covered by tests. The official configuration schema was checked against every new model constructor, and the port preserves upstream model math apart from the compile-safe RoPE cache guard and Diffusers device/offloading integration.Before submitting
self-reviewskill on the diff?Who can review?