Instructions to use himalaya-ai/himalayagpt-0.5b-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use himalaya-ai/himalayagpt-0.5b-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="himalaya-ai/himalayagpt-0.5b-it", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("himalaya-ai/himalayagpt-0.5b-it", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("himalaya-ai/himalayagpt-0.5b-it", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use himalaya-ai/himalayagpt-0.5b-it with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "himalaya-ai/himalayagpt-0.5b-it" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "himalaya-ai/himalayagpt-0.5b-it", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/himalaya-ai/himalayagpt-0.5b-it
- SGLang
How to use himalaya-ai/himalayagpt-0.5b-it 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 "himalaya-ai/himalayagpt-0.5b-it" \ --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": "himalaya-ai/himalayagpt-0.5b-it", "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 "himalaya-ai/himalayagpt-0.5b-it" \ --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": "himalaya-ai/himalayagpt-0.5b-it", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use himalaya-ai/himalayagpt-0.5b-it with Docker Model Runner:
docker model run hf.co/himalaya-ai/himalayagpt-0.5b-it
Handle Colab meta-tensor load path with automatic device_map fallback
Browse files- run_standalone_inference.py +26 -1
run_standalone_inference.py
CHANGED
|
@@ -154,6 +154,18 @@ def _top_k_filter(logits, top_k: int):
|
|
| 154 |
return masked
|
| 155 |
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
def generate_compat(model, input_ids, max_new_tokens: int, temperature: float, top_k: int, seed: int):
|
| 158 |
import torch
|
| 159 |
import torch.nn.functional as F
|
|
@@ -212,7 +224,20 @@ def main() -> None:
|
|
| 212 |
low_cpu_mem_usage=bool(device.type == "cuda" and args.use_device_map),
|
| 213 |
)
|
| 214 |
if device.type == "cpu" or (device.type == "cuda" and not args.use_device_map):
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
model.eval()
|
| 217 |
|
| 218 |
cfg = model.config
|
|
|
|
| 154 |
return masked
|
| 155 |
|
| 156 |
|
| 157 |
+
def _has_meta_tensors(model) -> bool:
|
| 158 |
+
import torch
|
| 159 |
+
|
| 160 |
+
for p in model.parameters():
|
| 161 |
+
if isinstance(p, torch.Tensor) and p.is_meta:
|
| 162 |
+
return True
|
| 163 |
+
for b in model.buffers():
|
| 164 |
+
if isinstance(b, torch.Tensor) and b.is_meta:
|
| 165 |
+
return True
|
| 166 |
+
return False
|
| 167 |
+
|
| 168 |
+
|
| 169 |
def generate_compat(model, input_ids, max_new_tokens: int, temperature: float, top_k: int, seed: int):
|
| 170 |
import torch
|
| 171 |
import torch.nn.functional as F
|
|
|
|
| 224 |
low_cpu_mem_usage=bool(device.type == "cuda" and args.use_device_map),
|
| 225 |
)
|
| 226 |
if device.type == "cpu" or (device.type == "cuda" and not args.use_device_map):
|
| 227 |
+
if _has_meta_tensors(model):
|
| 228 |
+
print("[warn] Detected meta tensors after load; retrying with device_map='auto' fallback.")
|
| 229 |
+
del model
|
| 230 |
+
if torch.cuda.is_available():
|
| 231 |
+
torch.cuda.empty_cache()
|
| 232 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 233 |
+
local,
|
| 234 |
+
trust_remote_code=True,
|
| 235 |
+
torch_dtype=torch_dtype,
|
| 236 |
+
device_map="auto" if device.type == "cuda" else None,
|
| 237 |
+
low_cpu_mem_usage=bool(device.type == "cuda"),
|
| 238 |
+
)
|
| 239 |
+
else:
|
| 240 |
+
model = model.to(device)
|
| 241 |
model.eval()
|
| 242 |
|
| 243 |
cfg = model.config
|