facebookresearch / metaseq

Repo for external large-scale work
MIT License
6.52k stars 726 forks source link

Very weird predictions of OPT-IML-30B on Blended Skill Talk dataset. #694

Closed qtli closed 1 year ago

qtli commented 1 year ago

❓ Very weird predictions of OPT-IML-30B on Blended Skill Talk dataset.

My question

I want to use the OPT-IML model for diverse generation tasks, including dialogue datasets. I tried the dataset - Blended Skill Talk from PromptSource which is evaluated in the OPT-IML paper. I use greedy decoding where the input is combined with the prompt template guess-last-utterance.

I use the DeepSpeed framework for inference and the checkpoints are downloaded from Huggingface. The checkpoints are pre-sharded for speed-up.

Code

data_type = getattr(torch, args.dtype)
model = deepspeed.init_inference(pipe.model,
                                 mp_size=world_size,
                                 dtype=data_type,
                                 replace_with_kernel_inject=args.use_kernel,  # args.use_kernel
                                 replace_method=args.replace_method,
                                 max_tokens=args.length,
                                 save_mp_checkpoint_path=args.save_mp_checkpoint_path,
                                 **ds_kwargs
                                 )

prompt_text_0 = "Keywords: cat, look, mouse\n\nWhat is a sentence that includes all these keywords?\nAnswer:"
prompt_texts = [prompt_text_0]

eprompt = []
for ppt in prompt_text:
    eprompt.append(tokenizer.encode(ppt.strip(), add_special_tokens=False, return_tensors="pt"))  

for encoded_prompt, ppt in zip(eprompt, prompt_text):
    encoded_prompt = encoded_prompt.to(device)

    if encoded_prompt.size()[-1] == 0:
        input_ids = None
    else:
        input_ids = encoded_prompt

    output_sequences = model.generate(
        input_ids=input_ids,
        max_new_tokens=args.length,  # 256
        temperature=args.temperature,  # 1.0
        top_k=args.top_k,  # 0
        top_p=args.top_p, # 1.0
        pad_token_id=args.pad_token_id, 
    )

generated_sequences = []  
for generated_sequence_idx, generated_sequence in enumerate(output_sequences):
    generated_sequence = generated_sequence.tolist()

    text = tokenizer.decode(generated_sequence, clean_up_tokenization_spaces=True)
    text = text[: text.find(args.stop_token) if args.stop_token else None]

    total_sequence = text[len(tokenizer.decode(encoded_prompt[0], clean_up_tokenization_spaces=True)) :].strip()
    if args.local_rank in [-1, 0]:
        print('#####INPUT: {}\n'.format(ppt))
        print('#####OUTPUT: {}\n'.format(total_sequence))

Cases

I post several examples I tried here:

Input 1:

Given the below conversation between two people, what would the listener say?

A: Our son in the Army is taking a leave to visit us next month.

B: Oh, you must be so excited! I have a son in the Army as well and I love when he gets to visit! 

A: Can't believe he grew up so quick

B: Yeah, kids grow up so quickly 

A: What do you usually do when he visits?

B: We will probably just spend most of the time here at home, no big plans really.

A: I understand. I think we will do the same. I hope he brings a few of his friends. I am not that old... if you know what I mean :)

B: You're only as old as you feel is what I say.

A: Yes, that's exactly right! If you don't mind me asking, have you ever considered any of your son's friends? ^_^

B: Not really since I am usually spending my time alone in my studio painting, but I might give it some thought.

A: You should. I am not really a blond, but I would say cute and the kids dig me. :) And you know, sometimes I let them play with me

B: Well everyone is an adult so who am I to judge, sounds like a good bit of fun to me.

A: What are you up to now, girl?

B:

Output 1:

