Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix rwkv libai code step2
  • Loading branch information
CPFLAME committed Aug 26, 2022
commit f135eec96fbdc60f25f7a507ef27176692fa3855
2 changes: 1 addition & 1 deletion libai/engine/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ def run_step(self, get_batch: Callable, input_placement_device: str = "cuda"):
data_time = time.perf_counter() - start

loss_dict = self.model(**data)

losses = sum(loss_dict.values()) / self.grad_acc_steps

losses.backward()
Expand Down Expand Up @@ -337,6 +336,7 @@ def run_step(self, get_batch: Callable, input_placement_device: str = "cuda"):
data = get_batch(
data, input_placement_device, getattr(self.data_loader, "mixup_func", None)
)

data_time = time.perf_counter() - start

# If you want to do something with the losses, you can wrap the model.
Expand Down
2 changes: 2 additions & 0 deletions libai/models/utils/graph_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def __init__(
self.set_grad_scaler(grad_scaler)
elif amp_type == "bf16":
self.config.enable_amp(True, dtype=flow.bfloat16)
else:
raise NotImplementedError

if grad_acc_steps > 1:
self.config.set_gradient_accumulation_steps(grad_acc_steps)
Expand Down