-
Notifications
You must be signed in to change notification settings - Fork 49
2D Rope into develop #1540
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: develop
Are you sure you want to change the base?
2D Rope into develop #1540
Conversation
- Add copyright attribution for rotate_half() and apply_rotary_pos_emb() functions - Rename apply_rotary_pos_emb_2d() to rotary_pos_emb_2d() for consistency - Rename config parameter use_2D_rope to rope_2D for better extensibility when supporting different RoPE variants in the future
clessig
left a comment
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.
We can simplify the code if we change the syntax of the forward fct of the attention blocks slightly. This should probably be done consistently for all heads, even those without 2D rope.
| ) | ||
|
|
||
| return iter_start, iter_end | ||
| return iter_start, iter_end |
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.
Can we revert this
| def forward(self, tokens, coords=None, use_reentrant=False): | ||
| for block in self.ae_aggregation_blocks: | ||
| tokens = checkpoint(block, tokens, use_reentrant=use_reentrant) | ||
| if isinstance(block, MultiSelfAttentionHead | MultiSelfAttentionHeadLocal): |
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.
We could avoid the branches if we would follow the approach in the MLP:
| def forward(self, *args): |
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.
Or some compromise with *args and **kwargs
| def forward(self, tokens, coords=None, use_reentrant=False): | ||
| for block in self.ae_global_blocks: | ||
| tokens = checkpoint(block, tokens, use_reentrant=use_reentrant) | ||
| if isinstance(block, MultiSelfAttentionHead | MultiSelfAttentionHeadLocal): |
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.
Same as above: if-statement is not necessary
| for _b_idx, block in enumerate(self.fe_blocks): | ||
| if isinstance(block, torch.nn.modules.normalization.LayerNorm): | ||
| tokens = block(tokens) | ||
| elif isinstance(block, MultiSelfAttentionHead | MultiSelfAttentionHeadLocal): |
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.
Same as above
| ) | ||
| self.pe_global = torch.nn.Parameter(pe, requires_grad=False) | ||
|
|
||
| ### ROPE COORDS ### |
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.
standard comment:
# rope coords
| ks = self.lnorm_k(self.proj_heads_k(x).reshape(s)).to(self.dtype) | ||
| vs = self.proj_heads_v(x).reshape(s).to(self.dtype) | ||
|
|
||
| if coords is not None: |
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.
MultiSelfAttenionHead is a vanilla self attention block. The 2D rope positional encoding makes strong assumption of the structure of the qs and ks. At the very least, we need some documentation on what the option means and when it makes sense. Not sure if there's another good way to ensure proper use of this option (one could have a separate class but then one should make sure there's no code duplication).
Description
This is @csjfwang 's implementation of 2D rope, coming from this orignal PR: #1445
Issue Number
Closes #1445
Closes #1109
Checklist before asking for review
./scripts/actions.sh lint./scripts/actions.sh unit-test./scripts/actions.sh integration-testlaunch-slurm.py --time 60