MCPcopy Create free account
hub / github.com/00why00/JoDiffusion / forward

Method forward

pipelines/modeling_uvit.py:169–347  ·  view source on GitHub ↗

Args: prompt_embeds (`torch.Tensor` of shape `(batch size, seq_len, text_dim)`): CLIP-embedded text representation. image_latents (`torch.Tensor` of shape `(batch size, latent channels, height, width)`): Latent image representation fro

(
        self,
        prompt_embeds: torch.Tensor,
        image_latents: torch.Tensor,
        image_embeds: torch.Tensor,
        label_latents: torch.Tensor,
        timestep_img: Union[torch.Tensor, float, int],
        timestep_text: Union[torch.Tensor, float, int],
        data_type: Optional[Union[torch.Tensor, float, int]] = 1,
        encoder_hidden_states=None,
        cross_attention_kwargs=None,
    )

Source from the content-addressed store, hash-verified

167 return {"pos_embed"}
168
169 def forward(
170 self,
171 prompt_embeds: torch.Tensor,
172 image_latents: torch.Tensor,
173 image_embeds: torch.Tensor,
174 label_latents: torch.Tensor,
175 timestep_img: Union[torch.Tensor, float, int],
176 timestep_text: Union[torch.Tensor, float, int],
177 data_type: Optional[Union[torch.Tensor, float, int]] = 1,
178 encoder_hidden_states=None,
179 cross_attention_kwargs=None,
180 ):
181 """
182 Args:
183 prompt_embeds (`torch.Tensor` of shape `(batch size, seq_len, text_dim)`):
184 CLIP-embedded text representation.
185 image_latents (`torch.Tensor` of shape `(batch size, latent channels, height, width)`):
186 Latent image representation from the VAE encoder.
187 image_embeds (`torch.Tensor` of shape `(batch size, 1, clip_img_dim)`):
188 CLIP-embedded image representation (unsqueezed in the first dimension).
189 label_latents (`torch.Tensor` of shape `(batch size, seq_len, label_dim)`):
190 Task-specific-model-embedded label representation.
191 timestep_text (`torch.long` or `float` or `int`):
192 Current denoising step for the label.
193 timestep_img (`torch.long` or `float` or `int`):
194 Current denoising step for the image.
195 data_type: (`torch.int` or `float` or `int`, *optional*, defaults to `1`):
196 Only used in UniDiffuser-v1-style models. Can be either `1`, to use weights trained on nonpublic data,
197 or `0` otherwise.
198 encoder_hidden_states ( `torch.LongTensor` of shape `(batch size, encoder_hidden_states dim)`, *optional*):
199 Conditional embeddings for cross attention layer. If not given, cross-attention defaults to
200 self-attention.
201 cross_attention_kwargs (*optional*):
202 Keyword arguments to supply to the cross attention layers, if used.
203
204
205 Returns:
206 `tuple`: Returns relevant parts of the model's noise prediction: the first element of the tuple is tbe VAE
207 image embedding, the second element is the CLIP image embedding, and the third element is label embedding.
208 """
209 batch_size = image_latents.shape[0]
210
211 # 1. Input
212 # 1.1. Map inputs to shape (B, N, inner_dim)
213 text_hidden_states = self.text_in(self.pre_text(prompt_embeds))
214 vae_hidden_states = self.vae_img_in(image_latents)
215 clip_hidden_states = self.clip_img_in(image_embeds)
216 label_hidden_states = self.vae_label_in(label_latents)
217
218 num_text_tokens, num_img_tokens = text_hidden_states.size(1), vae_hidden_states.size(1)
219
220 # 1.2. Encode image timesteps to single token (B, 1, inner_dim)
221 if not torch.is_tensor(timestep_img):
222 timestep_img = torch.tensor([timestep_img], dtype=torch.long, device=vae_hidden_states.device)
223
224 # broadcast to batch dimension in a way that's compatible with ONNX/Core ML
225 timestep_img = timestep_img * torch.ones(batch_size, dtype=timestep_img.dtype, device=timestep_img.device)
226

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected