Skip to content
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

TextGenerationPipeline: ValueError: return_text is mutually exclusive with return_full_text #33535

Closed
2 of 4 tasks
lupreCSC opened this issue Sep 17, 2024 · 1 comment · Fixed by #33542
Closed
2 of 4 tasks
Labels
bug Core: Pipeline Internals of the library; Pipeline. Usage General questions about the library

Comments

@lupreCSC
Copy link

System Info

  • transformers version: 4.44.2
  • Platform: Linux-6.8.0-40-generic-x86_64-with-glibc2.35
  • Python version: 3.11.4
  • Huggingface_hub version: 0.24.6
  • Safetensors version: 0.4.5
  • Accelerate version: 0.24.0
  • Accelerate config: not found
  • PyTorch version (GPU?): 2.0.0+cu117 (False)
  • Tensorflow version (GPU?): not installed (NA)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Using distributed or parallel set-up in script?: no

Who can help?

@Rocketknight1

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

from transformers.pipelines import pipeline, TextGenerationPipeline
template = """
<s>
{%- for message in messages %}
    {{- message['role'] + ' ' + message['content'] }}
{%- endfor %}
    assistant
"""

model_name = "TurkuNLP/gpt3-finnish-small"
model_pipeline: TextGenerationPipeline = pipeline(model=model_name, framework="pt", task="text-generation")
model_pipeline.tokenizer.chat_template = template

messages = [{"role": "user", "content": "Mitä Suomen paras kaupunki on?"}]
output = model_pipeline(messages, return_text=True, return_full_text=False, do_sample=True, max_new_tokens=10, num_return_sequences=2)
print(output)

(Nevermind that this template for this model doesn't really make sense).
The above raises

File .../transformers/pipelines/text_generation.py:174, in TextGenerationPipeline._sanitize_parameters(self, return_full_text, return_tensors, return_text, return_type, clean_up_tokenization_spaces, prefix, handle_long_generation, stop_sequence, truncation, max_length, **generate_kwargs)
    172 if return_full_text is not None and return_type is None:
    173     if return_text is not None:
--> 174         raise ValueError("`return_text` is mutually exclusive with `return_full_text`")
    175     if return_tensors is not None:
    176         raise ValueError("`return_full_text` is mutually exclusive with `return_tensors`")

ValueError: `return_text` is mutually exclusive with `return_full_text`

Removing the return_text=True argument to the pipeline call returns the expected result (only the newly generated text).

Expected behavior

The code above succeeds and returns only newly generated text, without the prompt, as specified in the documentation:

return_text (bool, optional, defaults to True) — Whether or not to return the decoded texts in the outputs.
return_full_text (bool, optional, defaults to True) — If set to False only added text is returned, otherwise the full text is returned. Only meaningful if return_text is set to True.

@lupreCSC lupreCSC added the bug label Sep 17, 2024
@Rocketknight1
Copy link
Member

This is definitely a bug, or at the very least incorrect documentation. Thanks for flagging it, we're investigating now!

@LysandreJik LysandreJik added Core: Pipeline Internals of the library; Pipeline. Usage General questions about the library labels Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Core: Pipeline Internals of the library; Pipeline. Usage General questions about the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants