Comments (8)
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.
from transformers.
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.
@zucchini-nlp thanks. why user need to create mask by themself?
from transformers.
@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.
Thanks for your help.
from transformers.
@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 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)
- Cannot import name 'WhisperForAudioClassification -Already installed transformers==4.40.2 HOT 4
- Rewriting usage of `torch.bucketize` with more elementary functions
- Significant performance degradation with multi-GPU training on newer torch/transformers HOT 10
- [BLIP2] BLIP2QFormerLayer is missing the self.intermediate parameter, which makes training from scratch impossible
- ImportError: cannot import name 'PaliGemmaForConditionalGeneration' from 'transformers' (/usr/local/lib/python3.10/dist-packages/transformers/__init__.py) HOT 2
- Mamba: `use_cache` is not passed through in `prepare_inputs_for_generation` HOT 1
- scores_for_ground_truths Error for deepset/roberta-base-squad2 model and squad_v2 dataset HOT 1
- Enabling device_map="auto" for Video-LLaVA HOT 1
- Cache problem while runing on multiple nodes with GPU HOT 3
- Improving memory efficiency further 🚀
- Unsuppressable warning: "<model> will not detect padding tokens in `inputs_embeds`" HOT 1
- HF's llama implementation is different from meta-llama's HOT 4
- Owlv2 model keeps crashing HOT 2
- Kosmos-2.5 implementation in transformers HOT 3
- Have `_is_peft_model` check if there's any peft submodule/Allow quantised training HOT 2
- Wav2vec2 model has unknown attributes weight_g/weight_v when DeepSpeed ZeRO-3 is enabled
- Add IRIS
- How to get the data seen by the model during training? HOT 2
- ImportError: Using `bitsandbytes` 8-bit quantization requires Accelerate: `pip install accelerate` and the latest version of bitsandbytes: `pip install -i https://pypi.org/simple/ bitsandbytes` HOT 1
- RuntimeError: Failed to import transformers.generation.utils because of the following error (look up to see its traceback): cannot import name 'GenerateOutput' from partially initialized module 'transformers.generation.utils' (most likely due to a circular import) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from transformers.