Add padding-free to Granite hybrid moe models 
Author: garrett361
Pull request: yes
Labels: name: Flash Attention

# What does this PR do?

Enables padding-free training for granite hybrid moe models, analogously to #35861

Previously, `**kwargs` were not being properly passed down correctly and attempts at padding-free training were silently wrong. 

The padding-free correctness tests were also updated to verify that that the losses for models agree. 

CC @vasqu @ArthurZucker @fabianlim @Swanand-Kadhe

<!--
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).
- [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
- vision models: @amyeroberts, @qubvel
- speech models: @eustlb
- graph models: @clefourrier

Library:

- flax: @gante and @Rocketknight1
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @zach-huggingface, @SunMarc and @qgallouedec
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @SunMarc @zach-huggingface
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc @MekkCyber

Documentation: @stevhliu

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: @Rocketknight1
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
I verified that `GraniteMoeHybridForCausalLM` and `BambaForCausalLM` both pass the updated padding-free tests

There is 
```python
FAILED tests/models/granitemoe/test_modeling_granitemoe.py::GraniteMoeModelTest::test_causal_lm_can_accept_kwargs - TypeError: forward() got an unexpected keyword argument 'num_items_in_batch'
FAILED tests/models/granitemoeshared/test_modeling_granitemoeshared.py::GraniteMoeSharedModelTest::test_causal_lm_can_accept_kwargs - TypeError: forward() got an unexpected keyword argument 'num_items_in_batch'
```

yeah @ArthurZucker trying to figure out those fails now; passing for me fine, locally 

```
❯ pytest -rsfP tests/models/granitemoehybrid/test_modeling_granitemoehybrid.py -k accept_kwargs
===================================================================================================== test session starts =====================================================================================================
platform linux -- Python 3.11.13, pytest-7.4.4, pluggy-1.6.0
rootdir: /u/goon/github/garrett361/transformers
configfile: pyproject.toml
plugins: anyio-4.9.0, order-1.3.0, timeout-2.4.0, rerunfailures-15.1, xdist-3.8.0, asyncio-0.23.8, rich-0.2.0, hypothesis-6.136.4
asyncio: mode=Mode.STRICT
collected 457 items / 455 deselected / 2 selected

tests/models/granitemoehybrid/test_modeling_granitemoehybrid.py::BambaModelTest::test_causal_lm_can_accept_kwargs PASSED                                                                                                [ 50%]
tests/models/granitemoehybrid/test_modeling_granitemoehybrid.py::GraniteMoeHybridModelTest::test_causal_lm_can_accept_kwargs PASSED                                                                                     [100%]

====================================================================================================== warnings summary =======================================================================================================
.venv/lib/python3.11/site-packages/_pytest/config/__init__.py:1373
  /u/goon/github/garrett361/transformers/.venv/lib/python3.11/site-packages/_pytest/config/__init__.py:1373: PytestConfigWarning: Unknown config option: asyncio_default_fixture_loop_scope

    self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================================================================================================== PASSES ============================================================================================================
_______________________________________________________________________________________ BambaModelTest.test_causal_lm_can_accept_kwargs _______________________________________________________________________________________
---------------------------------------------------------------------------------------------------- Captured stderr call -----------------------------------------------------------------------------------------------------
The fast path for Bamba will be used when running the model on a GPU
Bamba requires an initialized `HybridMambaAttentionDynamicCache` to return a cache. None was provided, so no cache will be returned.
_________________________________________________________________________________ GraniteMoeHybridModelTest.test_causal_lm_can_accept_kwargs __________________________________________________________________________________
---------------------------------------------------------------------------------------------------- Captured stderr call -----------------------------------------------------------------------------------------------------
The fast path for GraniteMoeHybrid will be used when running the model on a GPU
GraniteMoeHybrid requires an initialized `HybridMambaAttentionDynamicCache` to return a cache. Because one was not provided, no cache will be returned.
======================================================================================== 2 passed, 455 deselected, 1 warning in 8.65s =========================================================================================
```

Oh, I see, it's ` tests/models/granitemoe/test_modeling_granitemoe.py`, not  `tests/models/granitemoehybrid/test_modeling_granitemoehybrid.py`. Will fix.

One left!

yeah I forgot to run the modular util. Will ping when I think it's all good

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: bamba, granitemoe, granitemoehybrid, granitemoeshared

Don't worry about other failing tests they should be unrelated!

Okay merging! thanks for adding this support!

Thanks @ArthurZucker ! super quick

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