Text Ranking
Safetensors
Transformers
vllm
mistral3
text-classification
reranker
cross-encoder
visual-document-retrieval
multimodal reranking
semantic-search
rag
8-bit precision
compressed-tensors
Instructions to use nvidia/Nemotron-3.5-Rerank-8B-NVFP4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nvidia/Nemotron-3.5-Rerank-8B-NVFP4 with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForSequenceClassification processor = AutoProcessor.from_pretrained("nvidia/Nemotron-3.5-Rerank-8B-NVFP4") model = AutoModelForSequenceClassification.from_pretrained("nvidia/Nemotron-3.5-Rerank-8B-NVFP4", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Remove the unused Transformers shim
#1
by oliverholworthy - opened
- config.json +0 -3
- model.py +0 -30
config.json
CHANGED
|
@@ -2,9 +2,6 @@
|
|
| 2 |
"architectures": [
|
| 3 |
"Mistral3ForSequenceClassification"
|
| 4 |
],
|
| 5 |
-
"auto_map": {
|
| 6 |
-
"AutoModelForSequenceClassification": "model.Mistral3ForSequenceClassification"
|
| 7 |
-
},
|
| 8 |
"dtype": "bfloat16",
|
| 9 |
"id2label": {
|
| 10 |
"0": "LABEL_0"
|
|
|
|
| 2 |
"architectures": [
|
| 3 |
"Mistral3ForSequenceClassification"
|
| 4 |
],
|
|
|
|
|
|
|
|
|
|
| 5 |
"dtype": "bfloat16",
|
| 6 |
"id2label": {
|
| 7 |
"0": "LABEL_0"
|
model.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
| 1 |
-
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
| 2 |
-
# SPDX-License-Identifier: OpenMDW-1.1
|
| 3 |
-
|
| 4 |
-
import torch
|
| 5 |
-
from torch import nn
|
| 6 |
-
from transformers import Mistral3Config, Mistral3Model
|
| 7 |
-
from transformers.models.mistral3.modeling_mistral3 import Mistral3PreTrainedModel
|
| 8 |
-
from transformers.modeling_outputs import SequenceClassifierOutputWithPast
|
| 9 |
-
from transformers.conversion_mapping import register_checkpoint_conversion_mapping, WeightRenaming
|
| 10 |
-
|
| 11 |
-
class Mistral3ForSequenceClassification(Mistral3PreTrainedModel):
|
| 12 |
-
config_class = Mistral3Config
|
| 13 |
-
base_model_prefix = "model"
|
| 14 |
-
def __init__(self, config):
|
| 15 |
-
super().__init__(config)
|
| 16 |
-
self.model = Mistral3Model(config)
|
| 17 |
-
self.score = nn.Linear(config.text_config.hidden_size, 1, bias=False)
|
| 18 |
-
self.post_init()
|
| 19 |
-
def forward(self, input_ids=None, attention_mask=None, pixel_values=None, image_sizes=None, position_ids=None, **kwargs):
|
| 20 |
-
outputs = self.model(input_ids=input_ids, attention_mask=attention_mask, pixel_values=pixel_values, image_sizes=image_sizes, position_ids=position_ids, **kwargs)
|
| 21 |
-
hidden = outputs.last_hidden_state
|
| 22 |
-
pooled = hidden.masked_fill(~attention_mask[..., None].bool(), 0).sum(1) / attention_mask.sum(1)[:,None]
|
| 23 |
-
logits = torch.nn.functional.linear(pooled.float(), self.score.weight.float())
|
| 24 |
-
return SequenceClassifierOutputWithPast(logits=logits)
|
| 25 |
-
|
| 26 |
-
register_checkpoint_conversion_mapping(
|
| 27 |
-
'Mistral3ForSequenceClassification',
|
| 28 |
-
[WeightRenaming(source_patterns=r'^language_model\.score\.weight$', target_patterns='score.weight')],
|
| 29 |
-
overwrite=True,
|
| 30 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|