attention_mask seems wrong in fdsp when use_remove_padding is False
System Info
The problematic line is still on main.
Information
- [ ] The official example scripts
- [x] My own modified scripts
Tasks
- [ ] An officially supported task in the
examplesfolder (such as GLUE/SQuAD, ...) - [x] My own task or dataset (give details below)
Reproduction
Set use_remove_padding: False and strategy to fsdp2, and run GRPO.
The pg/clipfrac and ppo_kl are unusually high (more than 40% for the clipfrac in my case), even before any optimizer step, so the rollout and training policy should be similar up to some noise.
I think the problem comes from this line.
The attention mask is computed from loss_mask, which has the same shape as the response, but is used as an attention mask on the entire prompt+response.
Expected behavior
I think that something like this would make more sense:
positions = torch.arange(int(max_seq_len), device=input_ids.device).unsqueeze(0)
attention_mask = (positions < seq_len_effective.to(input_ids.device).unsqueeze(1)).to(torch.int32)
Or maybe having the attention_mask as None, similar to when use_remove_padding is True ?
Btw, I think that those two lines are also broken, because downstream (in ppo_loss, no_padding_2_padding), a flat tensor of shape (total_nnz,) is expected instead of (bsz, response_length). Maybe use_remove_padding: False is not maintained ?
Yeah both look like real bugs, loss_mask being response-only but used as the full sequence attention mask explains the clipfrac/KL blowup. The shape mismatch at 1156 also tracks. I think this path is just untested.
Happy to take a stab at a fix if you haven't already.
I won’t have time to work on it this week, so if you can please go for it ! Thanks