Skip to content

fix: prevent input side-effects in processor text args #36866

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

Closed
wants to merge 6 commits into from

Conversation

nph4rd
Copy link

@nph4rd nph4rd commented Mar 20, 2025

What does this PR do?

Fixes input side-effects in multiple processor classes when the text input is a list.

Fixes #36865

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@ArthurZucker @qubvel

@github-actions github-actions bot marked this pull request as draft March 20, 2025 17:57
Copy link
Contributor

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. When it is ready for review, please click the Ready for review button (at the bottom of the PR page).

@nph4rd nph4rd marked this pull request as ready for review March 20, 2025 18:04
@github-actions github-actions bot requested review from molbap and yonigozlan March 20, 2025 18:04
@zucchini-nlp
Copy link
Member

For me it seems the problem is in how qwen2-vl is written. Other VLMs do not override the text and use save expanded prompts in a new list. So rewriting Qwen2-VL is more preferable than adding a copy() in all processors

@nph4rd
Copy link
Author

nph4rd commented Mar 20, 2025

@zucchini-nlp - thanks for the comment! 😃

Just to be clear: I added the copy() in all the processors that have a similar pattern like:

for sample in text:
    sample = sample.replace(...)

This isn't just Qwen-based processors. One example: Pixtral.

So, if I understand correctly, you're saying it'd be preferrable to change all these processors to have something like:

expanded_samples = []
for sample in text:
    expanded_sample =  sample.replace(...)
    expanded_samples.append(expanded_sample)

Correct?

I must say: I don't find that cleaner 🤔 and if it's for the sake of consistency then I'd suggest adding the .copy() to the rest of the VLM processors. That would imply less changed lines and better readability IMO -- e.g. no variable name change. However, if what you're saying is the consensus then I'd be happy to make the changes.

@nph4rd
Copy link
Author

nph4rd commented Mar 20, 2025

That would imply less changed lines

ha! 🤔 don't think that's true. My bad.

Still, it seems a bit less readable to me.

Again, happy to go either way if that's your suggestion.

@zucchini-nlp
Copy link
Member

@nph4rd not a big difference for me, I am good whichever way as long as it doesn't do in-place modifications. I was surprised to see so many processor's changed, while the error is applicable only to Qwen VL

Let's also see what @molbap thinks

@pbarker
Copy link

pbarker commented Apr 9, 2025

@molbap any thoughts here? This is a pretty tricky bug when encountered downstream that is hurting the larger ecosystem

Copy link
Member

@qubvel qubvel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing! Agree, we should avoid modifying original inputs.

P.S. Let's merge main and resolve conflicts, to be able to merge the PR

@zucchini-nlp
Copy link
Member

Sorry, qwen has been fixed already as part of a different PR. We might not need this fix anymore, other VLMs don't do in-place modification

@nph4rd
Copy link
Author

nph4rd commented May 14, 2025

@qubvel - apologies for the delay. I've just merged main.

@molbap molbap requested a review from ArthurZucker May 14, 2025 09:12
@molbap
Copy link
Contributor

molbap commented May 14, 2025

Missed out on this - I think we should not mutate inputs indeed.

@zucchini-nlp
Copy link
Member

I think it was already fixed as part of another PR already for qwen models, and other models don't mutate input

@nph4rd
Copy link
Author

nph4rd commented May 15, 2025

I think it was already fixed as part of another PR already for qwen models, and other models don't mutate input

@zucchini-nlp - could you link the PR? I can't find it

I'm not sure about the other models. I don't see why they wouldn't. I tried to include all of the processors that had in-place mutations.

@zucchini-nlp
Copy link
Member

zucchini-nlp commented May 15, 2025

@nph4rd it was #37342 because some tests would fail otherwise (I think that test was modified right before merging though). And since the test passed for other models, I assume no other processor has in-place modifications. We usually save expanded inputs in a new list, and qwen was an more of an exception 😄

If you see other models doing in-place modification, feel free to rebase and update the PR. Will be very much welcome. And adding a test would be nice so we catch these processors before merging

@nph4rd
Copy link
Author

nph4rd commented May 15, 2025

Ah, I see, @zucchini-nlp. Looks good! Thanks for the heads up.

In that case, @molbap, I'll close this PR and the corresponding issue 👍

@nph4rd nph4rd closed this May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple processor classes have input side-effects
5 participants