sentence-transformers
Safetensors
English
nomic_bert
flash-attention
code-retrieval
nomic-bert
bf16
custom_code
Instructions to use handwoven8588/CodeRankEmbed-flash-attn with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use handwoven8588/CodeRankEmbed-flash-attn with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("handwoven8588/CodeRankEmbed-flash-attn", trust_remote_code=True) 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] - Notebooks
- Google Colab
- Kaggle
README: reframe bf16 weights — reason is flash_attn half-precision + runtime-bf16 (not download size)
Browse files
README.md
CHANGED
|
@@ -32,11 +32,12 @@ itself, so no runtime patching or post-load hooks are needed.
|
|
| 32 |
|
| 33 |
## Behavior
|
| 34 |
|
| 35 |
-
- **Loads bf16 by default.**
|
| 36 |
-
`config.json` declares `torch_dtype:
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
| 40 |
- **CUDA + `flash_attn`** → flash-varlen path (fast, low VRAM). Attention tensors are cast to bf16
|
| 41 |
internally as a safety net; with the default bf16 load this is a no-op.
|
| 42 |
- **CPU, or no `flash_attn`** → the original eager attention algorithm runs unchanged. Because the
|
|
@@ -78,7 +79,11 @@ also scales to far larger batches (bs=256 fits in ~7.6 GB) where eager O(seq²)
|
|
| 78 |
|
| 79 |
## What changed vs the source repo
|
| 80 |
|
| 81 |
-
1. **Weights**: fp32 → bf16
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
2. **`from_pretrained` dtype fix**: the upstream custom `from_pretrained` instantiated the model
|
| 83 |
fp32 and `load_state_dict`-ed the checkpoint into fp32 params, **ignoring `torch_dtype`**. The
|
| 84 |
copy here adds the standard transformers dtype resolution (explicit arg → `config.torch_dtype` →
|
|
|
|
| 32 |
|
| 33 |
## Behavior
|
| 34 |
|
| 35 |
+
- **Loads bf16 by default.** `flash_attn` requires half precision and the model runs bf16 in any
|
| 36 |
+
real serving setup, so the weights are stored bf16 and `config.json` declares `torch_dtype:
|
| 37 |
+
bfloat16`. The upstream custom `from_pretrained` silently dropped `torch_dtype` and always loaded
|
| 38 |
+
fp32; the copy in this repo honors it, so the model loads bf16 natively, like any normal HF
|
| 39 |
+
model. Pass `torch_dtype=torch.float32` to load fp32 (note: the stored weights are bf16-precision,
|
| 40 |
+
so this only widens the dtype, not the precision).
|
| 41 |
- **CUDA + `flash_attn`** → flash-varlen path (fast, low VRAM). Attention tensors are cast to bf16
|
| 42 |
internally as a safety net; with the default bf16 load this is a no-op.
|
| 43 |
- **CPU, or no `flash_attn`** → the original eager attention algorithm runs unchanged. Because the
|
|
|
|
| 79 |
|
| 80 |
## What changed vs the source repo
|
| 81 |
|
| 82 |
+
1. **Weights**: fp32 → bf16. `flash_attn` only accepts half precision and the model runs bf16 in
|
| 83 |
+
any real serving configuration, so the weights are stored bf16 and (via the load fix below)
|
| 84 |
+
arrive bf16 — which is simply how this model is used, and removes the need for a post-load dtype
|
| 85 |
+
cast. Parity-neutral (cosine 0.9986 vs the fp32 original); the smaller download is incidental,
|
| 86 |
+
not the reason.
|
| 87 |
2. **`from_pretrained` dtype fix**: the upstream custom `from_pretrained` instantiated the model
|
| 88 |
fp32 and `load_state_dict`-ed the checkpoint into fp32 params, **ignoring `torch_dtype`**. The
|
| 89 |
copy here adds the standard transformers dtype resolution (explicit arg → `config.torch_dtype` →
|