Instructions to use togethercomputer/LLaMA-2-7B-32K with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use togethercomputer/LLaMA-2-7B-32K with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="togethercomputer/LLaMA-2-7B-32K")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("togethercomputer/LLaMA-2-7B-32K") model = AutoModelForCausalLM.from_pretrained("togethercomputer/LLaMA-2-7B-32K") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use togethercomputer/LLaMA-2-7B-32K with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "togethercomputer/LLaMA-2-7B-32K" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "togethercomputer/LLaMA-2-7B-32K", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/togethercomputer/LLaMA-2-7B-32K
- SGLang
How to use togethercomputer/LLaMA-2-7B-32K 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 "togethercomputer/LLaMA-2-7B-32K" \ --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": "togethercomputer/LLaMA-2-7B-32K", "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 "togethercomputer/LLaMA-2-7B-32K" \ --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": "togethercomputer/LLaMA-2-7B-32K", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use togethercomputer/LLaMA-2-7B-32K with Docker Model Runner:
docker model run hf.co/togethercomputer/LLaMA-2-7B-32K
RuntimeError: "addmm_impl_cpu_" not implemented for 'Half'
Hi, I get this runtime error when I try without flash attention, ie. if I don't use trust_remote_code=True
File "/mnt/home/miniconda/envs/autoreview/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/home/miniconda/envs/autoreview/lib/python3.11/site-packages/transformers/models/llama/modeling_llama.py", line 305, in forward
query_states = self.q_proj(hidden_states)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/home/miniconda/envs/autoreview/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mnt/home/miniconda/envs/autoreview/lib/python3.11/site-packages/torch/nn/modules/linear.py", line 114, in forward
return F.linear(input, self.weight, self.bias)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: "addmm_impl_cpu_" not implemented for 'Half'
Hi @shubhamagarwal92 , this is likely because you're using float16 data type. Can you try to change it to float32 and see if the error persists?
i have used float32 the error persists
Hi @Anash , can you provide the code you use that results in this error?
Hi mauriceweber, I have the same question, my code is below:
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_path = r'/home/model/LLaMA-2-7B-32K'
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, torch_dtype=torch.float16)
input_context = "Your text here"
input_ids = tokenizer.encode(input_context, return_tensors="pt")
output = model.generate(input_ids, max_new_tokens=6000, temperature=0.7)
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
output_text_path=r'/qa/txt/split-cat-00/test.txt'
with open(output_text_path, 'w', encoding='utf-8') as output_file:
output_file.write(output_text)
print('success')
RuntimeError: "addmm_impl_cpu_" not implemented for 'Half'
if I change the float16 to float32, there is new error:
File "", line 21, in rotary_kernel
KeyError: ('2-.-0-.-0-1e8410f206c822547fb50e2ea86e45a6-d6252949da17ceb5f3a278a70250af1
3-1af5134066c618146d2cd009138944a0-9b9585c66493f30389231e55f159817f-3498c340fd4b6ee780
5fd54b882a04f5-e1f133f98d04093da2078dfc51c36b72-b26258bf01f839199e39d64851821f26-d7c06
e3b46e708006c15224aac7a1378-f585402118c8a136948ce0a49cfe122c', (torch.float32, torch.f
loat32, torch.float32, torch.float32, None, 'i32', 'i32', 'i32', 'i32', 'i32', 'i32',
'i32', 'i32', 'i32', 'i32', 'i32', 'i32', 'i32', 'i32'), (128, False, False, False, Fa
lse, 4), (True, True, True, True, (False,), (True, False), (False, False), (True, Fals
e), (True, False), (False, False), (False, False), (True, False), (True, False), (True
, False), (False, True), (True, False), (True, False), (True, False), (False, True)))