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

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
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

Sorry, something went wrong.

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

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).

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@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.

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
2 participants