Adding mplugdocowl
Author: danaaubakirova
Pull request: yes

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes # (issue)


## 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](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? 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](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc 

Documentation: @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_31792). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Hi there, @zucchini-nlp @danaaubakirova 

Would it be okay if I also participate in this PR? 
I have experience with writing the [Processor](https://github.com/jp1924/UReader-kr/blob/main/models/ureader/image_processing_ureader.py) and code for the previous version of DocOwl, UReader, so I believe I can be of help.

Additionally, when coding the Processor and Model, how about referring to [Llava-NEXT](https://huggingface.co/docs/transformers/model_doc/llava_next)? 
Like DocOWL, Llava-NEXT divides images into patches for resolution, so you might find solutions to various issues you’ve encountered while implementing DocOWL on HuggingFace.

Thank you.

Hello @jp1924,

Thank you for reaching out and for your suggestions. This PR is almost complete. However, I look forward to collaborating with you next time.

Best,

Thank you for considering it! I hope we have the opportunity to collaborate together in the future!

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

cc @zucchini-nlp not sur what is the sate of this PR, were you waiting for @molbap 's review (he is off for 2 more weeks I think)) 

@ArthurZucker Hello! Yes, I completed this around 1-2 months ago notified @molbap , and was waiting for his review. 

Hey! @zucchini-nlp will have an other look before I do the final review! 🤗 (pablo is 🌴 off for a while) 

@danaaubakirova I added the expansion logic in processors so now we don't need the `merge_inputs` method in modeling code. I didn't review the PR but some general comments from what I saw during adding the code.
- I added `cache_position` in one Module, but we need to pass it in further to the LM so it is actually used to update the cache. Can help with that one if you are low on bandwidth :) 
- The `modality_indicators` can be prepared in the processor logic and we can call it `token_type_ids`. It is very similar to what we did in CogVLM and somewhat to Paligemma. Would be a lot cleaner that way
- I am not sure if the model is expected to work when no image is passed, because the processing assign `None` to pixels and later tries to get keys from the `None` dict. Can you check pls, as the current logic I implemented also doesn't expected no-image inputs?
- I changed the order of inputs for processor to be `image, text` and not `text, image` but we still need to use the new standardized ProcessorKwargs as noted by @molbap earlier
- Lastly, we need to add GenerationTesterMixin because the latest VLMs should have no problem at enabling them. See https://github.com/huggingface/transformers/pull/32673 for reference
- Overall clean up on docstring and formatting is needed before review, e.g. there are two `MPLUGDOCOWL_INPUTS_DOCSTRING` in difference cases

Let me know if you need any help or PR is ready for review after the above comments are addressed 🤗  

Hey @danaaubakirova @zucchini-nlp ! I can answer on (very) few points here
- `cache_position` passing should be doable yes. Decoder is llama-like. 
- `modality_indicators` to `token_type_ids`, I'm not sure it's a 1-to-1 mapping, might be tricky to do.
- 90% sure the model always expects an image. It's a document analysis model first and foremost, not a text-only conversational model. 
- processors kwargs uniformization is doable. I can help a bit on that.
- for the generation tester mixin, got to go test by test and see what fails. Not sure what is robust right now.
- I can help on docstring formatting.
Overall this looks veryyy close to be done, let's push it over the finish line! 

> for the generation tester mixin, got to go test by test and see what fails. Not sure what is robust right now.

We're almost there, current tests should work in text-only cases. For ex when a LLaVA generates from text and no images. For multimodality opened a PR just today, so I hope it will be there soon (https://github.com/huggingface/transformers/pull/33533)

LMK if some things start failing, it's always better to know why it fails to see if we need fixes on generation side :)