Port Ideogram 4.0 to JAX / MaxDiffusion - #442
Conversation
23fa1c2 to
ab6318b
Compare
|
/gemini review |
|
🤖 Hi @Perseus14, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
|
🤖 I'm sorry @Perseus14, but I was unable to process your request. Please see the logs for more details. |
|
/gemini review |
|
🤖 Hi @mbohlool, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
|
🤖 I'm sorry @mbohlool, but I was unable to process your request. Please see the logs for more details. |
|
/gemini review |
| # 1. Warmup Compilation | ||
| config.get_keys()["enable_profiler"] = False | ||
| config.get_keys()["enable_ml_diagnostics"] = False | ||
| config.get_keys()["num_inference_steps"] = 2 # lower for warmup |
There was a problem hiding this comment.
since we have z, _, _ = jax.lax.fori_loop(0, num_steps, denoise_step, init_val) in src/maxdiffusion/pipelines/ideogram/ideogram_pipeline.py, setting the warmup step as 2 means that the later 50 step inference time includes compile
I think this is the reason why we see a 50 sec generation time. We could either:
- go with what WAN does: only compile one step and do a plain for loop
- warmup with 50 steps
I am not sure which would be faster, it's worth testing
There was a problem hiding this comment.
Addressed: Updated the warmup compilation pass in generate_ideogram.py to use num_inference_steps = original_num_steps so XLA compiles the full 50-step loop during warmup, removing the compilation overhead from the timed inference pass. But the inference time is is ~50s. We can improve it in a follow up PR.
| q, k = _apply_rotary_pos_emb(q, k, cos, sin) | ||
|
|
||
| # Block-diagonal mask from segment ids | ||
| attn_mask = jnp.expand_dims(segment_ids, axis=2) == jnp.expand_dims(segment_ids, axis=1) |
There was a problem hiding this comment.
I am not quite sure why we need masks to do this...we can leave this for future optimization
There was a problem hiding this comment.
Acknowledged: The segment mask handles variable-length sequence padding vs. active token boundaries. We'll leave specialized splash kernel optimizations for a follow-up PR.
|
|
||
| class Ideogram4Attention(nnx.Module): | ||
|
|
||
| def __init__(self, rngs: nnx.Rngs, hidden_size: int, num_heads: int, eps: float = 1e-5, dtype=jnp.float32): |
There was a problem hiding this comment.
dtype=jnp.float32 default is never overridden, so weights_dtype/activations_dtype: bfloat16 in the config are inert.
There was a problem hiding this comment.
Addressed: Made dtype configurable in Ideogram4Config and Ideogram4Transformer, and ensured IdeogramPipeline passes config.weights_dtype (bfloat16) to the transformer instances.
- Implements native Ideogram4Transformer using flax.nnx with configurable dtype support and FSDP sharding rules - Implements IdeogramPipeline orchestrating conditional/unconditional transformers, Qwen3VLTextEncoder, and AutoEncoder with an asymmetric CFG denoising loop - Adds Qwen3VLTextEncoder for multi-layer intermediate hidden state extraction and FP8 quantized weight loading - Pre-dequantizes FP8 linear weights at load time to avoid per-step overhead - Implements Ideogram 4.0 resolution-dependent noise schedule and vectorizes sigma step calculations - Adds canonical JSON prompt schema parsing and key re-ordering for structured prompts - Adds robust offline cache loading for multi-component pipeline tokenizers - Adds generate_ideogram.py generation entrypoint with full-inference warmup compilation - Includes unit tests (generate_ideogram_smoke_test.py and generate_ideogram_end_to_end.py)
|
🤖 Hi @eltsai, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
|
🤖 I'm sorry @eltsai, but I was unable to process your request. Please see the logs for more details. |
1 similar comment
|
🤖 I'm sorry @eltsai, but I was unable to process your request. Please see the logs for more details. |
Title: Port Ideogram 4.0 to JAX / MaxDiffusion
Summary:
This PR ports the Ideogram 4.0 pipeline to JAX. It introduces the native Flax NNX
Ideogram4Transformer, integrates theTorchaxQwen3VLTextEncoderfor complex prompt processing, and implements the required asymmetric CFG denoising loop. It also includes caption key re-ordering in the pipeline to enforce Ideogram's strict JSON-based prompt schema (high_level_description,style_description,compositional_deconstruction).Generated Examples:
Prompt:
Prompt:
Prompt: