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

Added pajama data generation #1

Merged
merged 7 commits into from
Jan 12, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/datautils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ def set_seed(seed: Optional[int]):
torch.random.manual_seed(seed)


def get_red_pajama(nsamples, seqlen, tokenizer, eval_mode=False):
loaded_data = load_dataset("togethercomputer/RedPajama-Data-1T-Sample", split="test" if eval_mode else "train")
tokenizer.bos_token_id = 1
tokenizer.eos_token_id = 2
loader = []
for _ in range(nsamples):
while True:
i = random.randint(0, len(loaded_data) - 1)
enc = tokenizer(loaded_data[i]["text"], return_tensors="pt")
if enc.input_ids.shape[1] > seqlen:
break
i = random.randint(0, enc.input_ids.shape[1] - seqlen - 1)
j = i + seqlen
inp = enc.input_ids[:, i:j]
assert inp.shape[1] == seqlen
loader.append(inp)

return loader, None


def get_wikitext2(nsamples, seqlen, tokenizer, eval_mode=False):
if not eval_mode:
traindata = load_dataset("wikitext", "wikitext-2-raw-v1", split="train")
Expand Down Expand Up @@ -186,9 +206,8 @@ def get_loaders(name, nsamples=128, seed=0, seqlen=2048, eval_mode=False, model_
set_seed(seed)

# for pre-tokenized datasets
if name.lower() == "pajama":
data = torch.load(f"./data/red_pajama_n=1024_{seqlen}_context_length.pth")[:nsamples]
elif name.lower() == "refinedweb":

if name.lower() == "refinedweb":
data = torch.load("./data/refined_web_n=128.pth")[:nsamples]
Copy link
Collaborator

@justheuristic justheuristic Jan 12, 2024

Choose a reason for hiding this comment

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

I'd recommend that we remove refinedweb since we don't even know what it was tokenized with. If user really wants that dataset, they can directly set DATASET="./data/refined_web_n=128.pt" from CLI

Copy link
Owner Author

Choose a reason for hiding this comment

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

will do

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really intend to work with Falcon models?

Copy link
Collaborator

Choose a reason for hiding this comment

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

we may eventually need 'em, but the user can still run falcon via DATASET=./data/... as long as they know what they're doing.

My concern is that someone might accidentally try training llama/mistral on main.py "refinedweb" without realizing it's model-specific

elif name.lower() == "none":
print("Not loading any dataset. (OK if you use no compression or methods like RTN.)")
Expand Down Expand Up @@ -220,6 +239,8 @@ def get_loaders(name, nsamples=128, seed=0, seqlen=2048, eval_mode=False, model_

if name.lower() == "wikitext2":
data = get_wikitext2(nsamples, seqlen, tokenizer, eval_mode=eval_mode)
elif name.lower() == "pajama":
data = get_red_pajama(nsamples, seqlen, tokenizer, eval_mode=eval_mode)
elif name.lower() == "ptb":
data = get_ptb(nsamples, seqlen, tokenizer, eval_mode=eval_mode)
elif name.lower() == "ptb_new":
Expand Down