Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use var_len attention in context parallel? #1080

Open
liuzhaowen1218 opened this issue Aug 6, 2024 · 1 comment
Open

How to use var_len attention in context parallel? #1080

liuzhaowen1218 opened this issue Aug 6, 2024 · 1 comment
Assignees

Comments

@liuzhaowen1218
Copy link

I am doing a 128k sequence length SFT task revolving many pad tokens in training tokens which may lead to abnormal loss by irrelevant attention. When not using Context Parallel, this problem can be fixed by customizing cu_seqlens_q and cu_seqlens_kv as parameters sending into flash_attn_varlen_func. How can I get the same result by using Context Parallel?

or attn_mask_type in ["padding", "padding_causal"]

@xrennvidia
Copy link
Collaborator

Hi @liuzhaowen1218

You can refer our TE unit test.

You need to make sure each individual sequence length is divisible by CPx2. If your running does not meeting this requirements, you need to pad a few tokens to each sequence so that their lengths are divisible by CPx2. Then you can split your input across GPUs like this.

Since you may need to do some padding for each sequence, you possibly will have some padded tokens between sequences. Hence you not only need to handle cu_seqlens, you also need to handle cu_seqlens_padded (refer here). Padding between sequences is only supported with FusedAttention, not with FlashAttention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants