Skip to content
Open
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
7 changes: 4 additions & 3 deletions swirl_dynamics/projects/probabilistic_diffusion/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,18 @@ def loss_fn(
vmapped_mult = jax.vmap(jnp.multiply, in_axes=(0, 0))
noised = batch["x"] + vmapped_mult(noise, sigma)
cond = batch["cond"] if self.cond_shape else None
denoised = self.denoiser.apply(
{"params": params},
denoised, updated_mutables = self.denoiser.apply(
{"params": params, **mutables},
x=noised,
sigma=sigma,
cond=cond,
is_training=True,
mutable=mutables.keys() if mutables else False,
rngs={"dropout": rng3}, # TODO: refactor this.
)
loss = jnp.mean(vmapped_mult(weights, jnp.square(denoised - batch["x"])))
metric = dict(loss=loss)
return loss, (metric, mutables)
return loss, (metric, updated_mutables)

def eval_fn(
self, variables: models.PyTree, batch: models.BatchType, rng: Array
Expand Down
4 changes: 4 additions & 0 deletions swirl_dynamics/projects/probabilistic_diffusion/trainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def inference_fn_from_state_dict(
variables = state.ema_variables
else:
variables = state.model_variables
if state.flax_mutables:
variables = flax.core.FrozenDict(
{**variables, **state.flax_mutables}
)
return models.DenoisingModel.inference_fn(variables, *args, **kwargs)


Expand Down