Skip to content

Commit

Permalink
Add debug points
Browse files Browse the repository at this point in the history
  • Loading branch information
pomonam committed Jun 29, 2024
1 parent 7fad0d7 commit 74ad18e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/dailymail/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DailyMail & T5 Example

This directory contains scripts for fine-tuning RoBERTa computing influence scores on the SWAG dataset. The pipeline is motivated from [this HuggingFace Example](https://github.com/huggingface/transformers/tree/main/examples/pytorch/multiple-choice) demonstrates how to define `post_process_per_sample_gradient`.
This directory contains scripts for fine-tuning T5 and computing influence scores on the DailyMail dataset. The pipeline is motivated from [this HuggingFace Example](https://github.com/huggingface/transformers/tree/main/examples/pytorch/summarization).
To begin, install the necessary packages:

```bash
Expand Down
1 change: 1 addition & 0 deletions examples/dailymail/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"xglue": ("news_body", "news_title"),
"xsum": ("document", "summary"),
"wiki_summary": ("article", "highlights"),
"multi_news": ("document", "summary"),
}


Expand Down
4 changes: 4 additions & 0 deletions examples/dailymail/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
sentencepiece!=0.1.92
nltk
py7zr
rouge-score
transformers
evaluate
datasets
18 changes: 6 additions & 12 deletions examples/dailymail/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np
import torch
import torch.nn.functional as F
from accelerate.utils import set_seed
from accelerate.utils import set_seed, send_to_device
from filelock import FileLock
from torch import nn
from torch.nn import CrossEntropyLoss
Expand All @@ -30,7 +30,7 @@


DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")

print(DEVICE)

def parse_args():
parser = argparse.ArgumentParser(description="Train seq2seq models on DailyMail dataset.")
Expand Down Expand Up @@ -115,18 +115,12 @@ def train(
model.train()
for epoch in range(num_train_epochs):
total_loss = 0.0
print("epoch start")
for batch in train_dataloader:
print("done")
optimizer.zero_grad(set_to_none=True)
logits = model(
input_ids=batch["input_ids"].to(device=DEVICE),
attention_mask=batch["attention_mask"].to(device=DEVICE),
decoder_input_ids=batch["decoder_input_ids"].to(device=DEVICE),
).logits
loss = F.cross_entropy(
logits.view(-1, logits.size(-1)),
batch["labels"].view(-1).to(device=DEVICE),
ignore_index=-100,
)
batch = send_to_device(batch, device=DEVICE)
loss = model(**batch).loss
loss.backward()
optimizer.step()
total_loss += loss.detach().float()
Expand Down
2 changes: 1 addition & 1 deletion examples/swag/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SWAG & RoBERTa Example

This directory contains scripts for fine-tuning RoBERTa computing influence scores on the SWAG dataset. The pipeline is motivated from [this HuggingFace Example](https://github.com/huggingface/transformers/tree/main/examples/pytorch/multiple-choice) demonstrates how to define `post_process_per_sample_gradient`.
This directory contains scripts for fine-tuning RoBERTa and computing influence scores on the SWAG dataset. The pipeline is motivated from [this HuggingFace Example](https://github.com/huggingface/transformers/tree/main/examples/pytorch/multiple-choice) demonstrates how to define `post_process_per_sample_gradient`.
To begin, install the necessary packages:

```bash
Expand Down

0 comments on commit 74ad18e

Please sign in to comment.