Instructions to use dynatrace-oss/llama-embed-mamba2-7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use dynatrace-oss/llama-embed-mamba2-7b with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("dynatrace-oss/llama-embed-mamba2-7b") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
feat: model checkpoint
Browse files- .gitattributes +35 -0
- LLAMA_LICENSE +114 -0
- NOTICE +9 -0
- README.md +181 -0
- config.json +50 -0
- config_sentence_transformers.json +14 -0
- model.safetensors +3 -0
- modules.json +20 -0
- sentence_bert_config.json +4 -0
- tokenizer.json +0 -0
- tokenizer_config.json +15 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
LLAMA_LICENSE
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
LLAMA 3.1 COMMUNITY LICENSE AGREEMENT
|
| 2 |
+
Llama 3.1 Version Release Date: July 23, 2024
|
| 3 |
+
|
| 4 |
+
“Agreement” means the terms and conditions for use, reproduction, distribution and modification of the
|
| 5 |
+
Llama Materials set forth herein.
|
| 6 |
+
|
| 7 |
+
“Documentation” means the specifications, manuals and documentation accompanying Llama 3.1
|
| 8 |
+
distributed by Meta at https://llama.meta.com/doc/overview.
|
| 9 |
+
|
| 10 |
+
“Licensee” or “you” means you, or your employer or any other person or entity (if you are entering into
|
| 11 |
+
this Agreement on such person or entity’s behalf), of the age required under applicable laws, rules or
|
| 12 |
+
regulations to provide legal consent and that has legal authority to bind your employer or such other
|
| 13 |
+
person or entity if you are entering in this Agreement on their behalf.
|
| 14 |
+
|
| 15 |
+
“Llama 3.1” means the foundational large language models and software and algorithms, including
|
| 16 |
+
machine-learning model code, trained model weights, inference-enabling code, training-enabling code,
|
| 17 |
+
fine-tuning enabling code and other elements of the foregoing distributed by Meta at
|
| 18 |
+
https://llama.meta.com/llama-downloads.
|
| 19 |
+
|
| 20 |
+
“Llama Materials” means, collectively, Meta’s proprietary Llama 3.1 and Documentation (and any
|
| 21 |
+
portion thereof) made available under this Agreement.
|
| 22 |
+
|
| 23 |
+
“Meta” or “we” means Meta Platforms Ireland Limited (if you are located in or, if you are an entity, your
|
| 24 |
+
principal place of business is in the EEA or Switzerland) and Meta Platforms, Inc. (if you are located
|
| 25 |
+
outside of the EEA or Switzerland).
|
| 26 |
+
|
| 27 |
+
By clicking “I Accept” below or by using or distributing any portion or element of the Llama Materials,
|
| 28 |
+
you agree to be bound by this Agreement.
|
| 29 |
+
|
| 30 |
+
1. License Rights and Redistribution.
|
| 31 |
+
|
| 32 |
+
a. Grant of Rights. You are granted a non-exclusive, worldwide, non-transferable and royalty-free
|
| 33 |
+
limited license under Meta’s intellectual property or other rights owned by Meta embodied in the Llama
|
| 34 |
+
Materials to use, reproduce, distribute, copy, create derivative works of, and make modifications to the
|
| 35 |
+
Llama Materials.
|
| 36 |
+
|
| 37 |
+
b. Redistribution and Use.
|
| 38 |
+
|
| 39 |
+
i. If you distribute or make available the Llama Materials (or any derivative works
|
| 40 |
+
thereof), or a product or service (including another AI model) that contains any of them, you shall (A)
|
| 41 |
+
provide a copy of this Agreement with any such Llama Materials; and (B) prominently display “Built with
|
| 42 |
+
Llama” on a related website, user interface, blogpost, about page, or product documentation. If you use
|
| 43 |
+
the Llama Materials or any outputs or results of the Llama Materials to create, train, fine tune, or
|
| 44 |
+
otherwise improve an AI model, which is distributed or made available, you shall also include “Llama” at
|
| 45 |
+
the beginning of any such AI model name.
|
| 46 |
+
|
| 47 |
+
ii. If you receive Llama Materials, or any derivative works thereof, from a Licensee as part
|
| 48 |
+
of an integrated end user product, then Section 2 of this Agreement will not apply to you.
|
| 49 |
+
|
| 50 |
+
iii. You must retain in all copies of the Llama Materials that you distribute the following
|
| 51 |
+
attribution notice within a “Notice” text file distributed as a part of such copies: “Llama 3.1 is
|
| 52 |
+
licensed under the Llama 3.1 Community License, Copyright © Meta Platforms, Inc. All Rights
|
| 53 |
+
Reserved.”
|
| 54 |
+
|
| 55 |
+
iv. Your use of the Llama Materials must comply with applicable laws and regulations
|
| 56 |
+
(including trade compliance laws and regulations) and adhere to the Acceptable Use Policy for the Llama
|
| 57 |
+
Materials (available at https://llama.meta.com/llama3_1/use-policy), which is hereby incorporated by
|
| 58 |
+
reference into this Agreement.
|
| 59 |
+
|
| 60 |
+
2. Additional Commercial Terms. If, on the Llama 3.1 version release date, the monthly active users
|
| 61 |
+
of the products or services made available by or for Licensee, or Licensee’s affiliates, is greater than 700
|
| 62 |
+
million monthly active users in the preceding calendar month, you must request a license from Meta,
|
| 63 |
+
which Meta may grant to you in its sole discretion, and you are not authorized to exercise any of the
|
| 64 |
+
rights under this Agreement unless or until Meta otherwise expressly grants you such rights.
|
| 65 |
+
|
| 66 |
+
3. Disclaimer of Warranty. UNLESS REQUIRED BY APPLICABLE LAW, THE LLAMA MATERIALS AND ANY
|
| 67 |
+
OUTPUT AND RESULTS THEREFROM ARE PROVIDED ON AN “AS IS” BASIS, WITHOUT WARRANTIES OF
|
| 68 |
+
ANY KIND, AND META DISCLAIMS ALL WARRANTIES OF ANY KIND, BOTH EXPRESS AND IMPLIED,
|
| 69 |
+
INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF TITLE, NON-INFRINGEMENT,
|
| 70 |
+
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. YOU ARE SOLELY RESPONSIBLE FOR
|
| 71 |
+
DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING THE LLAMA MATERIALS AND
|
| 72 |
+
ASSUME ANY RISKS ASSOCIATED WITH YOUR USE OF THE LLAMA MATERIALS AND ANY OUTPUT AND
|
| 73 |
+
RESULTS.
|
| 74 |
+
|
| 75 |
+
4. Limitation of Liability. IN NO EVENT WILL META OR ITS AFFILIATES BE LIABLE UNDER ANY THEORY OF
|
| 76 |
+
LIABILITY, WHETHER IN CONTRACT, TORT, NEGLIGENCE, PRODUCTS LIABILITY, OR OTHERWISE, ARISING
|
| 77 |
+
OUT OF THIS AGREEMENT, FOR ANY LOST PROFITS OR ANY INDIRECT, SPECIAL, CONSEQUENTIAL,
|
| 78 |
+
INCIDENTAL, EXEMPLARY OR PUNITIVE DAMAGES, EVEN IF META OR ITS AFFILIATES HAVE BEEN ADVISED
|
| 79 |
+
OF THE POSSIBILITY OF ANY OF THE FOREGOING.
|
| 80 |
+
|
| 81 |
+
5. Intellectual Property.
|
| 82 |
+
|
| 83 |
+
a. No trademark licenses are granted under this Agreement, and in connection with the Llama
|
| 84 |
+
Materials, neither Meta nor Licensee may use any name or mark owned by or associated with the other
|
| 85 |
+
or any of its affiliates, except as required for reasonable and customary use in describing and
|
| 86 |
+
redistributing the Llama Materials or as set forth in this Section 5(a). Meta hereby grants you a license to
|
| 87 |
+
use “Llama” (the “Mark”) solely as required to comply with the last sentence of Section 1.b.i. You will
|
| 88 |
+
comply with Meta’s brand guidelines (currently accessible at
|
| 89 |
+
https://about.meta.com/brand/resources/meta/company-brand/ ). All goodwill arising out of your use
|
| 90 |
+
of the Mark will inure to the benefit of Meta.
|
| 91 |
+
|
| 92 |
+
b. Subject to Meta’s ownership of Llama Materials and derivatives made by or for Meta, with
|
| 93 |
+
respect to any derivative works and modifications of the Llama Materials that are made by you, as
|
| 94 |
+
between you and Meta, you are and will be the owner of such derivative works and modifications.
|
| 95 |
+
|
| 96 |
+
c. If you institute litigation or other proceedings against Meta or any entity (including a
|
| 97 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Llama Materials or Llama 3.1 outputs or
|
| 98 |
+
results, or any portion of any of the foregoing, constitutes infringement of intellectual property or other
|
| 99 |
+
rights owned or licensable by you, then any licenses granted to you under this Agreement shall
|
| 100 |
+
terminate as of the date such litigation or claim is filed or instituted. You will indemnify and hold
|
| 101 |
+
harmless Meta from and against any claim by any third party arising out of or related to your use or
|
| 102 |
+
distribution of the Llama Materials.
|
| 103 |
+
|
| 104 |
+
6. Term and Termination. The term of this Agreement will commence upon your acceptance of this
|
| 105 |
+
Agreement or access to the Llama Materials and will continue in full force and effect until terminated in
|
| 106 |
+
accordance with the terms and conditions herein. Meta may terminate this Agreement if you are in
|
| 107 |
+
breach of any term or condition of this Agreement. Upon termination of this Agreement, you shall delete
|
| 108 |
+
and cease use of the Llama Materials. Sections 3, 4 and 7 shall survive the termination of this
|
| 109 |
+
Agreement.
|
| 110 |
+
|
| 111 |
+
7. Governing Law and Jurisdiction. This Agreement will be governed and construed under the laws of
|
| 112 |
+
the State of California without regard to choice of law principles, and the UN Convention on Contracts
|
| 113 |
+
for the International Sale of Goods does not apply to this Agreement. The courts of California shall have
|
| 114 |
+
exclusive jurisdiction of any dispute arising out of this Agreement.
|
NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
llama-embed-mamba2-7b
|
| 2 |
+
|
| 3 |
+
Copyright 2026 the model authors.
|
| 4 |
+
|
| 5 |
+
This model was partially trained on synthetic data generated with Llama 3.1 70B.
|
| 6 |
+
|
| 7 |
+
Llama 3.1 is licensed under the Llama 3.1 Community License, Copyright © Meta Platforms, Inc. All Rights Reserved.
|
| 8 |
+
|
| 9 |
+
Built with Llama.
|
README.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: mistralai/Mamba-Codestral-7B-v0.1
|
| 3 |
+
datasets:
|
| 4 |
+
- jspringer/open-synthetic-embeddings
|
| 5 |
+
library_name: sentence-transformers
|
| 6 |
+
license: apache-2.0
|
| 7 |
+
pipeline_tag: sentence-similarity
|
| 8 |
+
tags:
|
| 9 |
+
- sentence-transformers
|
| 10 |
+
- sentence-similarity
|
| 11 |
+
- feature-extraction
|
| 12 |
+
- mamba2
|
| 13 |
+
- vertical-chunking
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# llama-embed-mamba2-7b
|
| 17 |
+
|
| 18 |
+
**llama-embed-mamba2-7b** is a general-purpose text embedding model that reproduces the [e5-mistral-7b-instruct](https://huggingface.co/intfloat/e5-mistral-7b-instruct) training procedure on top of [Codestral Mamba2 7B](https://huggingface.co/mistralai/Mamba-Codestral-7B-v0.1), a recurrent (state space model) architecture. It achieves **embedding quality competitive** with e5-mistral-7b-instruct and similarly trained transformer-based models while offering **linear-time** computational complexity and **constant-memory** inference through a novel vertically chunked inference strategy. This makes it substantially more efficient for long sequences and suitable for memory-constrained environments.
|
| 19 |
+
|
| 20 |
+
A smaller variant is available as [llama-embed-mamba2-1.3b](https://huggingface.co/dynatrace-oss/llama-embed-mamba2-1.3b).
|
| 21 |
+
|
| 22 |
+
> [!Note]
|
| 23 |
+
> **Built with Llama.** This model was partially trained on synthetic data generated with Llama 3.1 70B. See [License](#license) for details.
|
| 24 |
+
|
| 25 |
+
## Performance
|
| 26 |
+
|
| 27 |
+
Aggregated task-mean benchmark results compared to the original e5-mistral-7b-instruct. For detailed results, see our [paper](#citation).
|
| 28 |
+
|
| 29 |
+
| Model | MTEB(Multilingual, v2) | MTEB(eng, v2) | LongEmbed |
|
| 30 |
+
|---|:-:|:-:|:-:|
|
| 31 |
+
| [**llama-embed-mamba2-1.3b**](https://huggingface.co/dynatrace-oss/llama-embed-mamba2-1.3b) | **55.2** | **64.3** | **40.8** |
|
| 32 |
+
| **llama-embed-mamba2-7b** (this model) | **59.4** | **65.2** | **44.5** |
|
| 33 |
+
| [e5-mistral-7b-instruct](https://huggingface.co/intfloat/e5-mistral-7b-instruct) | 60.2 | 68.0 | 43.7 |
|
| 34 |
+
|
| 35 |
+
## Vertically Chunked Inference
|
| 36 |
+
|
| 37 |
+
This model supports **vertically chunked inference**, which achieves **constant memory usage** regardless of input sequence length. Instead of processing the full sequence through one layer at a time (standard horizontal inference), this approach:
|
| 38 |
+
|
| 39 |
+
1. Partitions the input into fixed-size vertical chunks
|
| 40 |
+
2. Processes each chunk through **all** model layers before advancing to the next
|
| 41 |
+
3. Maintains the recurrent states across chunks, preserving full context
|
| 42 |
+
|
| 43 |
+
Parallelization benefits saturate at comparatively small chunk sizes, so processing in fixed-size blocks incurs negligible runtime overhead while dramatically reducing memory consumption. This makes the model particularly advantageous for long documents, resource-constrained environments, and large-batch processing where transformer memory requirements become prohibitive. Additional information can be found in our [paper](#citation).
|
| 44 |
+
|
| 45 |
+
## Usage
|
| 46 |
+
|
| 47 |
+
> [!IMPORTANT]
|
| 48 |
+
> Requires `transformers>=5.5.0` due to a breaking change to the cache of Mamba2 introduced in `v5.5.0` ([transformers#44950](https://github.com/huggingface/transformers/pull/44950)).
|
| 49 |
+
|
| 50 |
+
To utilize the efficient kernel implementations enabling vertically chunked inference, the following libraries must be installed in addition to `sentence-transformers`/`transformers`:
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
pip install kernels einops
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
### Sentence Transformers
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
from sentence_transformers import SentenceTransformer
|
| 60 |
+
|
| 61 |
+
model = SentenceTransformer("dynatrace-oss/llama-embed-mamba2-7b", trust_remote_code=True)
|
| 62 |
+
|
| 63 |
+
queries = [
|
| 64 |
+
"Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery: What is a state space model?",
|
| 65 |
+
]
|
| 66 |
+
documents = [
|
| 67 |
+
"A state space model (SSM) is a mathematical framework that describes a system using state variables.",
|
| 68 |
+
"Embedding models map text to dense vector representations that capture semantic meaning.",
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
query_embeddings = model.encode(queries)
|
| 72 |
+
document_embeddings = model.encode(documents)
|
| 73 |
+
|
| 74 |
+
similarities = model.similarity(query_embeddings, document_embeddings)
|
| 75 |
+
print(similarities)
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
For long inputs, pass `vertical_chunk_size` to enable constant-memory inference. The value should be a multiple of 256 (the intra-layer chunk size). Recommended: largest value that fits in memory for single sequences, 256 or 512 for larger batches.
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
embeddings = model.encode(
|
| 82 |
+
["Your long document text here..."],
|
| 83 |
+
vertical_chunk_size=512,
|
| 84 |
+
)
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
### Transformers
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
import torch
|
| 91 |
+
import torch.nn.functional as F
|
| 92 |
+
from transformers import AutoModel, AutoTokenizer
|
| 93 |
+
|
| 94 |
+
tokenizer = AutoTokenizer.from_pretrained("dynatrace-oss/llama-embed-mamba2-7b")
|
| 95 |
+
model = AutoModel.from_pretrained(
|
| 96 |
+
"dynatrace-oss/llama-embed-mamba2-7b", trust_remote_code=True, torch_dtype=torch.bfloat16
|
| 97 |
+
).eval().cuda()
|
| 98 |
+
|
| 99 |
+
def encode(texts):
|
| 100 |
+
inputs = tokenizer(texts, return_tensors="pt", padding=True).to(model.device)
|
| 101 |
+
with torch.no_grad():
|
| 102 |
+
outputs = model(**inputs)
|
| 103 |
+
embeddings = outputs.last_hidden_state[:, -1, :]
|
| 104 |
+
return F.normalize(embeddings, p=2, dim=-1)
|
| 105 |
+
|
| 106 |
+
queries = [
|
| 107 |
+
"Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery: What is a state space model?",
|
| 108 |
+
]
|
| 109 |
+
documents = [
|
| 110 |
+
"A state space model (SSM) is a mathematical framework that describes a system using state variables.",
|
| 111 |
+
"Embedding models map text to dense vector representations that capture semantic meaning.",
|
| 112 |
+
]
|
| 113 |
+
|
| 114 |
+
query_embeddings = encode(queries)
|
| 115 |
+
document_embeddings = encode(documents)
|
| 116 |
+
|
| 117 |
+
similarities = query_embeddings @ document_embeddings.T
|
| 118 |
+
print(similarities)
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
For long inputs, process the input in vertical chunks to maintain constant memory usage. The `vertical_chunk_size` must be a multiple of 256 (the intra-layer chunk size).
|
| 122 |
+
|
| 123 |
+
```python
|
| 124 |
+
text = "Your long document text here..."
|
| 125 |
+
inputs = tokenizer(text, return_tensors="pt").to(model.device)
|
| 126 |
+
|
| 127 |
+
vertical_chunk_size = 512
|
| 128 |
+
cache_params = None
|
| 129 |
+
for chunk_start in range(0, inputs["input_ids"].size(1), vertical_chunk_size):
|
| 130 |
+
chunk_end = chunk_start + vertical_chunk_size
|
| 131 |
+
chunk_inputs = {
|
| 132 |
+
k: v[:, chunk_start:chunk_end]
|
| 133 |
+
for k, v in inputs.items() if k != "attention_mask"
|
| 134 |
+
}
|
| 135 |
+
chunk_inputs["attention_mask"] = inputs["attention_mask"][:, :chunk_end]
|
| 136 |
+
with torch.no_grad():
|
| 137 |
+
outputs = model(**chunk_inputs, use_cache=True, cache_params=cache_params)
|
| 138 |
+
cache_params = outputs.cache_params
|
| 139 |
+
|
| 140 |
+
embedding = outputs.last_hidden_state[:, -1, :]
|
| 141 |
+
embedding = F.normalize(embedding, p=2, dim=-1)
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
## Open Source Integration Roadmap
|
| 145 |
+
|
| 146 |
+
Our goal is to integrate all necessary changes to simplify the adoption of vertically chunked inference for other models:
|
| 147 |
+
|
| 148 |
+
> [!Note]
|
| 149 |
+
> ⚪ Planned | 🟡 In Progress | 🟢 Integrated
|
| 150 |
+
|
| 151 |
+
- ⚪ **causal-conv1d:** Enable simultaneous `seq_idx` + `initial_states` (required for recurrent processing with left padding)
|
| 152 |
+
- ⚪ **mamba-ssm:** Use `seq_idx` + `initial_states` in `mamba_split_conv1d_scan_combined` and export final states
|
| 153 |
+
- ⚪ **kernels-community:** Propagate changes in `causal-conv1d` and `mamba-ssm` to their kernel hub equivalents in the `kernels-community` repositories
|
| 154 |
+
- ⚪ **transformers:** Use updated `mamba_split_conv1d_scan_combined` with cache params during inference (currently only used during training, not configurable, problems with left padding)
|
| 155 |
+
- ⚪ **sentence-transformers:** Native vertical chunking support
|
| 156 |
+
|
| 157 |
+
*This list will be updated as integration progresses.*
|
| 158 |
+
|
| 159 |
+
## Code Repositories
|
| 160 |
+
|
| 161 |
+
The custom model and inference code used by this model is maintained in two separate repositories so that it can be shared between model checkpoints:
|
| 162 |
+
|
| 163 |
+
- [dynatrace-oss/chunkable-mamba2](https://huggingface.co/dynatrace-oss/chunkable-mamba2): Adjusted Mamba2 kernel and model & configuration classes with recurrent chunked inference support.
|
| 164 |
+
- [dynatrace-oss/chunkable-sentence-transformer](https://huggingface.co/dynatrace-oss/chunkable-sentence-transformer): Sentence Transformers modules (`ChunkableTransformer`, `LastIndexPooling`) enabling constant-memory encoding.
|
| 165 |
+
|
| 166 |
+
## License
|
| 167 |
+
|
| 168 |
+
This model is licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). The training dataset ([open-synthetic-embeddings](https://huggingface.co/datasets/jspringer/open-synthetic-embeddings)) is licensed under MIT.
|
| 169 |
+
|
| 170 |
+
**Llama 3.1 Community License:** This model was partially trained on synthetic data generated with Llama 3.1 70B. Use of this model is subject to the [Llama 3.1 Community License Agreement](https://www.llama.com/llama3_1/license/) and the [Llama 3.1 Acceptable Use Policy](https://www.llama.com/llama3_1/use-policy/). A copy of the Llama 3.1 license is included in the [`LLAMA_LICENSE`](LLAMA_LICENSE) file. Llama 3.1 is licensed under the Llama 3.1 Community License, Copyright © Meta Platforms, Inc. All Rights Reserved.
|
| 171 |
+
|
| 172 |
+
## Usage Considerations
|
| 173 |
+
|
| 174 |
+
This model is intended for the generation of text embeddings for retrieval, clustering, classification, and similar tasks.
|
| 175 |
+
|
| 176 |
+
Embedding models can reflect biases present in their pretraining and fine-tuning data. Users should evaluate the model for fairness in their specific use case and combine model outputs with human verification for applications where embedding quality could materially impact individuals or decisions. This model must not be used for any application prohibited by the [Llama 3.1 Acceptable Use Policy](https://www.llama.com/llama3_1/use-policy/) or in any manner that violates applicable laws and regulations.
|
| 177 |
+
|
| 178 |
+
## Citation
|
| 179 |
+
|
| 180 |
+
> [!Note]
|
| 181 |
+
> Coming soon!
|
config.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"ChunkableMamba2Model"
|
| 4 |
+
],
|
| 5 |
+
"auto_map": {
|
| 6 |
+
"AutoConfig": "dynatrace-oss/chunkable-mamba2--configuration_chunkable_mamba2.ChunkableMamba2Config",
|
| 7 |
+
"AutoModel": "dynatrace-oss/chunkable-mamba2--modeling_chunkable_mamba2.ChunkableMamba2Model"
|
| 8 |
+
},
|
| 9 |
+
"bos_token_id": 0,
|
| 10 |
+
"chunk_size": 256,
|
| 11 |
+
"conv_kernel": 4,
|
| 12 |
+
"dtype": "bfloat16",
|
| 13 |
+
"eos_token_id": 0,
|
| 14 |
+
"expand": 2,
|
| 15 |
+
"head_dim": 64,
|
| 16 |
+
"hidden_act": "silu",
|
| 17 |
+
"hidden_size": 4096,
|
| 18 |
+
"initializer_range": 0.1,
|
| 19 |
+
"intermediate_size": 8192,
|
| 20 |
+
"layer_norm_epsilon": 1e-05,
|
| 21 |
+
"model_type": "mamba2",
|
| 22 |
+
"n_groups": 8,
|
| 23 |
+
"norm_before_gate": true,
|
| 24 |
+
"num_heads": 128,
|
| 25 |
+
"num_hidden_layers": 64,
|
| 26 |
+
"pad_token_id": 0,
|
| 27 |
+
"rescale_prenorm_residual": false,
|
| 28 |
+
"residual_in_fp32": true,
|
| 29 |
+
"rms_norm": true,
|
| 30 |
+
"state_size": 128,
|
| 31 |
+
"tie_word_embeddings": false,
|
| 32 |
+
"time_step_floor": 0.0001,
|
| 33 |
+
"time_step_init_scheme": "random",
|
| 34 |
+
"time_step_limit": [
|
| 35 |
+
0.0,
|
| 36 |
+
{
|
| 37 |
+
"__float__": "Infinity"
|
| 38 |
+
}
|
| 39 |
+
],
|
| 40 |
+
"time_step_max": 0.1,
|
| 41 |
+
"time_step_min": 0.001,
|
| 42 |
+
"time_step_rank": 256,
|
| 43 |
+
"time_step_scale": 1.0,
|
| 44 |
+
"transformers_version": "5.5.0",
|
| 45 |
+
"use_bias": false,
|
| 46 |
+
"use_cache": false,
|
| 47 |
+
"use_conv_bias": true,
|
| 48 |
+
"use_mem_eff_path": true,
|
| 49 |
+
"vocab_size": 32768
|
| 50 |
+
}
|
config_sentence_transformers.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "SentenceTransformer",
|
| 3 |
+
"__version__": {
|
| 4 |
+
"sentence_transformers": "5.4.1",
|
| 5 |
+
"transformers": "5.5.4",
|
| 6 |
+
"pytorch": "2.9.1"
|
| 7 |
+
},
|
| 8 |
+
"prompts": {
|
| 9 |
+
"query": "",
|
| 10 |
+
"document": ""
|
| 11 |
+
},
|
| 12 |
+
"default_prompt_name": null,
|
| 13 |
+
"similarity_fn_name": "cosine"
|
| 14 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7e367c39c7c76e409015a9addae9ddb697ad46e2c30344b6717c40775c66ba65
|
| 3 |
+
size 14302430240
|
modules.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"idx": 0,
|
| 4 |
+
"name": "0",
|
| 5 |
+
"path": "",
|
| 6 |
+
"type": "dynatrace-oss/chunkable-sentence-transformer--models.ChunkableTransformer"
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"idx": 1,
|
| 10 |
+
"name": "1",
|
| 11 |
+
"path": "1_LastIndexPooling",
|
| 12 |
+
"type": "dynatrace-oss/chunkable-sentence-transformer--models.LastIndexPooling"
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"idx": 2,
|
| 16 |
+
"name": "2",
|
| 17 |
+
"path": "2_Normalize",
|
| 18 |
+
"type": "sentence_transformers.models.Normalize"
|
| 19 |
+
}
|
| 20 |
+
]
|
sentence_bert_config.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"do_lower_case": false,
|
| 3 |
+
"output_all_token_embeddings": false
|
| 4 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": true,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"clean_up_tokenization_spaces": false,
|
| 6 |
+
"eos_token": "</s>",
|
| 7 |
+
"is_local": true,
|
| 8 |
+
"pad_token": "</s>",
|
| 9 |
+
"padding_side": "left",
|
| 10 |
+
"sp_model_kwargs": {},
|
| 11 |
+
"spaces_between_special_tokens": false,
|
| 12 |
+
"tokenizer_class": "LlamaTokenizer",
|
| 13 |
+
"unk_token": "<unk>",
|
| 14 |
+
"use_default_system_prompt": false
|
| 15 |
+
}
|