fix conflicts
This commit is contained in:
commit
571608b4dd
@ -15,7 +15,7 @@ class Config:
|
|||||||
height: int = 1024,
|
height: int = 1024,
|
||||||
guidance: float = 4.0,
|
guidance: float = 4.0,
|
||||||
):
|
):
|
||||||
if width %16 != 0 or height % 16 != 0:
|
if width % 16 != 0 or height % 16 != 0:
|
||||||
log.warning("Width and height should be multiples of 16. Rounding down.")
|
log.warning("Width and height should be multiples of 16. Rounding down.")
|
||||||
self.width = 16 * (height // 16)
|
self.width = 16 * (height // 16)
|
||||||
self.height = 16 * (width // 16)
|
self.height = 16 * (width // 16)
|
||||||
|
|||||||
@ -56,12 +56,12 @@ class Flux1:
|
|||||||
|
|
||||||
mx.eval(latents)
|
mx.eval(latents)
|
||||||
|
|
||||||
latents = Flux1._unpack_latents(latents, config.width, config.height)
|
latents = Flux1._unpack_latents(latents, config.height, config.width)
|
||||||
decoded = self.vae.decode(latents)
|
decoded = self.vae.decode(latents)
|
||||||
return ImageUtil.to_image(decoded)
|
return ImageUtil.to_image(decoded)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _unpack_latents(latents, width, height):
|
def _unpack_latents(latents: mx.array, width: int, height: int) -> mx.array:
|
||||||
latents = mx.reshape(latents, (1, height//16, width//16, 16, 2, 2))
|
latents = mx.reshape(latents, (1, height//16, width//16, 16, 2, 2))
|
||||||
latents = mx.transpose(latents, (0, 3, 1, 4, 2, 5))
|
latents = mx.transpose(latents, (0, 3, 1, 4, 2, 5))
|
||||||
latents = mx.reshape(latents, (1, 16, height//16 *2, width//16 * 2))
|
latents = mx.reshape(latents, (1, 16, height//16 *2, width//16 * 2))
|
||||||
|
|||||||
@ -5,7 +5,7 @@ class LatentCreator:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create(height: int, width: int, seed: int) -> (mx.array, mx.array):
|
def create(height: int, width: int, seed: int) -> (mx.array, mx.array):
|
||||||
r_h = height // 16
|
latent_height = height // 16
|
||||||
r_w = width // 16
|
latent_width = width // 16
|
||||||
latents = mx.random.normal(shape=[1, r_h * r_w, 64], key=mx.random.key(seed))
|
latents = mx.random.normal(shape=[1, latent_height * latent_width, 64], key=mx.random.key(seed))
|
||||||
return latents
|
return latents
|
||||||
|
|||||||
@ -41,7 +41,7 @@ class Transformer(nn.Module):
|
|||||||
text_embeddings = self.time_text_embed.forward(time_step, pooled_prompt_embeds, guidance)
|
text_embeddings = self.time_text_embed.forward(time_step, pooled_prompt_embeds, guidance)
|
||||||
encoder_hidden_states = self.context_embedder(prompt_embeds)
|
encoder_hidden_states = self.context_embedder(prompt_embeds)
|
||||||
txt_ids = Transformer._prepare_text_ids(seq_len = prompt_embeds.shape[1])
|
txt_ids = Transformer._prepare_text_ids(seq_len = prompt_embeds.shape[1])
|
||||||
img_ids = Transformer._prepare_latent_image_ids(config.width, config.height)
|
img_ids = Transformer._prepare_latent_image_ids(config.height, config.width)
|
||||||
ids = mx.concatenate((txt_ids, img_ids), axis=1)
|
ids = mx.concatenate((txt_ids, img_ids), axis=1)
|
||||||
image_rotary_emb = self.pos_embed.forward(ids)
|
image_rotary_emb = self.pos_embed.forward(ids)
|
||||||
|
|
||||||
@ -69,14 +69,14 @@ class Transformer(nn.Module):
|
|||||||
return noise
|
return noise
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _prepare_latent_image_ids(width, height) -> mx.array:
|
def _prepare_latent_image_ids(width: int, height: int) -> mx.array:
|
||||||
r_h = height // 16
|
latent_height = height // 16
|
||||||
r_w = width // 16
|
latent_width = width // 16
|
||||||
latent_image_ids = mx.zeros((r_h, r_w, 3))
|
latent_image_ids = mx.zeros((latent_height, latent_width, 3))
|
||||||
latent_image_ids = latent_image_ids.at[:, :, 1].add(mx.arange(0, r_h)[:, None])
|
latent_image_ids = latent_image_ids.at[:, :, 1].add(mx.arange(0, latent_height)[:, None])
|
||||||
latent_image_ids = latent_image_ids.at[:, :, 2].add(mx.arange(0, r_w)[None, :])
|
latent_image_ids = latent_image_ids.at[:, :, 2].add(mx.arange(0, latent_width)[None, :])
|
||||||
latent_image_ids = mx.repeat(latent_image_ids[None, :], 1, axis=0)
|
latent_image_ids = mx.repeat(latent_image_ids[None, :], 1, axis=0)
|
||||||
latent_image_ids = mx.reshape(latent_image_ids, (1, r_h * r_w, 3))
|
latent_image_ids = mx.reshape(latent_image_ids, (1, latent_height * latent_width, 3))
|
||||||
return latent_image_ids
|
return latent_image_ids
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user