I The I I: I: The, The, The, The The The The, The, The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The following The The The The The The The The The The The The The The The The The The The Theatre is Theatre is Theatre is Theatre is Theatre is The( The( The( The( is is is is is is is is is is is is is is is is is is is,, is,,,,,,,,,,, sounds is sounds.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Input 2:

Given the below conversation between two people, what would the listener say?

A: My turtle ran away from me today.

B: Oh my god. Did you guys have a fight?

A: that's funny. No. I let him roam around the house.

B: What does your turtle eat?  Is it hard to take care of a turtle?

A: He eats insects, leaves and sun flower seeds. It's easy. They don't need walking and cleanup is simple. Do you have any pets?

B: No, not at the moment.  I have 3 girls and they are enough trouble! LOL

A: Congratulations. Do you come from a big family?

B: I don't, just 2 siblings.  But my wife wanted a lot of kids. So, there you go.

A: Wow. cool. How often do you use computers?

B: I use a Mac for my work - I'm a music teacher.  I find it really helpful.  How about you?  Are you on the computer a lot?

A: Often. I use them at work for editing. I head about a way to stream videos or movies from the local library.

B: Stream from the library - now, that sounds interesting. My wife and I do some scuba diving and want to begin filming underwater. Ever tried that?

A: No, but I have snorkled.

B:

Output 2:

Ial ( I and I and I The. The. I I. I I?. I?....
........????.?.?.?????.????????????? The?? The?? The.. The The. The The
 The The The. The The The The The The... The
 The... The The... The... The... The... The... The... The... The... The The... The... The... The... The The... The... The... The... The... The... The... The... The... The... The... The... The... The... The... The... The... The... The... The... The The... The... The The... The... The... The... The The... The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The Th

Input 3:

Given the below conversation between two people, what would the listener say?

A: My turtle ran away from me today.

B: Oh my god. Did you guys have a fight?

A: that's funny. No. I let him roam around the house.

B: What does your turtle eat?  Is it hard to take care of a turtle?

A: He eats insects, leaves and sun flower seeds. It's easy. They don't need walking and cleanup is simple. Do you have any pets?

B: No, not at the moment.  I have 3 girls and they are enough trouble! LOL

A: 

Output 3:

Haha. I have 2 boys. They are a handful too.

Input 4:

Keywords: cat, look, mouse

What is a sentence that includes all these keywords?

Output 4:

cat looking at a mouse

Input 5:

Put the triples together to form a sentence: Hawaii Five-O : NOTES : Episode: The Flight of the Jewels | [TABLECONTEXT] : [TITLE] : Jeff Daniels | [TABLECONTEXT] : TITLE : Hawaii Five-O
Sentence:

Output 5:

Jeff Daniels starred as Steve McGarrett in the television series Hawaii Five-O.

What's your environment?

I don't know why the predictions from OPT-IML-3OB become weird when the dialogue context is relatively long (but other relatively short cases are good). Is anyone who could help me with this issue? I want to know the reasons behind the messy outputs (1 & 2).

Thanks in advance!

larekrow commented 1 year ago

How did you initialize your tokenizer? Anyway try this:

tokenizer = AutoTokenizer.from_pretrained('facebook/opt-iml-30b', use_fast=False)
qtli commented 1 year ago

How did you initialize your tokenizer? Anyway try this:

tokenizer = AutoTokenizer.from_pretrained('facebook/opt-iml-30b', use_fast=False)

Hi, @larekrow Thanks for your reply.

I previousely used:

tokenizer = AutoTokenizer.from_pretrained('/home/qintongli/llms/sharded_opt_iml_30b', padding_side="left")  

When I changed to:

tokenizer = AutoTokenizer.from_pretrained('/home/qintongli/llms/sharded_opt_iml_30b', use_fast=False)

The situation is not getting better:

#####INPUT: Given the below conversation between two people, what would the listener say?

A: My turtle ran away from me today.

B: Oh my god. Did you guys have a fight?

A: that's funny. No. I let him roam around the house.

B: What does your turtle eat?  Is it hard to take care of a turtle?

A: He eats insects, leaves and sun flower seeds. It's easy. They don't need walking and cleanup is simple. Do you have any pets?

B: No, not at the moment.  I have 3 girls and they are enough trouble! LOL

A: Congratulations. Do you come from a big family?

B: I don't, just 2 siblings.  But my wife wanted a lot of kids. So, there you go.

A: Wow. cool. How often do you use computers?

B: I use a Mac for my work - I'm a music teacher.  I find it really helpful.  How about you?  Are you on the computer a lot?

A: Often. I use them at work for editing. I head about a way to stream videos or movies from the local library.

B: Stream from the library - now, that sounds interesting. My wife and I do some scuba diving and want to begin filming underwater. Ever tried that?

A: No, but I have snorkled.

B:

#####OUTPUT: I I to I I I. I. and I. and and I..................................................

#####INPUT: Given the commands below, what is the corresponding correct sequence of actions (commaseparated)?
run opposite left twice after turn left
Answer: 

#####OUTPUT: turn left, turn left, turn left, run, turn left, turn left, run

#####INPUT: Put the triples together to form a sentence: Hawaii Five-O : NOTES : Episode: The Flight of the Jewels | [TABLECONTEXT] : [TITLE] : Jeff Daniels | [TABLECONTEXT] : TITLE : Hawaii Five-O
Sentence:

#####OUTPUT: Jeff Daniels starred as Steve McGarrett in the television series Hawaii Five-O.
larekrow commented 1 year ago

I would try these changes:

tokenizer = AutoTokenizer.from_pretrained('facebook/opt-iml-30b', use_fast=False, padding_side="left")

Unless you finetuned your own tokenizer, it might be better to troubleshoot with the open sourced version which many people have tried and tested.

output_sequences = model.generate(
    input_ids=input_ids,
    max_new_tokens=256,
    top_p=0.9
    temperature=0.7,
    pad_token_id=args.pad_token_id, 
)

A lower top P to not generate the long tail, and a lower temperature to smooth out probability distribution spikes which could contribute to repetition.

You could also play around with the generation arguments and see if it suits your task better.

qtli commented 1 year ago

Many thanks for your kind suggestion @larekrow I have solved my problem :)