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

[test][DO NOT MERGE] disable fori_loop #11

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/maxdiffusion/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ def run_inference(unet_state, vae_state, params, rng, config, batch_size, pipeli
vae_decode_p = functools.partial(vae_decode, pipeline=pipeline)

with mesh, nn_partitioning.axis_rules(config.logical_axis_rules):
latents, _, _ = jax.lax.fori_loop(0, config.num_inference_steps,
loop_body_p, (latents, scheduler_state, unet_state))
val = (latents, scheduler_state, unet_state)
for i in range(0, config.num_inference_steps):
val = loop_body_p(i, val)
latents, _, _ = val
image = vae_decode_p(latents, vae_state)
return image

Expand Down
6 changes: 4 additions & 2 deletions src/maxdiffusion/generate_sdxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ def run_inference(unet_state, vae_state, params, rng, config, batch_size, pipeli
vae_decode_p = functools.partial(vae_decode, pipeline=pipeline)

with mesh, nn_partitioning.axis_rules(config.logical_axis_rules):
latents, _, _ = jax.lax.fori_loop(0, config.num_inference_steps,
loop_body_p, (latents, scheduler_state, unet_state))
val = (latents, scheduler_state, unet_state)
for i in range(0, config.num_inference_steps):
val = loop_body_p(i, val)
latents, _, _ = val
image = vae_decode_p(latents, vae_state)
return image

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ def loop_body(step, args):
for i in range(num_inference_steps):
latents, scheduler_state = loop_body(i, (latents, scheduler_state))
else:
latents, _ = jax.lax.fori_loop(0, num_inference_steps, loop_body, (latents, scheduler_state))
val = (latents, scheduler_state)
for i in range(0, num_inference_steps):
val = loop_body(i, val)
latents, _ = val

# scale and decode the image latents with vae
latents = 1 / self.vae.config.scaling_factor * latents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ def loop_body(step, args):
for i in range(num_inference_steps):
latents, scheduler_state = loop_body(i, (latents, scheduler_state))
else:
latents, _ = jax.lax.fori_loop(0, num_inference_steps, loop_body, (latents, scheduler_state))
val = (latents, scheduler_state)
for i in range(0, num_inference_steps):
val = loop_body(i, val)
latents, _ = val

if return_latents:
return latents
Expand Down