Text Generation
Transformers
Safetensors
PyTorch
nemotron_h
nvidia
conversational
custom_code
Eval Results
Instructions to use nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Local Apps Settings
- vLLM
How to use nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16" # 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/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16
- SGLang
How to use nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16 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/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16" \ --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/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16", "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/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16" \ --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/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16 with Docker Model Runner:
docker model run hf.co/nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16
Upload modeling_nemotron_h.py
Browse files- modeling_nemotron_h.py +4 -3
modeling_nemotron_h.py
CHANGED
|
@@ -623,8 +623,8 @@ class NemotronHMamba2Mixer(nn.Module):
|
|
| 623 |
hidden_states = hidden_states.reshape(batch_size, seq_len, -1, self.head_dim).float()
|
| 624 |
B = B.reshape(batch_size, seq_len, -1, self.ssm_state_size).float()
|
| 625 |
C = C.reshape(batch_size, seq_len, -1, self.ssm_state_size).float()
|
| 626 |
-
B = B.
|
| 627 |
-
C = C.
|
| 628 |
pad_size = (self.chunk_size - seq_len % self.chunk_size) % self.chunk_size
|
| 629 |
|
| 630 |
D_residual = self.D[..., None] * pad_tensor_by_size(hidden_states, pad_size)
|
|
@@ -852,7 +852,8 @@ class NemotronHMOE(nn.Module):
|
|
| 852 |
final_hidden_states.index_add_(0, token_indices, weighted_output)
|
| 853 |
else:
|
| 854 |
# Local empty expert: no-op compute that still marks params as used.
|
| 855 |
-
|
|
|
|
| 856 |
final_hidden_states = final_hidden_states + dummy_out
|
| 857 |
|
| 858 |
# in original deepseek, the output of the experts are gathered once we leave this module
|
|
|
|
| 623 |
hidden_states = hidden_states.reshape(batch_size, seq_len, -1, self.head_dim).float()
|
| 624 |
B = B.reshape(batch_size, seq_len, -1, self.ssm_state_size).float()
|
| 625 |
C = C.reshape(batch_size, seq_len, -1, self.ssm_state_size).float()
|
| 626 |
+
B = B.repeat_interleave(self.num_heads // self.n_groups, dim=2, output_size=self.num_heads)
|
| 627 |
+
C = C.repeat_interleave(self.num_heads // self.n_groups, dim=2, output_size=self.num_heads)
|
| 628 |
pad_size = (self.chunk_size - seq_len % self.chunk_size) % self.chunk_size
|
| 629 |
|
| 630 |
D_residual = self.D[..., None] * pad_tensor_by_size(hidden_states, pad_size)
|
|
|
|
| 852 |
final_hidden_states.index_add_(0, token_indices, weighted_output)
|
| 853 |
else:
|
| 854 |
# Local empty expert: no-op compute that still marks params as used.
|
| 855 |
+
expert_dtype = expert.down_proj.weight.dtype
|
| 856 |
+
dummy_out = expert(torch.zeros_like(hidden_states[0]).unsqueeze(0).to(expert_dtype))
|
| 857 |
final_hidden_states = final_hidden_states + dummy_out
|
| 858 |
|
| 859 |
# in original deepseek, the output of the experts are gathered once we leave this module
|