-
Notifications
You must be signed in to change notification settings - Fork 482
Add T5 model #145
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
Merged
Merged
Add T5 model #145
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
ec00c54
add t5 to trlx
dacb652
add t5 examples for sentiment
56a0a3c
add eval for t5
5feff9f
fix eval
ccfabde
remove old files
2674d24
remove bad files
6e43ea1
remove bad files
59c2cf5
fix incompatible with gpt model, add summarization code base
2c133b0
freeze frozen branch
c9ddfcf
Merge branch 'main' into add_t5
PhungVanDuy 5f38a81
fix evaluation bug t5, add summarization cnn/daily mail example
17be682
update sentiment example
2d1a4dc
stable config sentiment
f9f85ba
add attention mask decoder
500099f
setting worked - flant5 two unfrozen small rollouts
b55a4e8
merge newest code from main
36a74e6
fix head nn, config cnn daily mail, remove sent examples
6baee0b
fix style, change model_arch_type, truncated tokenizer fixed
d2082a7
fix style
d2f6a1d
precommit changes
eaf9c94
fix ppo state values for t5
c03313a
Merge branch 'main' into add_t5
PhungVanDuy 93cf3cc
fix style
8ac399b
remove sentiment example
fefa62b
fix typo
5ae1188
fix ppo for causal models, add save best, seperate rollouts/eval args
ea10837
add ppo sentiment
84f8b7b
fix rewards typo
03cc954
Merge branch 'main' into add_t5
PhungVanDuy 347e314
merging with main
220c8f3
fix style
a0a43f8
add docstring for gen_kwargs_inference, save best
b86e3d4
add gen kwargs support for rollouts sampling
eb0b0cc
Make summarization example self-contained
jon-tow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
train: | ||
seq_length: 612 | ||
epochs: 100 | ||
total_steps: 100000 | ||
batch_size: 12 | ||
|
||
checkpoint_interval: 10000 | ||
eval_interval: 500 | ||
save_best: False | ||
|
||
pipeline: "PromptPipeline" | ||
orchestrator: "PPOOrchestrator" | ||
trainer: "AcceleratePPOTrainer" | ||
|
||
model: | ||
model_path: "google/flan-t5-large" | ||
model_arch_type: "seq2seq" | ||
tokenizer_path: "google/flan-t5-large" | ||
num_layers_unfrozen: 2 | ||
|
||
optimizer: | ||
name: "adamw" | ||
kwargs: | ||
lr: 1.0e-5 | ||
betas: [0.9, 0.999] | ||
eps: 1.0e-8 | ||
weight_decay: 1.0e-6 | ||
|
||
scheduler: | ||
name: "cosine_annealing" | ||
kwargs: | ||
T_max: 10000 | ||
eta_min: 1.0e-6 | ||
|
||
method: | ||
name: "ppoconfig" | ||
num_rollouts: 512 | ||
chunk_size: 12 | ||
ppo_epochs: 4 | ||
init_kl_coef: 0.05 | ||
target: 6 | ||
horizon: 10000 | ||
gamma: 0.99 | ||
lam: 0.95 | ||
cliprange: 0.2 | ||
cliprange_value: 0.2 | ||
vf_coef: 1.0 | ||
scale_reward: False | ||
ref_mean: null | ||
ref_std: null | ||
cliprange_reward: 10 | ||
gen_kwargs: | ||
max_new_tokens: 100 | ||
# top_k: 50 | ||
# top_p: 0.95 | ||
# do_sample: True | ||
gen_inference_kwargs: | ||
max_new_tokens: 100 |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from typing import List | ||
|
||
import evaluate | ||
from datasets import load_dataset | ||
from tqdm import tqdm | ||
from transformers import AutoTokenizer | ||
|
||
import trlx | ||
from trlx.data.configs import TRLConfig | ||
|
||
meteor = evaluate.load("meteor") # use meteor as the reward function | ||
|
||
if __name__ == "__main__": | ||
|
||
def reward_fn(samples: List[str]): | ||
sep_token = tokenizer.sep_token | ||
articles = [sample.split(sep_token)[0].strip() for sample in samples] | ||
predicted_summaries = [sample.split(sep_token)[1].strip() for sample in samples] | ||
labels = [prompt_label[sample] for sample in articles] | ||
scores = [ | ||
meteor.compute(predictions=[summary], references=[label]) | ||
for (summary, label) in zip(predicted_summaries, labels) | ||
] | ||
scores = [score["meteor"] for score in scores] | ||
return scores | ||
|
||
config = TRLConfig.load_yaml("configs/ppo_config_cnn_daily.yml") | ||
|
||
# samples 10000 samples from the training set as prompts for training | ||
dataset = load_dataset("cnn_dailymail", "3.0.0", split="train", cache_dir="data") | ||
prompts = dataset["article"][0:20000] | ||
summaries = dataset["highlights"][0:20000] | ||
prompts = ["Summarize: " + prompt for prompt in prompts] | ||
|
||
# samples 100 samples from the validation set as prompts for evaluation | ||
val_dataset = load_dataset( | ||
"cnn_dailymail", "3.0.0", split="validation", cache_dir="data" | ||
) | ||
val_prompts = ["Summarize: " + prompt for prompt in val_dataset["article"][0:1000]] | ||
val_summaries = val_dataset["highlights"][0:1000] | ||
|
||
# make dictionary of prompts and labels to use for reward function | ||
tokenizer = AutoTokenizer.from_pretrained(config.model.model_path) | ||
tokenizer.padding_side = "left" | ||
tokenizer.truncation_side = "right" | ||
tokenizer.sep_token = "<sep>" | ||
prompt_label = {} | ||
max_length = config.train.seq_length - config.method.gen_kwargs["max_new_tokens"] | ||
|
||
for i in tqdm(range(len(prompts))): | ||
key = tokenizer.decode( | ||
tokenizer(prompts[i], truncation=True, max_length=max_length)["input_ids"], | ||
skip_special_tokens=True, | ||
) # get prompt like trlx's prompt | ||
prompt_label[key.strip()] = summaries[i] | ||
|
||
for i in tqdm(range(len(val_prompts))): | ||
key = tokenizer.decode( | ||
tokenizer(val_prompts[i], truncation=True, max_length=max_length)[ | ||
"input_ids" | ||
], | ||
skip_special_tokens=True, | ||
) # get prompt like trlx's prompt | ||
prompt_label[key.strip()] = val_summaries[i] | ||
|
||
model = trlx.train( | ||
config.model.model_path, | ||
reward_fn=reward_fn, | ||
prompts=prompts, | ||
eval_prompts=val_prompts, | ||
config=config, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This this is an example we probably should have lots of comments.