-
Notifications
You must be signed in to change notification settings - Fork 272
Expose flex_attention kernel options in DFlash and Domino training #586
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -44,6 +44,7 @@ def __init__( | |||||||||||||||||||||
| num_anchors: int = 512, | ||||||||||||||||||||||
| loss_decay_gamma: Optional[float] = None, | ||||||||||||||||||||||
| shift_label: bool = False, | ||||||||||||||||||||||
| flex_kernel_options: Optional[Dict] = None, | ||||||||||||||||||||||
| ): | ||||||||||||||||||||||
| super().__init__() | ||||||||||||||||||||||
| self.draft_model = draft_model | ||||||||||||||||||||||
|
|
@@ -55,6 +56,7 @@ def __init__( | |||||||||||||||||||||
| self.num_anchors = num_anchors | ||||||||||||||||||||||
| self.loss_decay_gamma = loss_decay_gamma | ||||||||||||||||||||||
| self.shift_label = shift_label | ||||||||||||||||||||||
| self.flex_kernel_options = flex_kernel_options | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| self._cached_block_mask: Optional[BlockMask] = None | ||||||||||||||||||||||
| self._cached_seq_len: Optional[int] = None | ||||||||||||||||||||||
|
|
@@ -332,11 +334,19 @@ def forward( | |||||||||||||||||||||
| device=device, | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| draft_forward_kwargs = {} | ||||||||||||||||||||||
| if ( | ||||||||||||||||||||||
| self.attention_backend == "flex_attention" | ||||||||||||||||||||||
| and self.flex_kernel_options is not None | ||||||||||||||||||||||
| ): | ||||||||||||||||||||||
| draft_forward_kwargs["kernel_options"] = self.flex_kernel_options | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| output_hidden = self.draft_model( | ||||||||||||||||||||||
| position_ids=full_position_ids, | ||||||||||||||||||||||
| noise_embedding=noise_embedding, | ||||||||||||||||||||||
| target_hidden=hidden_states, | ||||||||||||||||||||||
| attention_mask=dflash_attn_mask, | ||||||||||||||||||||||
| **draft_forward_kwargs, | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
Comment on lines
346
to
350
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # --- Labels --- | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing
kernel_optionsdirectly toself.draft_modelwill cause aTypeErrorwhen using other attention backends likesdpaoreager(which are valid choices in the CLI), because their underlying attention functions do not acceptkernel_optionsas a parameter. To prevent this, we should only passkernel_optionswhen the attention backend is set toflex_attentionandflex_kernel_optionsis provided.