Add `StableLM`
Author: jon-tow
Pull request: yes

# What does this PR do?

This PR adds modeling support for [`StableLM 3B 4E1T`](https://huggingface.co/stabilityai/stablelm-3b-4e1t) (as well as [`StableLM 2 1.6B`](https://huggingface.co/stabilityai/stablelm-2-1_6b)) based models.

<!--
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 -->


## 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#start-contributing-pull-requests),
      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?

@ArthurZucker

<!-- 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

 -->

## Notes

**TODO**: The current online implementation uses an early naming scheme for the [`model_type`](https://huggingface.co/stabilityai/stablelm-3b-4e1t/blob/e3be657f4d1b78eb7520637ba922448a1ee456bd/config.json#L16)
```json
  "model_type": "stablelm_epoch",
```
I've temporarily created a development model repository https://huggingface.co/jon-tow/stablelm-3b-4e1t-dev for unit testing and [config archive mapping](https://github.com/jon-tow/transformers/blob/caf38d1659333ae826c0f64d2e3bec45e008081b/src/transformers/models/stablelm/configuration_stablelm.py#L24) which need to be updated before any merging.
Is there a better way to handle this? I've noticed a similar issue in [this](https://github.com/huggingface/transformers/pull/26170#discussion_r1368903469) `Phi` model PR discussion.



Comments:
Hey! Thanks for contributing! 
We usually recommend to start by adding the model on the hub, to allow for a quick distribution! 
See the tutorial [here](https://huggingface.co/docs/transformers/custom_models)

Hello!

> We usually recommend to start by adding the model on the hub, to allow for a quick distribution!

The model is already on the hub [here](https://huggingface.co/stabilityai/stablelm-3b-4e1t/tree/main) but uses custom modeling code. Is your suggestion to simply rename the `model_type` in the config.json and remove the custom implementation? Sorry if I'm misinterpreting this!

No what I mean is I think it's fine to keep it on the hub! 🤗 
We usually go for an integration if this is really asked by the community ( lots of activity on the repo / lots of activity on the issue for adding it here etc!) 
Thought it's really great that you want to contribute!
If you still want to add it, I would recommend you to make it as close as possible to other modelling files like Llama or Persimmon, and otherwise good that you created a repo for dev 👍🏻 

Hi, @ArthurZucker; thanks for the quick review! I'd like to point out that the recent commit https://github.com/huggingface/transformers/pull/28810/commits/097272f2272f545cf275c23e46cf7706e9bfac1f removes a copied-from comment from `StableLmModel` because `PersimmonModel` does not yet support `flash-attn` and the added `_attn_implementation` field breaks the `make repo-consistency` check. Let me know if you suggest a workaround 🙏 

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

Could you rebase on main and make sure CIs are all green? 🤗 I can help if you can't finish all of them

Can you please help with the `test_hubs` workflow? It errors with `FAILED tests/trainer/test_trainer.py::TrainerIntegrationWithHubTester::test_push_to_hub_with_saves_each_epoch - AssertionError: 'Training in progress, epoch 1' not found in ['Training in progress, epoch 3', 'Training in progress, epoch 2', 'initial commit']` ([here](https://app.circleci.com/pipelines/github/huggingface/transformers/84263/workflows/f575df75-a763-4730-87af-5a533829762b/jobs/1088603?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-checks-link&utm_content=summary)). Not sure how to fix this one up 😅 Thanks!