Text Generation
Transformers
Safetensors
PyTorch
nemotron_labs_diffusion
feature-extraction
nvidia
conversational
custom_code
Instructions to use nvidia/Nemotron-Labs-Diffusion-8B-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nvidia/Nemotron-Labs-Diffusion-8B-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nvidia/Nemotron-Labs-Diffusion-8B-Base", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("nvidia/Nemotron-Labs-Diffusion-8B-Base", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use nvidia/Nemotron-Labs-Diffusion-8B-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nvidia/Nemotron-Labs-Diffusion-8B-Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Nemotron-Labs-Diffusion-8B-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/nvidia/Nemotron-Labs-Diffusion-8B-Base
- SGLang
How to use nvidia/Nemotron-Labs-Diffusion-8B-Base with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "nvidia/Nemotron-Labs-Diffusion-8B-Base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Nemotron-Labs-Diffusion-8B-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "nvidia/Nemotron-Labs-Diffusion-8B-Base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Nemotron-Labs-Diffusion-8B-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use nvidia/Nemotron-Labs-Diffusion-8B-Base with Docker Model Runner:
docker model run hf.co/nvidia/Nemotron-Labs-Diffusion-8B-Base
Overriding the old function doesn't work, reverting to old approach
Browse files- modeling_ministral.py +6 -5
modeling_ministral.py
CHANGED
|
@@ -27,7 +27,7 @@ from transformers.utils import TransformersKwargs, auto_docstring, can_return_tu
|
|
| 27 |
# from transformers.utils.generic import maybe_autocast
|
| 28 |
from .configuration_ministral_dlm import MinistralDLMConfig
|
| 29 |
|
| 30 |
-
ALL_MASK_ATTENTION_FUNCTIONS._global_mapping['sdpa'] = sdpa_mask_older_torch
|
| 31 |
|
| 32 |
def rotate_half(x):
|
| 33 |
"""Rotates half the hidden dims of the input."""
|
|
@@ -418,10 +418,9 @@ class Ministral3Model(Ministral3PreTrainedModel):
|
|
| 418 |
if position_ids is None:
|
| 419 |
position_ids = cache_position.unsqueeze(0)
|
| 420 |
|
| 421 |
-
if self.training:
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
else:
|
| 425 |
mask_function = create_causal_mask if self.config.sliding_window is None else create_sliding_window_causal_mask
|
| 426 |
causal_mask = mask_function(
|
| 427 |
config=self.config,
|
|
@@ -431,6 +430,8 @@ class Ministral3Model(Ministral3PreTrainedModel):
|
|
| 431 |
past_key_values=past_key_values,
|
| 432 |
position_ids=position_ids,
|
| 433 |
)
|
|
|
|
|
|
|
| 434 |
|
| 435 |
hidden_states = inputs_embeds
|
| 436 |
position_embeddings = self.rotary_emb(hidden_states, position_ids=position_ids)
|
|
|
|
| 27 |
# from transformers.utils.generic import maybe_autocast
|
| 28 |
from .configuration_ministral_dlm import MinistralDLMConfig
|
| 29 |
|
| 30 |
+
#ALL_MASK_ATTENTION_FUNCTIONS._global_mapping['sdpa'] = sdpa_mask_older_torch
|
| 31 |
|
| 32 |
def rotate_half(x):
|
| 33 |
"""Rotates half the hidden dims of the input."""
|
|
|
|
| 418 |
if position_ids is None:
|
| 419 |
position_ids = cache_position.unsqueeze(0)
|
| 420 |
|
| 421 |
+
#if self.training:
|
| 422 |
+
# causal_mask = None
|
| 423 |
+
if kwargs.get("use_causal_mask", False):
|
|
|
|
| 424 |
mask_function = create_causal_mask if self.config.sliding_window is None else create_sliding_window_causal_mask
|
| 425 |
causal_mask = mask_function(
|
| 426 |
config=self.config,
|
|
|
|
| 430 |
past_key_values=past_key_values,
|
| 431 |
position_ids=position_ids,
|
| 432 |
)
|
| 433 |
+
else:
|
| 434 |
+
causal_mask = None
|
| 435 |
|
| 436 |
hidden_states = inputs_embeds
|
| 437 |
position_embeddings = self.rotary_emb(hidden_states, position_ids=position_ids)
|