@@ -456,9 +456,11 @@ def forward(
456456 gamma = self .gammas .to (r .device ).unsqueeze (- 1 )
457457 d = repeat (batch .dones .float (), f"b l d -> b l 1 { G } d" )
458458 D_emb = self .traj_encoder .emb_dim
459- state_mask = (~ ((batch .rl2s == self .pad_val ).all (- 1 , keepdim = True ))).float ()
460- actor_mask = repeat (state_mask , f"b l 1 -> b l { G } 1" )
461- critic_mask = repeat (state_mask [:, 1 :, ...], f"b l 1 -> b l { C } { G } 1" )
459+ # 1.0 where loss at this index should count, 0.0 where is should be ignored
460+ state_mask = (~ ((batch .rl2s == self .pad_val ).all (- 1 , keepdim = True ))).float ()[:, 1 :, ...]
461+ actor_mask = torch .cat ((state_mask , torch .zeros (B , 1 , 1 , device = d .device )), dim = 1 )
462+ actor_mask = repeat (actor_mask , f"b l 1 -> b l { G } 1" )
463+ critic_mask = repeat (state_mask , f"b l 1 -> b l { C } { G } 1" )
462464
463465 ########################
464466 ## Sequence Embedding ##
@@ -620,7 +622,6 @@ def _policy_stats(self, mask, a_dist) -> dict:
620622 masked_avg = (
621623 lambda x_ , dim : (mask [..., dim , :] * x_ [..., dim , :]).sum ().detach () / sum_
622624 )
623-
624625 if self .discrete :
625626 entropy = a_dist .entropy ().unsqueeze (- 1 )
626627 low_prob = torch .min (a_dist .probs , dim = - 1 , keepdims = True ).values
0 commit comments