Instructions to use dynatrace-oss/chunkable-sentence-transformer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use dynatrace-oss/chunkable-sentence-transformer with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("dynatrace-oss/chunkable-sentence-transformer") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Transformers
How to use dynatrace-oss/chunkable-sentence-transformer with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("dynatrace-oss/chunkable-sentence-transformer", device_map="auto") - Notebooks
- Google Colab
- Kaggle
chunkable-sentence-transformer
Custom Sentence Transformers modules that add support for vertically chunked inference to encode arbitrarily long texts with constant memory by processing fixed-size vertical chunks through all model layers sequentially.
What this repository provides
ExtendedTransformer: extends the Sentence TransformersTransformermodule with explicituse_cacheandcachearguments. The model's cache (past_key_values/cache_params) is returned asfeatures["cache"]whenever the model produces one, so recurrent states can carry across chunks.ExtendedPooling: extends the Sentence TransformersPoolingmodule so padded inputs are pooled from per-sequence accumulators. The accumulators are itscache, so the pooled embedding can be updated chunk by chunk. A single call without a cache gives the same result as upstreamPooling. Supports the upstream pooling modes (mean,mean_sqrt_len_tokens,weightedmean,max,cls,lasttoken).ChunkedModule: wraps a sequence of modules and, whenvertical_chunk_sizeis passed toencode, splits the input into chunks, runs each chunk through the full stack while carrying each module's cache forward, and returns the last chunk's sentence embedding.
Modules inside a ChunkedModule declare use_cache and cache explicitly (**kwargs does not count) and return their cache as features["cache"]. Modules that declare neither are treated as stateless, like Normalize.
Per-token embeddings are not reassembled by default, since that would bring back the full-length memory that chunking avoids. Pass return_token_embeddings=True to the ChunkedModule's forward to get them back.
Chunked inference is not supported for flattened/packed inputs (cu_seq_lens_q), those fall back to the unchunked forward with a warning.
Usage
This repository is designed to be referenced directly from Hugging Face model configs via modules.json, so that models can be loaded with trust_remote_code=True without any local installation.
Constant-memory inference is then available via the vertical_chunk_size encode parameter:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer(
"dynatrace-oss/llama-embed-mamba2-7b", trust_remote_code=True
)
embeddings = model.encode(["Your long document text here..."], vertical_chunk_size=512)
A checkpoint uses a ChunkedModule around the transformer and pooling, followed by the rest of the pipeline in modules.json:
[
{"idx": 0, "name": "0", "path": "", "type": "dynatrace-oss/chunkable-sentence-transformer--modules.ChunkedModule"},
{"idx": 1, "name": "1", "path": "1_Normalize", "type": "sentence_transformers.models.Normalize"}
]
The chunked part lists the transformer and the pooling in modules_chunked.json:
[
{"idx": 0, "name": "0", "path": "", "type": "dynatrace-oss/chunkable-sentence-transformer--modules.ExtendedTransformer"},
{"idx": 1, "name": "1", "path": "1_Pooling", "type": "dynatrace-oss/chunkable-sentence-transformer--modules.ExtendedPooling"}
]
Requirements
pip install sentence-transformers==6.2.0
Models
This code was created for the following embedding models:
License
Apache-2.0