| 129 | |
| 130 | |
| 131 | class LTXVModelModified(LTXVModel): |
| 132 | |
| 133 | def forward( |
| 134 | self, |
| 135 | x, |
| 136 | timestep, |
| 137 | context, |
| 138 | attention_mask, |
| 139 | frame_rate=25, |
| 140 | transformer_options={}, |
| 141 | keyframe_idxs=None, |
| 142 | **kwargs, |
| 143 | ): |
| 144 | patches_replace = transformer_options.get("patches_replace", {}) |
| 145 | |
| 146 | orig_shape = list(x.shape) |
| 147 | |
| 148 | x, latent_coords = self.patchifier.patchify(x) |
| 149 | pixel_coords = latent_to_pixel_coords( |
| 150 | latent_coords=latent_coords, |
| 151 | scale_factors=self.vae_scale_factors, |
| 152 | causal_fix=self.causal_temporal_positioning, |
| 153 | ) |
| 154 | |
| 155 | if keyframe_idxs is not None: |
| 156 | pixel_coords[:, :, -keyframe_idxs.shape[2] :] = keyframe_idxs |
| 157 | |
| 158 | fractional_coords = pixel_coords.to(torch.float32) |
| 159 | fractional_coords[:, 0] = fractional_coords[:, 0] * (1.0 / frame_rate) |
| 160 | |
| 161 | x = self.patchify_proj(x) |
| 162 | timestep = timestep * 1000.0 |
| 163 | |
| 164 | if attention_mask is not None and not torch.is_floating_point(attention_mask): |
| 165 | attention_mask = (attention_mask - 1).to(x.dtype).reshape( |
| 166 | (attention_mask.shape[0], 1, -1, attention_mask.shape[-1]) |
| 167 | ) * torch.finfo(x.dtype).max |
| 168 | |
| 169 | pe = self._precompute_freqs_cis( |
| 170 | fractional_coords, dim=self.inner_dim, out_dtype=x.dtype |
| 171 | ) |
| 172 | |
| 173 | batch_size = x.shape[0] |
| 174 | timestep, embedded_timestep = self.adaln_single( |
| 175 | timestep.flatten(), |
| 176 | {"resolution": None, "aspect_ratio": None}, |
| 177 | batch_size=batch_size, |
| 178 | hidden_dtype=x.dtype, |
| 179 | ) |
| 180 | # Second dimension is 1 or number of tokens (if timestep_per_token) |
| 181 | timestep = timestep.view(batch_size, -1, timestep.shape[-1]) |
| 182 | embedded_timestep = embedded_timestep.view( |
| 183 | batch_size, -1, embedded_timestep.shape[-1] |
| 184 | ) |
| 185 | |
| 186 | # 2. Blocks |
| 187 | if self.caption_projection is not None: |
| 188 | batch_size = x.shape[0] |
nothing calls this directly
no outgoing calls
no test coverage detected