|
|
--- |
|
|
library_name: sentence-transformers |
|
|
pipeline_tag: sentence-similarity |
|
|
tags: |
|
|
- sentence-transformers |
|
|
- sentence-similarity |
|
|
- feature-extraction |
|
|
license: apache-2.0 |
|
|
datasets: |
|
|
- nomic-ai/cornstack-python-v1 |
|
|
- nomic-ai/cornstack-javascript-v1 |
|
|
- nomic-ai/cornstack-java-v1 |
|
|
- nomic-ai/cornstack-go-v1 |
|
|
- nomic-ai/cornstack-php-v1 |
|
|
- nomic-ai/cornstack-ruby-v1 |
|
|
base_model: |
|
|
- Qwen/Qwen2.5-Coder-7B-Instruct |
|
|
--- |
|
|
|
|
|
# <span style="color: #7FFF7F;">nomic-embed-code GGUF Models</span> |
|
|
|
|
|
|
|
|
## <span style="color: #7F7FFF;">Model Generation Details</span> |
|
|
|
|
|
This model was generated using [llama.cpp](https://github.com/ggerganov/llama.cpp) at commit [`7f4fbe51`](https://github.com/ggerganov/llama.cpp/commit/7f4fbe5183b23b6b2e25fd1ccc5d1fa8bb010cb7). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## <span style="color: #7FFF7F;"> Quantization beyond the IMatrix</span> |
|
|
|
|
|
Testing a new quantization method using rules to bump important layers above what the standard imatrix would use. |
|
|
|
|
|
I have found that the standard IMatrix does not perform very well at low bit quantiztion and for MOE models. So I am using llama.cpp --tensor-type to bump up selected layers. See [Layer bumping with llama.cpp](https://github.com/Mungert69/GGUFModelBuilder/blob/main/model-converter/tensor_list_builder.py) |
|
|
|
|
|
This does create larger model files but increases precision for a given model size. |
|
|
|
|
|
### **Please provide feedback on how you find this method performs** |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## **Choosing the Right Model Format** |
|
|
|
|
|
Selecting the correct model format depends on your **hardware capabilities** and **memory constraints**. |
|
|
|
|
|
### **BF16 (Brain Float 16) – Use if BF16 acceleration is available** |
|
|
- A 16-bit floating-point format designed for **faster computation** while retaining good precision. |
|
|
- Provides **similar dynamic range** as FP32 but with **lower memory usage**. |
|
|
- Recommended if your hardware supports **BF16 acceleration** (check your device's specs). |
|
|
- Ideal for **high-performance inference** with **reduced memory footprint** compared to FP32. |
|
|
|
|
|
📌 **Use BF16 if:** |
|
|
✔ Your hardware has native **BF16 support** (e.g., newer GPUs, TPUs). |
|
|
✔ You want **higher precision** while saving memory. |
|
|
✔ You plan to **requantize** the model into another format. |
|
|
|
|
|
📌 **Avoid BF16 if:** |
|
|
❌ Your hardware does **not** support BF16 (it may fall back to FP32 and run slower). |
|
|
❌ You need compatibility with older devices that lack BF16 optimization. |
|
|
|
|
|
--- |
|
|
|
|
|
### **F16 (Float 16) – More widely supported than BF16** |
|
|
- A 16-bit floating-point **high precision** but with less of range of values than BF16. |
|
|
- Works on most devices with **FP16 acceleration support** (including many GPUs and some CPUs). |
|
|
- Slightly lower numerical precision than BF16 but generally sufficient for inference. |
|
|
|
|
|
📌 **Use F16 if:** |
|
|
✔ Your hardware supports **FP16** but **not BF16**. |
|
|
✔ You need a **balance between speed, memory usage, and accuracy**. |
|
|
✔ You are running on a **GPU** or another device optimized for FP16 computations. |
|
|
|
|
|
📌 **Avoid F16 if:** |
|
|
❌ Your device lacks **native FP16 support** (it may run slower than expected). |
|
|
❌ You have memory limitations. |
|
|
|
|
|
--- |
|
|
|
|
|
### **Hybrid Precision Models (e.g., `bf16_q8_0`, `f16_q4_K`) – Best of Both Worlds** |
|
|
These formats selectively **quantize non-essential layers** while keeping **key layers in full precision** (e.g., attention and output layers). |
|
|
|
|
|
- Named like `bf16_q8_0` (meaning **full-precision BF16 core layers + quantized Q8_0 other layers**). |
|
|
- Strike a **balance between memory efficiency and accuracy**, improving over fully quantized models without requiring the full memory of BF16/F16. |
|
|
|
|
|
📌 **Use Hybrid Models if:** |
|
|
✔ You need **better accuracy than quant-only models** but can’t afford full BF16/F16 everywhere. |
|
|
✔ Your device supports **mixed-precision inference**. |
|
|
✔ You want to **optimize trade-offs** for production-grade models on constrained hardware. |
|
|
|
|
|
📌 **Avoid Hybrid Models if:** |
|
|
❌ Your target device doesn’t support **mixed or full-precision acceleration**. |
|
|
❌ You are operating under **ultra-strict memory limits** (in which case use fully quantized formats). |
|
|
|
|
|
--- |
|
|
|
|
|
### **Quantized Models (Q4_K, Q6_K, Q8, etc.) – For CPU & Low-VRAM Inference** |
|
|
Quantization reduces model size and memory usage while maintaining as much accuracy as possible. |
|
|
- **Lower-bit models (Q4_K)** → **Best for minimal memory usage**, may have lower precision. |
|
|
- **Higher-bit models (Q6_K, Q8_0)** → **Better accuracy**, requires more memory. |
|
|
|
|
|
📌 **Use Quantized Models if:** |
|
|
✔ You are running inference on a **CPU** and need an optimized model. |
|
|
✔ Your device has **low VRAM** and cannot load full-precision models. |
|
|
✔ You want to reduce **memory footprint** while keeping reasonable accuracy. |
|
|
|
|
|
📌 **Avoid Quantized Models if:** |
|
|
❌ You need **maximum accuracy** (full-precision models are better for this). |
|
|
❌ Your hardware has enough VRAM for higher-precision formats (BF16/F16). |
|
|
|
|
|
--- |
|
|
|
|
|
### **Very Low-Bit Quantization (IQ3_XS, IQ3_S, IQ3_M, Q4_K, Q4_0)** |
|
|
These models are optimized for **very high memory efficiency**, making them ideal for **low-power devices** or **large-scale deployments** where memory is a critical constraint. |
|
|
|
|
|
- **IQ3_XS**: Ultra-low-bit quantization (3-bit) with **very high memory efficiency**. |
|
|
- **Use case**: Best for **ultra-low-memory devices** where even Q4_K is too large. |
|
|
- **Trade-off**: Lower accuracy compared to higher-bit quantizations. |
|
|
|
|
|
- **IQ3_S**: Small block size for **maximum memory efficiency**. |
|
|
- **Use case**: Best for **low-memory devices** where **IQ3_XS** is too aggressive. |
|
|
|
|
|
- **IQ3_M**: Medium block size for better accuracy than **IQ3_S**. |
|
|
- **Use case**: Suitable for **low-memory devices** where **IQ3_S** is too limiting. |
|
|
|
|
|
- **Q4_K**: 4-bit quantization with **block-wise optimization** for better accuracy. |
|
|
- **Use case**: Best for **low-memory devices** where **Q6_K** is too large. |
|
|
|
|
|
- **Q4_0**: Pure 4-bit quantization, optimized for **ARM devices**. |
|
|
- **Use case**: Best for **ARM-based devices** or **low-memory environments**. |
|
|
|
|
|
### **Ultra Low-Bit Quantization (IQ1_S IQ1_M IQ2_S IQ2_M IQ2_XS IQ2_XSS)** |
|
|
- *Ultra-low-bit quantization (1 2-bit) with **extreme memory efficiency**. |
|
|
- **Use case**: Best for cases were you have to fit the model into very constrained memory |
|
|
- **Trade-off**: Very Low Accuracy. May not function as expected. Please test fully before using. |
|
|
|
|
|
--- |
|
|
|
|
|
### **Summary Table: Model Format Selection** |
|
|
|
|
|
|
|
|
| Model Format | Precision | Memory Usage | Device Requirements | Best Use Case | |
|
|
|--------------------------|------------------|------------------|----------------------------------|--------------------------------------------------------------| |
|
|
| **BF16** | Very High | High | BF16-supported GPU/CPU | High-speed inference with reduced memory | |
|
|
| **F16** | High | High | FP16-supported GPU/CPU | Inference when BF16 isn’t available | |
|
|
| **Q4_K** | Medium-Low | Low | CPU or Low-VRAM devices | Memory-constrained inference | |
|
|
| **Q6_K** | Medium | Moderate | CPU with more memory | Better accuracy with quantization | |
|
|
| **Q8_0** | High | Moderate | GPU/CPU with moderate VRAM | Highest accuracy among quantized models | |
|
|
| **IQ3_XS** | Low | Very Low | Ultra-low-memory devices | Max memory efficiency, low accuracy | |
|
|
| **IQ3_S** | Low | Very Low | Low-memory devices | Slightly more usable than IQ3_XS | |
|
|
| **IQ3_M** | Low-Medium | Low | Low-memory devices | Better accuracy than IQ3_S | |
|
|
| **Q4_0** | Low | Low | ARM-based/embedded devices | Llama.cpp automatically optimizes for ARM inference | |
|
|
| **Ultra Low-Bit (IQ1/2_*)** | Very Low | Extremely Low | Tiny edge/embedded devices | Fit models in extremely tight memory; low accuracy | |
|
|
| **Hybrid (e.g., `bf16_q8_0`)** | Medium–High | Medium | Mixed-precision capable hardware | Balanced performance and memory, near-FP accuracy in critical layers | |
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Nomic Embed Code: A State-of-the-Art Code Retriever |
|
|
|
|
|
[Blog](https://www.nomic.ai/blog/posts/introducing-state-of-the-art-nomic-embed-code) | [Technical Report](https://arxiv.org/abs/2412.01007) | [AWS SageMaker](https://aws.amazon.com/marketplace/seller-profile?id=seller-tpqidcj54zawi) | [Atlas Embedding and Unstructured Data Analytics Platform](https://atlas.nomic.ai) |
|
|
|
|
|
|
|
|
`nomic-embed-code` is a state-of-the-art code embedding model that excels at code retrieval tasks: |
|
|
|
|
|
- **High Performance**: Outperforms Voyage Code 3 and OpenAI Embed 3 Large on CodeSearchNet |
|
|
- **Multilingual Code Support**: Trained for multiple programming languages (Python, Java, Ruby, PHP, JavaScript, Go) |
|
|
- **Advanced Architecture**: 7B parameter code embedding model |
|
|
- **Fully Open-Source**: Model weights, training data, and [evaluation code](https://github.com/gangiswag/cornstack/) released |
|
|
|
|
|
| Model | Python | Java | Ruby | PHP | JavaScript | Go | |
|
|
|-------|--------|------|------|-----|------------|-----| |
|
|
| **Nomic Embed Code** | **81.7** | **80.5** | 81.8 | **72.3** | 77.1 | **93.8** | |
|
|
| Voyage Code 3 | 80.8 | **80.5** | **84.6** | 71.7 | **79.2** | 93.2 | |
|
|
| OpenAI Embed 3 Large | 70.8 | 72.9 | 75.3 | 59.6 | 68.1 | 87.6 | |
|
|
| Nomic CodeRankEmbed-137M | 78.4 | 76.9 | 79.3 | 68.8 | 71.4 | 92.7 | |
|
|
| CodeSage Large v2 (1B) | 74.2 | 72.3 | 76.7 | 65.2 | 72.5 | 84.6 | |
|
|
| CodeSage Large (1B) | 70.8 | 70.2 | 71.9 | 61.3 | 69.5 | 83.7 | |
|
|
| Qodo Embed 1 7B | 59.9 | 61.6 | 68.4 | 48.5 | 57.0 | 81.4 | |
|
|
|
|
|
## Model Architecture |
|
|
|
|
|
- **Total Parameters**: 7B |
|
|
- **Training Approach**: Trained on the CoRNStack dataset with dual-consistency filtering and progressive hard negative mining |
|
|
- **Supported Languages**: Python, Java, Ruby, PHP, JavaScript, and Go |
|
|
|
|
|
## Usage Guide |
|
|
|
|
|
### Installation |
|
|
|
|
|
You can install the necessary dependencies with: |
|
|
|
|
|
```bash |
|
|
pip install transformers sentence-transformers torch |
|
|
``` |
|
|
|
|
|
### Transformers |
|
|
|
|
|
```python |
|
|
import torch |
|
|
import torch.nn.functional as F |
|
|
from transformers import AutoTokenizer, AutoModel |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("nomic-ai/nomic-embed-code") |
|
|
model = AutoModel.from_pretrained("nomic-ai/nomic-embed-code") |
|
|
|
|
|
def last_token_pooling(hidden_states, attention_mask): |
|
|
sequence_lengths = attention_mask.sum(-1) - 1 |
|
|
return hidden_states[torch.arange(hidden_states.shape[0]), sequence_lengths] |
|
|
|
|
|
queries = ['Represent this query for searching relevant code: Calculate the n-th factorial'] |
|
|
codes = ['def fact(n):\n if n < 0:\n raise ValueError\n return 1 if n == 0 else n * fact(n - 1)'] |
|
|
code_snippets = queries + codes |
|
|
|
|
|
encoded_input = tokenizer(code_snippets, padding=True, truncation=True, return_tensors='pt') |
|
|
model.eval() |
|
|
with torch.no_grad(): |
|
|
model_output = model(**encoded_input)[0] |
|
|
|
|
|
embeddings = last_token_pooling(model_output, encoded_input['attention_mask']) |
|
|
embeddings = F.normalize(embeddings, p=2, dim=1) |
|
|
print(embeddings.shape) |
|
|
|
|
|
similarity = F.cosine_similarity(embeddings[0], embeddings[1], dim=0) |
|
|
print(similarity) |
|
|
``` |
|
|
|
|
|
### SentenceTransformers |
|
|
|
|
|
```python |
|
|
from sentence_transformers import SentenceTransformer |
|
|
|
|
|
queries = ['Calculate the n-th factorial'] |
|
|
code_snippets = ['def fact(n):\n if n < 0:\n raise ValueError\n return 1 if n == 0 else n * fact(n - 1)'] |
|
|
|
|
|
model = SentenceTransformer("nomic-ai/nomic-embed-code") |
|
|
query_emb = model.encode(queries, prompt_name="query") |
|
|
code_emb = model.encode(code_snippets) |
|
|
|
|
|
similarity = model.similarity(query_emb[0], code_emb[0]) |
|
|
print(similarity) |
|
|
``` |
|
|
|
|
|
|
|
|
### CoRNStack Dataset Curation |
|
|
|
|
|
Starting with the deduplicated Stackv2, we create text-code pairs from function docstrings and respective code. We filtered out low-quality pairs where the docstring wasn't English, too short, or that contained URLs, HTML tags, or invalid characters. We additionally kept docstrings with text lengths of 256 tokens or longer to help the model learn long-range dependencies. |
|
|
|
|
|
|
|
|
 |
|
|
|
|
|
After the initial filtering, we used dual-consistency filtering to remove potentially noisy examples. We embed each docstring and code pair and compute the similarity between each docstring and every code example. We remove pairs from the dataset if the corresponding code example is not found in the top-2 most similar examples for a given docstring. |
|
|
|
|
|
During training, we employ a novel curriculum-based hard negative mining strategy to ensure the model learns from challenging examples. We use a softmax-based sampling strategy to progressively sample hard negatives with increasing difficulty over time. |
|
|
|
|
|
|
|
|
## Join the Nomic Community |
|
|
|
|
|
- Nomic Embed Ecosystem: [https://www.nomic.ai/embed](https://www.nomic.ai/embed) |
|
|
- Website: [https://nomic.ai](https://nomic.ai) |
|
|
- Twitter: [https://twitter.com/nomic_ai](https://twitter.com/nomic_ai) |
|
|
- Discord: [https://discord.gg/myY5YDR8z8](https://discord.gg/myY5YDR8z8) |
|
|
|
|
|
# Citation |
|
|
|
|
|
If you find the model, dataset, or training code useful, please cite our work: |
|
|
|
|
|
```bibtex |
|
|
@misc{suresh2025cornstackhighqualitycontrastivedata, |
|
|
title={CoRNStack: High-Quality Contrastive Data for Better Code Retrieval and Reranking}, |
|
|
author={Tarun Suresh and Revanth Gangi Reddy and Yifei Xu and Zach Nussbaum and Andriy Mulyar and Brandon Duderstadt and Heng Ji}, |
|
|
year={2025}, |
|
|
eprint={2412.01007}, |
|
|
archivePrefix={arXiv}, |
|
|
primaryClass={cs.CL}, |
|
|
url={https://arxiv.org/abs/2412.01007}, |
|
|
} |
|
|
``` |
|
|
# <span id="testllm" style="color: #7F7FFF;">🚀 If you find these models useful</span> |
|
|
|
|
|
Help me test my **AI-Powered Quantum Network Monitor Assistant** with **quantum-ready security checks**: |
|
|
|
|
|
👉 [Quantum Network Monitor](https://readyforquantum.com/?assistant=open&utm_source=huggingface&utm_medium=referral&utm_campaign=huggingface_repo_readme) |
|
|
|
|
|
|
|
|
The full Open Source Code for the Quantum Network Monitor Service available at my github repos ( repos with NetworkMonitor in the name) : [Source Code Quantum Network Monitor](https://github.com/Mungert69). You will also find the code I use to quantize the models if you want to do it yourself [GGUFModelBuilder](https://github.com/Mungert69/GGUFModelBuilder) |
|
|
|
|
|
💬 **How to test**: |
|
|
Choose an **AI assistant type**: |
|
|
- `TurboLLM` (GPT-4.1-mini) |
|
|
- `HugLLM` (Hugginface Open-source models) |
|
|
- `TestLLM` (Experimental CPU-only) |
|
|
|
|
|
### **What I’m Testing** |
|
|
I’m pushing the limits of **small open-source models for AI network monitoring**, specifically: |
|
|
- **Function calling** against live network services |
|
|
- **How small can a model go** while still handling: |
|
|
- Automated **Nmap security scans** |
|
|
- **Quantum-readiness checks** |
|
|
- **Network Monitoring tasks** |
|
|
|
|
|
🟡 **TestLLM** – Current experimental model (llama.cpp on 2 CPU threads on huggingface docker space): |
|
|
- ✅ **Zero-configuration setup** |
|
|
- ⏳ 30s load time (slow inference but **no API costs**) . No token limited as the cost is low. |
|
|
- 🔧 **Help wanted!** If you’re into **edge-device AI**, let’s collaborate! |
|
|
|
|
|
### **Other Assistants** |
|
|
🟢 **TurboLLM** – Uses **gpt-4.1-mini** : |
|
|
- **It performs very well but unfortunatly OpenAI charges per token. For this reason tokens usage is limited. |
|
|
- **Create custom cmd processors to run .net code on Quantum Network Monitor Agents** |
|
|
- **Real-time network diagnostics and monitoring** |
|
|
- **Security Audits** |
|
|
- **Penetration testing** (Nmap/Metasploit) |
|
|
|
|
|
🔵 **HugLLM** – Latest Open-source models: |
|
|
- 🌐 Runs on Hugging Face Inference API. Performs pretty well using the lastest models hosted on Novita. |
|
|
|
|
|
### 💡 **Example commands you could test**: |
|
|
1. `"Give me info on my websites SSL certificate"` |
|
|
2. `"Check if my server is using quantum safe encyption for communication"` |
|
|
3. `"Run a comprehensive security audit on my server"` |
|
|
4. '"Create a cmd processor to .. (what ever you want)" Note you need to install a Quantum Network Monitor Agent to run the .net code from. This is a very flexible and powerful feature. Use with caution! |
|
|
|
|
|
### Final Word |
|
|
|
|
|
I fund the servers used to create these model files, run the Quantum Network Monitor service, and pay for inference from Novita and OpenAI—all out of my own pocket. All the code behind the model creation and the Quantum Network Monitor project is [open source](https://github.com/Mungert69). Feel free to use whatever you find helpful. |
|
|
|
|
|
If you appreciate the work, please consider [buying me a coffee](https://www.buymeacoffee.com/mahadeva) ☕. Your support helps cover service costs and allows me to raise token limits for everyone. |
|
|
|
|
|
I'm also open to job opportunities or sponsorship. |
|
|
|
|
|
Thank you! 😊 |
|
|
|