Instructions to use openlm-research/open_llama_7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openlm-research/open_llama_7b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openlm-research/open_llama_7b")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("openlm-research/open_llama_7b") model = AutoModelForCausalLM.from_pretrained("openlm-research/open_llama_7b") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use openlm-research/open_llama_7b 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" # 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", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/openlm-research/open_llama_7b
- SGLang
How to use openlm-research/open_llama_7b 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" \ --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", "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" \ --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", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use openlm-research/open_llama_7b with Docker Model Runner:
docker model run hf.co/openlm-research/open_llama_7b
Why does the model output the embedding for the <s> token?
When asked for hidden states, causal models usually provide embeddings for all tokens in the input sentence. E.g., given the input "one two three", GPT-2 will return a tensor of size [1, 3, 768] for each layer. This model, surprisingly, returns tensors of size [1, 4, 4096], and the extra embedding seems to correspond to the initial <s> token. Its embeddings is therefore always the same:
In [4]: tokenisation = tok("one two three", return_tensors='pt')
In [5]: outputs = model(**tokenisation, output_hidden_states=True).hidden_states
In [6]: len(outputs)
Out[6]: 33
In [7]: outputs[-1].size()
Out[7]: torch.Size([1, 4, 4096])
In [8]: tok.tokenize("one two three")
Out[8]: ['▁one', '▁two', '▁three']
In [9]: tokenisation.input_ids[0]
Out[9]: tensor([ 1, 551, 753, 1166])
In [10]: tok.decode(tokenisation.input_ids[0])
Out[10]: '<s>one two three'
In [11]: outputs[-1][0, 0]
Out[11]:
tensor([ 0.0468, 0.2356, 0.5536, ..., 0.3180, -0.2200, 0.5274],
grad_fn=<SelectBackward0>)
In [12]: tokenisation = tok("five six seven", return_tensors='pt')
In [13]: outputs = model(**tokenisation, output_hidden_states=True).hidden_states
In [14]: outputs[-1][0, 0]
Out[14]:
tensor([ 0.0468, 0.2356, 0.5536, ..., 0.3180, -0.2200, 0.5274],
grad_fn=<SelectBackward0>)
Was this done by design or is it an API bug?
This is done by design. You can also turn off the BOS token during tokenization if you want.