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] MLM Training Objective #680

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

Conversation

prady-saligram
Copy link

Introduces train_mlm.py, a new file adapted from train_lm.py, to support masked language modeling with dynamic masking as utilized in RoBERTa. A new class, MaskedLMDataset, has been implemented in text.py to handle dynamic masking. This class is instantiated and utilized within train_mlm.py, preserving all structural and sharding-related comments from the original train_lm.py to maintain clarity and continuity. The integration of MaskedLMDataset with the training script has been verified with appropriate parameters to ensure consistency with existing training workflows.

@@ -64,6 +65,65 @@

DEFAULT_IGNORE_INDEX = -100 # Mirrors pytorch's default ignore index

class MaskedLmDataset(ShardableDataset[LmExample]):
Copy link
Member

Choose a reason for hiding this comment

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

fyi we're gonna do a big refactor on datasets soon, but I'll either handle the refactor or guide you through it)

def _create_mlm_example(tokens, key):
tokens_array = tokens.array

example = LmExample.causal(tokens=tokens, ignore_id=self.ignore_id)
Copy link
Member

Choose a reason for hiding this comment

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

you need a non-causal attention mask for Roberta, and you need to set a loss_mask to be only the masked tokens

Copy link
Member

Choose a reason for hiding this comment

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

you also can't use the current LmExample actually because you need a separate targets field (with the non-masked tokens). With more work you could avoid the need for targets (with just masked tokens), but probably better to add an targets: Optional[NamedArray] to the class (or make your own class)

src/levanter/data/text.py Show resolved Hide resolved
src/levanter/data/text.py Outdated Show resolved Hide resolved
@prady-saligram prady-saligram marked this pull request as draft August 5, 2024 21:50
@prady-saligram prady-saligram changed the title MLM Training Objective [WIP] MLM Training Objective Aug 6, 2024
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.

2 participants