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

[WIP] Implements Roberta Model #679

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

JulienDarve
Copy link

No description provided.

Copy link
Member

@dlwh dlwh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't check correctness. just some style/organization thoughts

distance_embedding = None
position_embedding_type = config.position_embedding_type

if position_embedding_type == "relative_key" or position_embedding_type == "relative_key_query":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise if it's not recognized

key = None
) -> Tuple[NamedArray]:

query_layer = self.transpose_for_scores(self.q_proj(hidden_states))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in theory you shouldn't need this transpose_for_scores

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it for compatibility with huggingface. I noticed that the llama code has the linear layer output it directly in the correct shape, but I didnt want to deal with communicating that in the state_dict functions. Do you want me to change it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameters are best declared in the same order as they are in HF (though that can be worked around) but intermediate values like query_layer can be in any order really. Haliax will automatically transpose things as needed.


attention_scores /= jnp.sqrt(self.HeadSize.size)

if attention_mask is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

masks in Levanter are traditionally binary, which means you need to use something like hax.where(attention_mask, attention_scores, -1E9)

src/levanter/models/roberta.py Show resolved Hide resolved
src/levanter/models/roberta.py Outdated Show resolved Hide resolved
src/levanter/models/roberta.py Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm before merge

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. Do you want me to add it somewhere else in levanter or just keep it to myself?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just move it into examples/roberta/ or something. Ideally it was be proper unit tests

return q_embed, k_embed


def llama_rotary_pos_emb(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll want to delete this i think? (if you end up needing it, just import from llama.py)

src/levanter/models/roberta.py Outdated Show resolved Hide resolved
src/levanter/models/roberta.py Outdated Show resolved Hide resolved
@dlwh
Copy link
Member

dlwh commented Jul 31, 2024

I should add: looking good! I know this ended up being a big lift and I appreciate you all taking it on!

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

Successfully merging this pull request may close these issues.

3 participants