Skip to content

Commit

Permalink
densify after optimizer step. fixes #426 (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-goel authored Sep 30, 2024
1 parent bbc9e98 commit 22540f7
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions examples/simple_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,27 +724,6 @@ def train(self):
data, f"{self.ckpt_dir}/ckpt_{step}_rank{self.world_rank}.pt"
)

if isinstance(self.cfg.strategy, DefaultStrategy):
self.cfg.strategy.step_post_backward(
params=self.splats,
optimizers=self.optimizers,
state=self.strategy_state,
step=step,
info=info,
packed=cfg.packed,
)
elif isinstance(self.cfg.strategy, MCMCStrategy):
self.cfg.strategy.step_post_backward(
params=self.splats,
optimizers=self.optimizers,
state=self.strategy_state,
step=step,
info=info,
lr=schedulers[0].get_last_lr()[0],
)
else:
assert_never(self.cfg.strategy)

# Turn Gradients into Sparse Tensor before running optimizer
if cfg.sparse_grad:
assert cfg.packed, "Sparse gradients only work with packed mode."
Expand Down Expand Up @@ -776,6 +755,28 @@ def train(self):
for scheduler in schedulers:
scheduler.step()

# Run post-backward steps after backward and optimizer
if isinstance(self.cfg.strategy, DefaultStrategy):
self.cfg.strategy.step_post_backward(
params=self.splats,
optimizers=self.optimizers,
state=self.strategy_state,
step=step,
info=info,
packed=cfg.packed,
)
elif isinstance(self.cfg.strategy, MCMCStrategy):
self.cfg.strategy.step_post_backward(
params=self.splats,
optimizers=self.optimizers,
state=self.strategy_state,
step=step,
info=info,
lr=schedulers[0].get_last_lr()[0],
)
else:
assert_never(self.cfg.strategy)

# eval the full set
if step in [i - 1 for i in cfg.eval_steps]:
self.eval(step)
Expand Down

0 comments on commit 22540f7

Please sign in to comment.