@@ -1517,8 +1517,8 @@ def _replay():
15171517 "No mini_batch_length is specified for off-policy training"
15181518 )
15191519 experience , batch_info = self ._replay_buffer .get_batch (
1520- batch_size = (mini_batch_size *
1521- config .num_updates_per_train_iter ),
1520+ batch_size = int (mini_batch_size *
1521+ config .num_updates_per_train_iter ),
15221522 batch_length = config .mini_batch_length )
15231523 num_updates = 1
15241524 return experience , batch_info , num_updates , mini_batch_size
@@ -1562,8 +1562,8 @@ def _replay():
15621562
15631563 with record_time ("time/offline_replay" ):
15641564 offline_experience , offline_batch_info = self ._offline_replay_buffer .get_batch (
1565- batch_size = (mini_batch_size *
1566- config .num_updates_per_train_iter ),
1565+ batch_size = int (mini_batch_size *
1566+ config .num_updates_per_train_iter ),
15671567 batch_length = config .mini_batch_length )
15681568 # train hybrid
15691569 with record_time ("time/offline_train" ):
@@ -1641,14 +1641,26 @@ def _train_experience(self,
16411641 torch .cuda .empty_cache ()
16421642
16431643 indices = None
1644+ # In the case where ``num_updates<1``, we will skip some mini-batches (only
1645+ # applicable if ``mini_batch_size<batch_size``).
1646+ training_fraction = min (1 , num_updates )
1647+ training_every_n_batches = int (1. / training_fraction )
1648+ num_updates = int (max (1 , np .ceil (num_updates )))
1649+ batches = 0
16441650 for u in range (num_updates ):
16451651 if mini_batch_size < batch_size :
16461652 indices = torch .randperm (batch_size ,
16471653 device = experience .step_type .device )
16481654 for b in range (0 , batch_size , mini_batch_size ):
1655+ if (b % (training_every_n_batches * mini_batch_size )) != 0 :
1656+ continue
16491657
1650- is_last_mini_batch = (u == num_updates - 1
1651- and b + mini_batch_size >= batch_size )
1658+ batches += 1
1659+
1660+ is_last_mini_batch = (
1661+ u == num_updates - 1
1662+ and b + mini_batch_size * training_every_n_batches
1663+ >= batch_size )
16521664 do_summary = alf .summary .should_record_summaries () and (
16531665 is_last_mini_batch or update_counter_every_mini_batch )
16541666
@@ -1674,7 +1686,7 @@ def _train_experience(self,
16741686 # These are no longer used, release them to reduce memory usage.
16751687 del exp , train_info , loss_info , params
16761688
1677- train_steps = batch_size * mini_batch_length * num_updates
1689+ train_steps = mini_batch_length * batches * mini_batch_size
16781690 return train_steps
16791691
16801692 def _prepare_experience_data (self ,
0 commit comments