Instructions to use openlm-research/open_llama_7b_v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openlm-research/open_llama_7b_v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openlm-research/open_llama_7b_v2")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("openlm-research/open_llama_7b_v2") model = AutoModelForCausalLM.from_pretrained("openlm-research/open_llama_7b_v2") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use openlm-research/open_llama_7b_v2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openlm-research/open_llama_7b_v2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openlm-research/open_llama_7b_v2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/openlm-research/open_llama_7b_v2
- SGLang
How to use openlm-research/open_llama_7b_v2 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 "openlm-research/open_llama_7b_v2" \ --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": "openlm-research/open_llama_7b_v2", "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 "openlm-research/open_llama_7b_v2" \ --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": "openlm-research/open_llama_7b_v2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use openlm-research/open_llama_7b_v2 with Docker Model Runner:
docker model run hf.co/openlm-research/open_llama_7b_v2
Update `README.md`
Add input_ids mapping to device, as otherwise the code fails since we're using device_map="auto" from π€accelerate and the previous code would just work if working in the CPU, otherwise we wouls encounter a RuntimeError: Expected all tensors to be on the same device exception, this way the code is safer and ensured to work in any device. Additionally, I've also removed some extra line breaks.
Maybe it would also be nice to add a line with the requirements pip install transformers[torch] einops accelerate sentencepiece even though most of it may already be at https://github.com/openlm-research/open_llama, I guess it may also be nice to include the requirements in the README.md too
BTW great work @young-geng ππ» I'm also happy to open a PR at https://github.com/openlm-research/open_llama as of https://github.com/openlm-research/open_llama/issues/76, let me know if that makes sense to you!
Had to change this line in the example to:
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(model.device)
Otherwise it complains that the model and token_ids are on different devices.
(PyTorch2, Windows, 4090 GPU)