Giter Club home page Giter Club logo

Comments (8)

liangan1 avatar liangan1 commented on May 21, 2024

According to my debug, the generate mask is not correct. for example, there should be some large negative values in mask, but there is only 0 now.
tensor([[[[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]],

    [[[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]]])

from transformers.

liangan1 avatar liangan1 commented on May 21, 2024

@gante @jianan-gu

from transformers.

zucchini-nlp avatar zucchini-nlp commented on May 21, 2024

Hey @liangan1 !

There are a few things that have to be changed for generation to work properly in batched form. Firstly, tt is recommended to use the left padding side in generation if you are using a decoder-only models. Also, attention mask needs to be passed into the generate if input is batched. Please try the code below to verify that it works :)

from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-chat-hf", padding_side='left')  # left padding for generation
model = AutoModelForCausalLM.from_pretrained("NousResearch/Llama-2-7b-chat-hf")
inputs = tokenizer(["how are you?", "what is the best the AI algorithm?"], return_tensors="pt",padding=True)
output = model.generate(**inputs, max_new_tokens=10)  # pass in not only input ids, but also attention mask
out_text = tokenizer.batch_decode(output, skip_special_tokens=True)
print(out_text)

input_ids = tokenizer(["how are you?"], return_tensors="pt",padding=True).input_ids
output = model.generate(input_ids, max_new_tokens=10)
out_text = tokenizer.batch_decode(output, skip_special_tokens=True)
print(out_text)

from transformers.

liangan1 avatar liangan1 commented on May 21, 2024

@zucchini-nlp thanks. why user need to create mask by themself?

from transformers.

zucchini-nlp avatar zucchini-nlp commented on May 21, 2024

@liangan1 you don't have to create it manually. The tokenizer returns attention mask, which should be passed into generate.

inputs = tokenizer(["how are you?", "what is the best the AI algorithm?"], return_tensors="pt",padding=True)
print(inputs.attention_mask)

I will close the issue as resolved. For any further questions it is recommended to ask in the forum 🤗

from transformers.

liangan1 avatar liangan1 commented on May 21, 2024

Thanks for your help.

from transformers.

gante avatar gante commented on May 21, 2024

@liangan1 to complement the answer above: there are a few seemingly innocuous differences that may result in slightly different LLM outputs, such as batching. To understand why it happens (and why it is unavoidable), have a look at this comment :)

from transformers.

liangan1 avatar liangan1 commented on May 21, 2024

@liangan1 to complement the answer above: there are a few seemingly innocuous differences that may result in slightly different LLM outputs, such as batching. To understand why it happens (and why it is unavoidable), have a look at this comment :)

Thanks for your info.

from transformers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.