Skip to content

Add support for DBRX models: dbrx-base and dbrx-instruct #6344

Closed

Description

@maziyarpanahi

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest code. Development is very rapid so there are no tagged versions as of now.
  • I carefully followed the README.md.
  • I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
  • I reviewed the Discussions, and have a new bug or useful enhancement to share.

Feature Description

Databricks just released 2 new models called DBRX (base and instruct). They have their own architecture:

{
  "architectures": [
    "DbrxForCausalLM"
  ],
  "attn_config": {
    "clip_qkv": 8,
    "kv_n_heads": 8,
    "model_type": "",
    "rope_theta": 500000
  },
  "auto_map": {
    "AutoConfig": "configuration_dbrx.DbrxConfig",
    "AutoModelForCausalLM": "modeling_dbrx.DbrxForCausalLM"
  },
  "d_model": 6144,
  "emb_pdrop": 0.0,
  "ffn_config": {
    "ffn_hidden_size": 10752,
    "model_type": "",
    "moe_jitter_eps": 0,
    "moe_loss_weight": 0.05,
    "moe_num_experts": 16,
    "moe_top_k": 4
  },
  "initializer_range": 0.02,
  "max_seq_len": 32768,
  "model_type": "dbrx",
  "n_heads": 48,
  "n_layers": 40,
  "output_router_logits": false,
  "resid_pdrop": 0.0,
  "router_aux_loss_coef": 0.05,
  "tie_word_embeddings": false,
  "torch_dtype": "bfloat16",
  "transformers_version": "4.38.2",
  "use_cache": true,
  "vocab_size": 100352
}

Motivation

These models are superior to the predecessors like Llama-2 or Mixtral (even though they are larger), the community can really benefit from these two and the fine-tuned models that come after.

https://huggingface.co/databricks/dbrx-instruct

Possible Implementation

If you have an idea as to how it can be implemented, please write a detailed description. Feel free to give links to external sources or share visuals that might be helpful to understand the details better.

python llama.cpp/convert-hf-to-gguf.py

Traceback (most recent call last):
  File "/llama.cpp/convert-hf-to-gguf.py", line 2099, in <module>
    main()
  File "/llama.cpp/convert-hf-to-gguf.py", line 2079, in main
    model_class = Model.from_model_architecture(hparams["architectures"][0])
  File "/llama.cpp/convert-hf-to-gguf.py", line 215, in from_model_architecture
    raise NotImplementedError(f'Architecture {arch!r} not supported!') from None
NotImplementedError: Architecture 'DbrxForCausalLM' not supported!

python llama.cpp/convert.py

  File "/llama.cpp/convert.py", line 1486, in <module>
    main()
  File "/llama.cpp/convert.py", line 1422, in main
    model_plus = load_some_model(args.model)
  File "/llama.cpp/convert.py", line 1291, in load_some_model
    model_plus = merge_multifile_models(models_plus)
  File "/llama.cpp/convert.py", line 747, in merge_multifile_models
    model = merge_sharded([mp.model for mp in models_plus])
  File "/llama.cpp/convert.py", line 726, in merge_sharded
    return {name: convert(name) for name in names}
  File "/llama.cpp/convert.py", line 726, in <dictcomp>
    return {name: convert(name) for name in names}
  File "/llama.cpp/convert.py", line 701, in convert
    lazy_tensors: list[LazyTensor] = [model[name] for model in models]
  File "/llama.cpp/convert.py", line 701, in <listcomp>
    lazy_tensors: list[LazyTensor] = [model[name] for model in models]
KeyError: 'transformer.blocks.0.ffn.experts.mlp.w1'

Dbrx is a mixture-of-experts model, which each FFN is divided into 16 experts and only 4 are activated at any given time. We build on MegaBlocks
https://github.com/databricks/megablocks

