Text Generation
Transformers
PyTorch
PEFT
English
llama
decapoda-research-7b-hf
prompt answering
text-generation-inference
8-bit precision
Instructions to use Sandiago21/llama-7b-hf-prompt-answering with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Sandiago21/llama-7b-hf-prompt-answering with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Sandiago21/llama-7b-hf-prompt-answering")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Sandiago21/llama-7b-hf-prompt-answering") model = AutoModelForCausalLM.from_pretrained("Sandiago21/llama-7b-hf-prompt-answering", device_map="auto") - PEFT
How to use Sandiago21/llama-7b-hf-prompt-answering with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Sandiago21/llama-7b-hf-prompt-answering with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Sandiago21/llama-7b-hf-prompt-answering" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Sandiago21/llama-7b-hf-prompt-answering", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Sandiago21/llama-7b-hf-prompt-answering
- SGLang
How to use Sandiago21/llama-7b-hf-prompt-answering 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 "Sandiago21/llama-7b-hf-prompt-answering" \ --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": "Sandiago21/llama-7b-hf-prompt-answering", "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 "Sandiago21/llama-7b-hf-prompt-answering" \ --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": "Sandiago21/llama-7b-hf-prompt-answering", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Sandiago21/llama-7b-hf-prompt-answering with Docker Model Runner:
docker model run hf.co/Sandiago21/llama-7b-hf-prompt-answering
Commit ·
2f7732f
1
Parent(s): c709ea2
Update README.md with improved way to load and use the model
Browse files
README.md
CHANGED
|
@@ -98,49 +98,50 @@ def generate_prompt(instruction: str, input_ctxt: str = None) -> str:
|
|
| 98 |
Use the code below to get started with the model.
|
| 99 |
|
| 100 |
```python
|
| 101 |
-
|
| 102 |
-
from
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
model
|
| 109 |
-
|
|
|
|
| 110 |
```
|
| 111 |
|
| 112 |
### Example of Usage
|
| 113 |
```python
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
PROMPT = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nWhich is the capital city of Greece and with which countries does Greece border?\n\n### Input:\nQuestion answering\n\n### Response:\n"""
|
| 117 |
-
DEVICE = "cuda"
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
)
|
| 123 |
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
top_p=0.95,
|
| 129 |
-
repetition_penalty=1.2,
|
| 130 |
-
)
|
| 131 |
|
| 132 |
-
|
| 133 |
-
with torch.no_grad():
|
| 134 |
-
generation_output = model.generate(
|
| 135 |
-
input_ids=input_ids,
|
| 136 |
-
generation_config=generation_config,
|
| 137 |
-
return_dict_in_generate=True,
|
| 138 |
-
output_scores=True,
|
| 139 |
-
max_new_tokens=256,
|
| 140 |
-
)
|
| 141 |
-
|
| 142 |
-
for s in generation_output.sequences:
|
| 143 |
-
print(tokenizer.decode(s))
|
| 144 |
```
|
| 145 |
|
| 146 |
### Example Output
|
|
|
|
| 98 |
Use the code below to get started with the model.
|
| 99 |
|
| 100 |
```python
|
| 101 |
+
import torch
|
| 102 |
+
from transformers import GenerationConfig, LlamaTokenizer, LlamaForCausalLM
|
| 103 |
+
|
| 104 |
+
tokenizer = LlamaTokenizer.from_pretrained("chainyo/alpaca-lora-7b")
|
| 105 |
+
model = LlamaForCausalLM.from_pretrained(
|
| 106 |
+
"chainyo/alpaca-lora-7b",
|
| 107 |
+
load_in_8bit=True,
|
| 108 |
+
torch_dtype=torch.float16,
|
| 109 |
+
device_map="auto",
|
| 110 |
+
)
|
| 111 |
+
generation_config = GenerationConfig(
|
| 112 |
+
temperature=0.2,
|
| 113 |
+
top_p=0.75,
|
| 114 |
+
top_k=40,
|
| 115 |
+
num_beams=4,
|
| 116 |
+
max_new_tokens=128,
|
| 117 |
+
)
|
| 118 |
|
| 119 |
+
model.eval()
|
| 120 |
+
if torch.__version__ >= "2":
|
| 121 |
+
model = torch.compile(model)
|
| 122 |
```
|
| 123 |
|
| 124 |
### Example of Usage
|
| 125 |
```python
|
| 126 |
+
instruction = "What is the capital city of Greece and with which countries does Greece border?"
|
| 127 |
+
input_ctxt = None # For some tasks, you can provide an input context to help the model generate a better response.
|
|
|
|
|
|
|
| 128 |
|
| 129 |
+
prompt = generate_prompt(instruction, input_ctxt)
|
| 130 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
| 131 |
+
input_ids = input_ids.to(model.device)
|
|
|
|
| 132 |
|
| 133 |
+
with torch.no_grad():
|
| 134 |
+
outputs = model.generate(
|
| 135 |
+
input_ids=input_ids,
|
| 136 |
+
generation_config=generation_config,
|
| 137 |
+
return_dict_in_generate=True,
|
| 138 |
+
output_scores=True,
|
| 139 |
+
)
|
| 140 |
|
| 141 |
+
response = tokenizer.decode(outputs.sequences[0], skip_special_tokens=True)
|
| 142 |
+
print(response)
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
+
>>> The capital city of Greece is Athens and it borders Albania, Macedonia, Bulgaria and Turkey.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
```
|
| 146 |
|
| 147 |
### Example Output
|