-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Address ernie-image review findings #13577 #13663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
6e61370
2b297bf
1176735
26d8bc0
cf3f6b3
3033a54
0b4934e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |||||||||
|
|
||||||||||
| import torch | ||||||||||
| from PIL import Image | ||||||||||
| from transformers import AutoModel, AutoModelForCausalLM, AutoTokenizer | ||||||||||
| from transformers import AutoTokenizer, Ministral3ForCausalLM, Mistral3Model | ||||||||||
|
|
||||||||||
| from ...models import AutoencoderKLFlux2 | ||||||||||
| from ...models.transformers import ErnieImageTransformer2DModel | ||||||||||
|
|
@@ -51,10 +51,10 @@ def __init__( | |||||||||
| self, | ||||||||||
| transformer: ErnieImageTransformer2DModel, | ||||||||||
| vae: AutoencoderKLFlux2, | ||||||||||
| text_encoder: AutoModel, | ||||||||||
| text_encoder: Mistral3Model, | ||||||||||
| tokenizer: AutoTokenizer, | ||||||||||
| scheduler: FlowMatchEulerDiscreteScheduler, | ||||||||||
| pe: Optional[AutoModelForCausalLM] = None, | ||||||||||
| pe: Optional[Ministral3ForCausalLM] = None, | ||||||||||
| pe_tokenizer: Optional[AutoTokenizer] = None, | ||||||||||
| ): | ||||||||||
| super().__init__() | ||||||||||
|
|
@@ -361,26 +361,26 @@ def __call__( | |||||||||
| progress_bar.update() | ||||||||||
|
|
||||||||||
| if output_type == "latent": | ||||||||||
| return latents | ||||||||||
|
|
||||||||||
| # Decode latents to images | ||||||||||
| # Unnormalize latents using VAE's BN stats | ||||||||||
| bn_mean = self.vae.bn.running_mean.view(1, -1, 1, 1).to(device) | ||||||||||
| bn_std = torch.sqrt(self.vae.bn.running_var.view(1, -1, 1, 1) + 1e-5).to(device) | ||||||||||
| latents = latents * bn_std + bn_mean | ||||||||||
| images = latents | ||||||||||
| else: | ||||||||||
| # Decode latents to images | ||||||||||
| # Unnormalize latents using VAE's BN stats | ||||||||||
| bn_mean = self.vae.bn.running_mean.view(1, -1, 1, 1).to(device) | ||||||||||
| bn_std = torch.sqrt(self.vae.bn.running_var.view(1, -1, 1, 1) + 1e-5).to(device) | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dtype casting to be safe and for consistency with modular
Suggested change
There could be a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||||||||||
| latents = latents * bn_std + bn_mean | ||||||||||
|
|
||||||||||
| # Unpatchify | ||||||||||
| latents = self._unpatchify_latents(latents) | ||||||||||
| # Unpatchify | ||||||||||
| latents = self._unpatchify_latents(latents) | ||||||||||
|
|
||||||||||
| # Decode | ||||||||||
| images = self.vae.decode(latents, return_dict=False)[0] | ||||||||||
| # Decode | ||||||||||
| images = self.vae.decode(latents, return_dict=False)[0] | ||||||||||
|
|
||||||||||
| # Post-process | ||||||||||
| images = (images.clamp(-1, 1) + 1) / 2 | ||||||||||
| images = images.cpu().permute(0, 2, 3, 1).float().numpy() | ||||||||||
| # Post-process | ||||||||||
| images = (images.clamp(-1, 1) + 1) / 2 | ||||||||||
| images = images.cpu().permute(0, 2, 3, 1).float().numpy() | ||||||||||
|
|
||||||||||
| if output_type == "pil": | ||||||||||
| images = [Image.fromarray((img * 255).astype("uint8")) for img in images] | ||||||||||
| if output_type == "pil": | ||||||||||
| images = [Image.fromarray((img * 255).astype("uint8")) for img in images] | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switched both standard and modular to |
||||||||||
|
|
||||||||||
| # Offload all models | ||||||||||
| self.maybe_free_model_hooks() | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we also take the opportunity to change the auto classes for the real classes, it gets confusing for some users that pass the text encoder e.g. quantization and also kind of annoying to get the warning all the time.