manbeast3b commited on
Commit
cc73f39
·
verified ·
1 Parent(s): 34269c9

Update src/pipeline.py

Browse files
Files changed (1) hide show
  1. src/pipeline.py +11 -27
src/pipeline.py CHANGED
@@ -19,7 +19,7 @@ from transformers import (
19
  )
20
  from PIL import Image as img
21
  from pipelines.models import TextToImageRequest
22
- from model import Encoder, Decoder
23
 
24
  # Environment configuration
25
  os.environ['PYTORCH_CUDA_ALLOC_CONF'] = "expandable_segments:True"
@@ -74,33 +74,17 @@ def load_pipeline():
74
 
75
  # Load VAE with custom encoder/decoder
76
  vae = AutoencoderTiny.from_pretrained("manbeast3b/flux.1-schnell-vae-quant1", torch_dtype=dtype)
77
- vae.encoder = Encoder(16)
78
- vae.decoder = Decoder(16)
79
-
80
- # Load encoder and decoder state dicts
81
- encoder_path = "encoder.pth"
82
- decoder_path = "decoder.pth"
83
-
84
- if encoder_path:
85
- encoder_state_dict = torch.load(encoder_path, map_location="cpu")
86
- filtered_state_dict = {
87
- k.replace('encoder.', ''): v
88
- for k, v in encoder_state_dict.items()
89
- if k.replace('encoder.', '') in vae.encoder.state_dict()
90
- }
91
- vae.encoder.load_state_dict(filtered_state_dict, strict=False)
92
- vae.encoder.to(dtype=dtype)
93
-
94
- if decoder_path:
95
- decoder_state_dict = torch.load(decoder_path, map_location="cpu")
96
- filtered_state_dict = {
97
- k.replace('decoder.', ''): v
98
- for k, v in decoder_state_dict.items()
99
- if k.replace('decoder.', '') in vae.decoder.state_dict()
100
- }
101
- vae.decoder.load_state_dict(filtered_state_dict, strict=False)
102
- vae.decoder.to(dtype=dtype)
103
 
 
 
 
 
 
 
 
 
104
  vae.encoder.requires_grad_(False)
105
  vae.decoder.requires_grad_(False)
106
 
 
19
  )
20
  from PIL import Image as img
21
  from pipelines.models import TextToImageRequest
22
+ from model import E, D
23
 
24
  # Environment configuration
25
  os.environ['PYTORCH_CUDA_ALLOC_CONF'] = "expandable_segments:True"
 
74
 
75
  # Load VAE with custom encoder/decoder
76
  vae = AutoencoderTiny.from_pretrained("manbeast3b/flux.1-schnell-vae-quant1", torch_dtype=dtype)
77
+ vae.encoder = E(16)
78
+ vae.decoder = D(16)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
+ def lsd(p, mod, pfx):
81
+ sd = t.load(p, map_location="cpu", weights_only=True)
82
+ f_sd = {k.strip(pfx): v for k, v in sd.items() if k.strip(pfx) in mod.state_dict() and v.size() == mod.state_dict()[k.strip(pfx)].size()}
83
+ mod.load_state_dict(f_sd, strict=False)
84
+ mod.to(dtype=t.float16)
85
+
86
+ if e_s: lsd("ko.pth", vae.encoder, "encoder.")
87
+ if d_s: lsd("ok.pth", vae.decoder, "decoder.")
88
  vae.encoder.requires_grad_(False)
89
  vae.decoder.requires_grad_(False)
90