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
Make standalone runner Colab-safe (disable device_map by default)
Browse files
run_standalone_inference.py
CHANGED
|
@@ -51,6 +51,11 @@ def parse_args() -> argparse.Namespace:
|
|
| 51 |
p.add_argument("--max-new-tokens", type=int, default=96)
|
| 52 |
p.add_argument("--seed", type=int, default=42)
|
| 53 |
p.add_argument("--device", choices=["auto", "cuda", "cpu"], default="auto")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
p.add_argument("--prompts-file", default=None, help="Optional .txt file with one prompt per line")
|
| 55 |
return p.parse_args()
|
| 56 |
|
|
@@ -203,9 +208,10 @@ def main() -> None:
|
|
| 203 |
local,
|
| 204 |
trust_remote_code=True,
|
| 205 |
torch_dtype=torch_dtype,
|
| 206 |
-
device_map="auto" if device.type == "cuda" else None,
|
|
|
|
| 207 |
)
|
| 208 |
-
if device.type == "cpu":
|
| 209 |
model = model.to(device)
|
| 210 |
model.eval()
|
| 211 |
|
|
@@ -227,7 +233,7 @@ def main() -> None:
|
|
| 227 |
max_prompt_tokens = max(1, context_window - args.max_new_tokens)
|
| 228 |
|
| 229 |
print(f"repo={args.repo_id} revision={args.revision} snapshot_sha={sha}")
|
| 230 |
-
print(f"device={device} dtype={torch_dtype} prompt_style={prompt_style}")
|
| 231 |
print(f"context_window={context_window} max_prompt_tokens={max_prompt_tokens}")
|
| 232 |
|
| 233 |
torch.manual_seed(args.seed)
|
|
|
|
| 51 |
p.add_argument("--max-new-tokens", type=int, default=96)
|
| 52 |
p.add_argument("--seed", type=int, default=42)
|
| 53 |
p.add_argument("--device", choices=["auto", "cuda", "cpu"], default="auto")
|
| 54 |
+
p.add_argument(
|
| 55 |
+
"--use-device-map",
|
| 56 |
+
action="store_true",
|
| 57 |
+
help="Use transformers/accelerate device_map='auto'. Disabled by default for maximum Colab compatibility.",
|
| 58 |
+
)
|
| 59 |
p.add_argument("--prompts-file", default=None, help="Optional .txt file with one prompt per line")
|
| 60 |
return p.parse_args()
|
| 61 |
|
|
|
|
| 208 |
local,
|
| 209 |
trust_remote_code=True,
|
| 210 |
torch_dtype=torch_dtype,
|
| 211 |
+
device_map="auto" if (device.type == "cuda" and args.use_device_map) else 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 |
model = model.to(device)
|
| 216 |
model.eval()
|
| 217 |
|
|
|
|
| 233 |
max_prompt_tokens = max(1, context_window - args.max_new_tokens)
|
| 234 |
|
| 235 |
print(f"repo={args.repo_id} revision={args.revision} snapshot_sha={sha}")
|
| 236 |
+
print(f"device={device} dtype={torch_dtype} prompt_style={prompt_style} use_device_map={args.use_device_map}")
|
| 237 |
print(f"context_window={context_window} max_prompt_tokens={max_prompt_tokens}")
|
| 238 |
|
| 239 |
torch.manual_seed(args.seed)
|