Activity

  1. abhi-mosaic commented on Mar 27, 2024

    @abhi-mosaic

    Hi! DBRX researcher here, happy to help out however I can!

    The architecture is quite similar to Mixtral, which is already supported in this framework. The modeling source code for DBRX is available on the HF Hub here: https://huggingface.co/databricks/dbrx-instruct/blob/main/modeling_dbrx.py

    The main differences vs. Mixtral as far as I can tell:

    Please let me know if you have any questions!

  2. abhi-mosaic commented on Mar 27, 2024

    @abhi-mosaic

    The model is ~132B params so I think the expected memory usage is:

  3. ggerganov commented on Mar 27, 2024

    @ggerganov
    Member

    @abhi-mosaic Thanks for the pointers. We do split the experts in separate tensors at the moment, but it is something that we planned to change: #6082

    Seems like now is the time do that

  4. maziyarpanahi commented on Mar 27, 2024

    @maziyarpanahi
    Author

    Thanks @abhi-mosaic for all the complete and detailed explanations.

    @ggerganov I have a big server, I can test any PR from 16bit all the way down to 2bit. (I have the model already downloaded and ready)

  5. moshemalawach commented on Mar 27, 2024

    @moshemalawach

    Same, got big servers with very fast and plentyful ram channels, so can try on CPU all the sizes.

  6. sirus20x6 commented on Mar 28, 2024

    @sirus20x6
    Contributor

    Put me in coach, I'm ready to play, today.

    image

  7. veryvanya commented on Mar 28, 2024

    @veryvanya

    happy to test on my server

  8. simsim314 commented on Mar 28, 2024

    @simsim314

    @abhi-mosaic While the llama.cpp guys are working on solving their issue with 16 experts and not 8, I was thinking to quantize 4 bits with the native huggingface BitsAndBytes, still getting an error
    P.S. This will enable many people with much smaller computational power still, 66GB to run the model. Single H100 or A100, instead of the current 4.

  9. abhi-mosaic commented on Mar 28, 2024

    @abhi-mosaic

    @simsim314 take a look at this comment, I think someone found a workaround by:

    • remapping the safetensor weight files to look like separate linear weights, 1 per expert
    • edit modeling source code to use a List[nn.Linear]
    • new model should work with bitsnbytes

    https://huggingface.co/databricks/dbrx-instruct/discussions/10#660566f14f41c0c7c0e54ab9

  10. peterhgruber commented on Mar 29, 2024

    @peterhgruber

    The model is ~132B params so I think the expected memory usage is:

    Not quite ... they say only 36B parameters are "active on any input", as it is a mixture of experts model.

  11. wrapss commented on Mar 29, 2024

    @wrapss

    Not quite ... they say only 36B parameters are "active on any input", as it is a mixture of experts model.

    but the entire model needs to be loaded into memory even if the parameters are not activated

  12. MohamedAliRashad commented on Mar 29, 2024

    @MohamedAliRashad

    I have the model downloaded in my server if something is added, i can help testing.

  13. RodriMora commented on Apr 1, 2024

    @RodriMora
    Contributor

    I have the model downloaded too and can help testing:

    image

  14. nkeilar commented on Apr 2, 2024

    @nkeilar

    Have a dual 3090 setup and interested in quant to 2bit to see if it will fit in 48GB VRAM, could also test with CPU layers offloaded as running 14900KS. Eric was able to get a The Professor, a 155 Billion parameter model into being able to run on a dual 3090.

  15. 22 remaining items

  16. phymbert commented on Apr 7, 2024

    @phymbert
    Collaborator

    Do you have a PR ready so I can also test it locally?

  17. ggerganov commented on Apr 8, 2024

    @ggerganov
    Member

    You just copy the original license exactly how they did it in their model card

    @ggerganov please confirm I can upload it on ggml-org with the above ?

    No need to upload it - in ggml-org we only want to have models that are used by the CI or for other kind of test/demo purposes

  18. phymbert commented on Apr 8, 2024

    @phymbert
    Collaborator

    No need to upload it - in ggml-org we only want to have models that are used by the CI or for other kind of test/demo purposes

    Noted, deleted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmodelModel specific

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions