Instructions to use nvidia/Minitron-4B-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nvidia/Minitron-4B-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nvidia/Minitron-4B-Base")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("nvidia/Minitron-4B-Base") model = AutoModelForCausalLM.from_pretrained("nvidia/Minitron-4B-Base") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use nvidia/Minitron-4B-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nvidia/Minitron-4B-Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Minitron-4B-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/nvidia/Minitron-4B-Base
- SGLang
How to use nvidia/Minitron-4B-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/Minitron-4B-Base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Minitron-4B-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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/Minitron-4B-Base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/Minitron-4B-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use nvidia/Minitron-4B-Base with Docker Model Runner:
docker model run hf.co/nvidia/Minitron-4B-Base
Update README
Browse files
README.md
CHANGED
|
@@ -30,22 +30,25 @@ import torch
|
|
| 30 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 31 |
|
| 32 |
# Load the tokenizer and model
|
| 33 |
-
model_path =
|
| 34 |
-
tokenizer
|
| 35 |
|
| 36 |
-
device='cuda'
|
| 37 |
-
dtype=torch.bfloat16
|
| 38 |
-
model
|
| 39 |
|
| 40 |
# Prepare the input text
|
| 41 |
-
prompt =
|
| 42 |
-
|
| 43 |
|
| 44 |
# Generate the output
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# Decode and print the output
|
| 48 |
-
output_text = tokenizer.decode(
|
| 49 |
print(output_text)
|
| 50 |
```
|
| 51 |
|
|
|
|
| 30 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 31 |
|
| 32 |
# Load the tokenizer and model
|
| 33 |
+
model_path = 'nvidia/Minitron-4B-Base'
|
| 34 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 35 |
|
| 36 |
+
device = 'cuda'
|
| 37 |
+
dtype = torch.bfloat16
|
| 38 |
+
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=dtype, device_map=device)
|
| 39 |
|
| 40 |
# Prepare the input text
|
| 41 |
+
prompt = 'Complete the paragraph: our solar system is'
|
| 42 |
+
inputs = tokenizer.encode(prompt, return_tensors='pt').to(model.device)
|
| 43 |
|
| 44 |
# Generate the output
|
| 45 |
+
outputs = model.generate(inputs,
|
| 46 |
+
max_length=20,
|
| 47 |
+
num_return_sequences=1,
|
| 48 |
+
pad_token_id=tokenizer.eos_token_id)
|
| 49 |
|
| 50 |
# Decode and print the output
|
| 51 |
+
output_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 52 |
print(output_text)
|
| 53 |
```
|
| 54 |
|