Skip to content
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

use correct autoencoder class for different model exports (#1245) #1246

Merged
merged 1 commit into from
Dec 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions helpers/training/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,16 +469,17 @@ def init_vae(self, move_to_accelerator: bool = True):
from diffusers import AutoencoderDC as AutoencoderClass
else:
from diffusers import AutoencoderKL as AutoencoderClass
self.vae_cls = AutoencoderClass

with ContextManagers(deepspeed_zero_init_disabled_context_manager()):
try:
self.vae = AutoencoderClass.from_pretrained(**self.config.vae_kwargs)
self.vae = self.vae_cls.from_pretrained(**self.config.vae_kwargs)
except:
logger.warning(
"Couldn't load VAE with default path. Trying without a subfolder.."
)
self.config.vae_kwargs["subfolder"] = None
self.vae = AutoencoderClass.from_pretrained(**self.config.vae_kwargs)
self.vae = self.vae_cls.from_pretrained(**self.config.vae_kwargs)
if (
self.vae is not None
and self.config.vae_enable_tiling
Expand Down Expand Up @@ -3233,7 +3234,7 @@ def train(self):
tokenizer_3=self.tokenizer_3,
vae=self.vae
or (
AutoencoderKL.from_pretrained(
self.vae_cls.from_pretrained(
self.config.vae_path,
subfolder=(
"vae"
Expand Down Expand Up @@ -3305,7 +3306,7 @@ def train(self):
tokenizer=self.tokenizer_1,
vae=self.vae
or (
AutoencoderKL.from_pretrained(
self.vae_cls.from_pretrained(
self.config.vae_path,
subfolder=(
"vae"
Expand Down Expand Up @@ -3339,7 +3340,7 @@ def train(self):
tokenizer=self.tokenizer_1,
vae=self.vae
or (
AutoencoderKL.from_pretrained(
self.vae_cls.from_pretrained(
self.config.vae_path,
subfolder=(
"vae"
Expand Down Expand Up @@ -3408,7 +3409,7 @@ def train(self):
tokenizer=self.tokenizer_1,
tokenizer_2=self.tokenizer_2,
vae=StateTracker.get_vae()
or AutoencoderKL.from_pretrained(
or self.vae_cls.from_pretrained(
self.config.vae_path,
subfolder=(
"vae"
Expand Down
Loading