-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
[Bug Fix] fix qa pipeline tensor to numpy #31585
Conversation
@@ -118,7 +118,7 @@ def select_starts_ends( | |||
max_answer_len (`int`): Maximum size of the answer to extract from the model's output. | |||
""" | |||
# Ensure padded tokens & question tokens cannot belong to the set of candidate answers. | |||
undesired_tokens = np.abs(np.array(p_mask) - 1) | |||
undesired_tokens = np.abs(p_mask.numpy() - 1) |
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.
Does this still work if you run the pipeline in jax?
from transformers import pipeline
pipe = pipeline("question-answering", model="hf-internal-testing/tiny-random-bert", framework="flax")
question = "What's my name?"
context = "My Name is Sasha and I live in Lyon."
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.
It will raise a value error.
ValueError: Pipeline cannot infer suitable model classes from hf-internal-testing/tiny-random-bert
.
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.
Besides, temsor.numpy()
has been already used in other pipelines like ASR
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.
OK, yes, looking into it we seem so assume either tf or pt everywhere in the pipeline, so even though I think this would break things for jax tensors it's not something we need to take account of at the moment. Thanks for testing!
Hi @amyeroberts , could you take a look at this PR? I am waiting for your response, thx! |
Hey @jiqing-feng! I'm trying to reproduce the issue but failing at doing so with python 3.8.18 and numpy 1.24.4.
What's your torch version? |
torch 2.3.0+cpu |
I just checked that torch 2.3.1+cpu fixed this issue; you can close this PR if you think there is no need to do this change. BTW, I suppose the change will not break anything, and it's more common. Thx! |
@jiqing-feng Thanks for investigating across the different pytorch versions. If the fix it only in later versions, then this is a change we'd still want as we officially support torch >= 1.11 |
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.
Thanks for fixing!
* fix qa pipeline * fix tensor to numpy
* fix qa pipeline * fix tensor to numpy
* fix qa pipeline * fix tensor to numpy
Hi @Narsil @amyeroberts
This PR fixed the error for question-answering pipeline, the error could be reproduced by
Traceback: