Text Generation
Transformers
Safetensors
llama
conversational
text-generation-inference
8-bit precision
bitsandbytes
Instructions to use tb2pi-persistent/Llama-2-13b-chat-hf-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tb2pi-persistent/Llama-2-13b-chat-hf-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tb2pi-persistent/Llama-2-13b-chat-hf-base") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tb2pi-persistent/Llama-2-13b-chat-hf-base") model = AutoModelForCausalLM.from_pretrained("tb2pi-persistent/Llama-2-13b-chat-hf-base") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use tb2pi-persistent/Llama-2-13b-chat-hf-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tb2pi-persistent/Llama-2-13b-chat-hf-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tb2pi-persistent/Llama-2-13b-chat-hf-base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tb2pi-persistent/Llama-2-13b-chat-hf-base
- SGLang
How to use tb2pi-persistent/Llama-2-13b-chat-hf-base 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 "tb2pi-persistent/Llama-2-13b-chat-hf-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tb2pi-persistent/Llama-2-13b-chat-hf-base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "tb2pi-persistent/Llama-2-13b-chat-hf-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tb2pi-persistent/Llama-2-13b-chat-hf-base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tb2pi-persistent/Llama-2-13b-chat-hf-base with Docker Model Runner:
docker model run hf.co/tb2pi-persistent/Llama-2-13b-chat-hf-base
Commit ·
bb9dd7c
1
Parent(s): 4f0e4d0
Upload 2 files
Browse files- handler.py +41 -0
- requirements.txt +7 -0
handler.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, List, Any
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import transformers
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
# dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] == 8 else torch.float16
|
| 7 |
+
|
| 8 |
+
class EndpointHandler:
|
| 9 |
+
def __init__(self, path=""):
|
| 10 |
+
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
|
| 12 |
+
tokenizer.padding_side = "left"
|
| 13 |
+
tokenizer.pad_token = tokenizer.unk_token
|
| 14 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 15 |
+
path,
|
| 16 |
+
return_dict=True,
|
| 17 |
+
device_map="auto",
|
| 18 |
+
load_in_8bit=True,
|
| 19 |
+
torch_dtype=torch.bfloat16,
|
| 20 |
+
trust_remote_code=True
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
generation_config = model.generation_config
|
| 24 |
+
generation_config.max_new_tokens = 200
|
| 25 |
+
generation_config.temperature = 0.7
|
| 26 |
+
generation_config.top_p = 0.7
|
| 27 |
+
generation_config.num_return_sequences = 1
|
| 28 |
+
generation_config.pad_token_id = tokenizer.pad_token_id
|
| 29 |
+
generation_config.eos_token_id = tokenizer.eos_token_id
|
| 30 |
+
self.generation_config = generation_config
|
| 31 |
+
|
| 32 |
+
self.pipeline = transformers.pipeline(
|
| 33 |
+
"text-generation",
|
| 34 |
+
model=model,
|
| 35 |
+
tokenizer=tokenizer
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
| 39 |
+
prompt = data.pop("inputs", data)
|
| 40 |
+
result = self.pipeline(prompt, generation_config=self.generation_config)
|
| 41 |
+
return result
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|
| 3 |
+
bitsandbytes
|
| 4 |
+
accelerate
|
| 5 |
+
loralib
|
| 6 |
+
einops
|
| 7 |
+
datasets
|