Repository navigation
[rl] Add varlen attention for trainer. - #2649
Conversation
tianyu-l
left a comment
There was a problem hiding this comment.
I would propose making varlen the default and the only supported attention backend under RL folder.
- generator is using varlen only. In order to get batch invariance, we can't rely on sdpa.
- although today we have one training sample per batch, eventually I think we should do packing and varlen is the only option, before flex is supported for inference. Related comment #2568 (comment)
73ed0aa to
ee0b3fc
Compare
071bb5c to
6478680
Compare
6478680 to
1246e6d
Compare
acisseJZhong
left a comment
There was a problem hiding this comment.
TODOs: (can we create tasks for them in case we forget)
- unify mask creation logic for RL
- Support input batching for bz>1 #2674
- Support flex attention backend
| """Build VarlenMetadata for all sequences in a batch.""" | ||
| cu_seqs = torch.cumsum( | ||
| torch.tensor( | ||
| [0] + [token_ids.shape[0] for token_ids, _, _ in input_sequences], |
There was a problem hiding this comment.
curious why do we add 0 in between?
There was a problem hiding this comment.
I think this is coming from varlen kernel's requirement. We always go from 0 as the index start.
|
@acisseJZhong Created 2 issues for tracking the followups: |
| token_lps = compute_token_log_probs( | ||
| model, | ||
| [ | ||
| build_full_sequence(prompt_toks, gen_toks, device), |
There was a problem hiding this comment.
Can we remove this helper function? seems it's only used here and it's very short. The name is a little bit confusing
There was a problem hiding this comment.
agree naming is confusing, this function is used in multiple places tho. And we should probably put in some data utils.
There was a problem hiding this comment.
This function is
- only used in
compute_token_log_probs - short
so agreed we can just directly expand the function content there.
| full_sequence, dtype=torch.long, device=device | ||
| ).unsqueeze(0) | ||
| # TODO Support input batching and expand this to batched inputs. | ||
| assert len(input_sequences) == 1, "batch size > 1 not supported yet" |
There was a problem hiding this comment.
Same, we can remove the check and remove the "batch" idea for now, you can leave a sentence in compute_token_log_probs's docstring to say this function accept one sequence for now.
1246e6d to
47a4b03
Compare
tianyu-l
left a comment
There was a problem hiding this comment.
please address remaining comments before merge
| """ | ||
|
|
||
| # TODO Also support flex attention backend later. | ||
| assert ( |
| token_lps = compute_token_log_probs( | ||
| model, | ||
| [ | ||
| build_full_sequence(prompt_toks, gen_toks, device), |
There was a problem hiding this comment.
This function is
- only used in
compute_token_log_probs - short
so agreed we can just directly expand the function content there.
Summary: We previously added varlen attention kernel for generator(vllm) by registering a CUSTOM backend and using it in Generator Config. In this PR, we added a new model config with attention_backend set to "varlen". In the test_attn_numerics.py we are now testing against Qwen variant "0.6B_varlen" instead of "0.6B" now, which means the generator and trainer should both use varlen kernel now. Test Plan: torchrun --nproc_per_node=2 torchtitan/experiments/rl/tests/test_attn_numerics.py Reviewers: Subscribers: Tasks: Tags:
47a4b03 to
21b5945
Compare
Lucaskabela
left a comment
There was a problem hiding this comment.
Thanks @zhxchen17 this LGTM :)
Summary: We previously added varlen attention kernel for generator(vllm) by registering a CUSTOM backend and using it in Generator Config. In this PR, we added a new model config with attention_backend set to "varlen". In the test_attn_numerics.py we are now testing against Qwen variant "0.6B_varlen" instead of "0.6B" now, which means the generator and trainer should both use varlen kernel now. Test Plan: torchrun --nproc_per_node=2 torchtitan/experiments/rl/tests/test_attn_numerics.py Reviewers: Subscribers: Tasks: Tags:
Summary: We previously added varlen attention kernel for generator(vllm) by registering a CUSTOM backend and using it in Generator Config. In this PR, we added a new model config with attention_backend set to "varlen". In the test_attn_numerics.py we are now testing against Qwen variant "0.6B_varlen" instead of "0.6B" now, which means the generator and trainer should both use varlen kernel now. Test Plan: torchrun --nproc_per_node=2 torchtitan/experiments/rl/tests/test_attn_numerics.py Reviewers: Subscribers: Tasks: Tags:
Summary: We previously added varlen attention kernel for generator(vllm) by registering a CUSTOM backend and using it in Generator Config. In this PR, we added a new model config with attention_backend set to "varlen". In the test_attn_numerics.py we are now testing against Qwen variant "0.6B_varlen" instead of "0.6B" now, which means the generator and trainer should both use varlen kernel now. Test Plan: torchrun --nproc_per_node=2 torchtitan/experiments/rl/tests/test_attn_numerics.py Reviewers: Subscribers: Tasks: Tags:
Summary: We previously added varlen attention kernel for generator(vllm) by registering a CUSTOM backend and using it in Generator Config. In this PR, we added a new model config with attention_backend set to "varlen". In the test_attn_numerics.py we are now testing against Qwen variant "0.6B_varlen" instead of "0.6B" now, which means the generator and trainer should both use varlen kernel now. Test Plan: torchrun --nproc_per_node=2 torchtitan/experiments/rl/tests/test_attn_numerics.py Reviewers: Subscribers: Tasks: Tags:
Summary:
We previously added varlen attention kernel for generator(vllm) by registering
a CUSTOM backend and using it in Generator Config. In this PR, we added a new
model config with attention_backend set to "varlen".
In the test_attn_numerics.py we are now testing against Qwen variant "0.6B_varlen"
instead of "0.6B" now, which means the generator and trainer should both use varlen
kernel now.
Test Plan:
torchrun --nproc_per_node=2 torchtitan/experiments/rl/tests/test_attn_numerics.py
Reviewers:
Subscribers:
Tasks:
Tags: