Add trainer integration test for llava to ensure accelerate autocasting works correctly
Author: frasermince
Pull request: yes

# What does this PR do?
This PR adds a new integration test to ensure the accelerate autocasting is working correctly. This came out of a discussion found [here](https://github.com/huggingface/transformers/pull/29721#discussion_r1567192103) and that PR should probably be merged first (or this one merged into that one).

Fixes # (issue)


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [x] 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.
      Not an issue but another PR that should probably be merged first: https://github.com/huggingface/transformers/pull/29721#discussion_r1567192103
- [ ] 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).
- [x] 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 and @younesbelkada
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @gante
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @pacman100

Integrations:

- deepspeed: HF Trainer/Accelerate: @pacman100
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc and @younesbelkada

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:
cc @muellerzr for first review 

Updated this now that the previous PR is merged! I am very concerned about OOMs being an issue here however. I think there's some open questions around:
1. How we ensure models are compatible with the trainer and accelerate
2. How we test training a model in CI given how memory intensive this can be

Gentle ping @muellerzr, or possibly @SunMarc? 

Another ping @muellerzr @SunMarc 

> Interesting finding, thanks for fixing and adding tests!
> 
> Out of curiosity, iiuc training llava and llava-next with HF Trainer and fp16/bf16 flags failed with dtype errors, before the fix was done. I am wondering about other llava-based models, this should mean that vipllava, llava-next-video and video-llava should fail with the same error because all follow similar architecture. But for llava-next-video I had a script with fp16 running w/o errors, would love to know your opinion on this

Interesting, it's possible that this error has been subsequently fixed in these other envs. It's been a couple of months since I have looked at this but I could definitely check if there are any other nuances that could cause those models to work with a half precision flag and llava and llava-next to not. I would have to do a a bit more research on this.