Skip to content

enable Qwen image Layered on Gaudi.#383

Merged
Wei-Lin-Intel merged 12 commits into
HabanaAI:aice/v1.22.0from
nc-BobLee:qwenimage_layered_dev
Jan 7, 2026
Merged

enable Qwen image Layered on Gaudi.#383
Wei-Lin-Intel merged 12 commits into
HabanaAI:aice/v1.22.0from
nc-BobLee:qwenimage_layered_dev

Conversation

@nc-BobLee
Copy link
Copy Markdown

No description provided.



device = 'hpu'
model_path = '/mnt/ceph1/libo/hf_models/Qwen-Image-Layered/'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the path to something like /data/Qwen-Image-Layered or the default huggingface model id


from transformers import Qwen2_5_VLForConditionalGeneration, Qwen2Tokenizer, Qwen2VLProcessor

from optimum.habana.transformers.models import GaudiQwen2_5_VLForConditionalGeneration
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is not used, delete it.

from transformers import Qwen2_5_VLForConditionalGeneration, Qwen2Tokenizer, Qwen2VLProcessor

from optimum.habana.transformers.models import GaudiQwen2_5_VLForConditionalGeneration
from optimum.habana.diffusers.models.qwenimage_transformer import QwenImageTransformer2DModelGaudi,QwenImageTransformerBlockForwardGaudi
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space between QwenImageTransformer2DModelGaudi, and QwenImageTransformerBlockForwardGaudi

if use_hpu_graphs:
logger.warning(
"WARNING:!!!GaudiQwenImageLayeredPipeline HPU graph mode may have OOM problem when image size changes. Please set use_hpu_graphs=False!!!"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set use_hpu_graphs=False here to avoid OOM issue

self.transformer.hidden_states_buckets_step = hidden_states_buckets_step
self.transformer.encoder_hidden_states_buckets_step = encoder_hidden_states_buckets_step

#self.to(self._device)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete it

from diffusers.utils.torch_utils import randn_tensor
from diffusers.pipelines.qwenimage import QwenImagePipelineOutput
from diffusers.models.autoencoders.autoencoder_kl_qwenimage import QwenImageAttentionBlock
from diffusers.pipelines.qwenimage.pipeline_qwenimage_layered import QwenImageLayeredPipeline,calculate_dimensions,retrieve_timesteps
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces bweteen ,

theta=10000, axes_dim=list(config["axes_dims_rope"]), scale_rope=True
)

self.vae_decode_latents_buckets = [128,160,188]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test different image sizes, and check if these default buckets value is suitable for this model.

f"vae_decode_latents_buckets is {self.vae_decode_latents_buckets}."
)

self.vae_encode_buckets = [1024,1280,1504]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test different image sizes, and check if these default buckets value is suitable for this model.

layer.forwward = types.MethodType(QwenImageAttentionBlockForwardGaudi, layer)

config = self.transformer.config
self.transformer.pos_embed = GaudiQwenEmbedRope(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful of new PR, not everything can be applied from old PR. According to Qwen-Image-Layered Diffusers PR, it uses QwenEmbedLayer3DRope, not QwenEmbedRope. Also please check the other places to make sure everything is migrated.

@Wei-Lin-Intel Wei-Lin-Intel merged commit 23dd420 into HabanaAI:aice/v1.22.0 Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants