Text Generation
Transformers
PyTorch
code
llama
Generated from Trainer
coding
llama-2
text-generation-inference
Instructions to use edumunozsala/llama-2-7b-int4-python-code-20k with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use edumunozsala/llama-2-7b-int4-python-code-20k with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="edumunozsala/llama-2-7b-int4-python-code-20k")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("edumunozsala/llama-2-7b-int4-python-code-20k") model = AutoModelForCausalLM.from_pretrained("edumunozsala/llama-2-7b-int4-python-code-20k", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use edumunozsala/llama-2-7b-int4-python-code-20k with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "edumunozsala/llama-2-7b-int4-python-code-20k" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "edumunozsala/llama-2-7b-int4-python-code-20k", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/edumunozsala/llama-2-7b-int4-python-code-20k
- SGLang
How to use edumunozsala/llama-2-7b-int4-python-code-20k 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 "edumunozsala/llama-2-7b-int4-python-code-20k" \ --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": "edumunozsala/llama-2-7b-int4-python-code-20k", "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 "edumunozsala/llama-2-7b-int4-python-code-20k" \ --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": "edumunozsala/llama-2-7b-int4-python-code-20k", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use edumunozsala/llama-2-7b-int4-python-code-20k with Docker Model Runner:
docker model run hf.co/edumunozsala/llama-2-7b-int4-python-code-20k
Commit ·
2b9d925
1
Parent(s): 43d3864
Upload README.md
Browse files
README.md
CHANGED
|
@@ -81,22 +81,24 @@ The following `bitsandbytes` quantization config was used during training:
|
|
| 81 |
import torch
|
| 82 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 83 |
|
| 84 |
-
model_id = "
|
| 85 |
|
| 86 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 87 |
|
| 88 |
-
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
| 89 |
|
| 90 |
-
|
|
|
|
| 91 |
|
| 92 |
prompt = f"""### Instruction:
|
| 93 |
Use the Task below and the Input given to write the Response, which is a programming code that can solve the Task.
|
| 94 |
|
| 95 |
### Task:
|
| 96 |
-
{
|
| 97 |
|
| 98 |
### Input:
|
| 99 |
-
{
|
| 100 |
|
| 101 |
### Response:
|
| 102 |
"""
|
|
@@ -107,7 +109,6 @@ outputs = model.generate(input_ids=input_ids, max_new_tokens=100, do_sample=True
|
|
| 107 |
|
| 108 |
print(f"Prompt:\n{prompt}\n")
|
| 109 |
print(f"Generated instruction:\n{tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0][len(prompt):]}")
|
| 110 |
-
print(f"Ground truth:\n{sample['output']}")
|
| 111 |
|
| 112 |
```
|
| 113 |
|
|
|
|
| 81 |
import torch
|
| 82 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 83 |
|
| 84 |
+
model_id = "edumunozsala/llama-2-7b-int4-python-code-20k"
|
| 85 |
|
| 86 |
+
tokenizer = AutoTokenizer.from_pretrained(hf_model_repo)
|
| 87 |
|
| 88 |
+
model = AutoModelForCausalLM.from_pretrained(hf_model_repo, load_in_4bit=True, torch_dtype=torch.float16,
|
| 89 |
+
device_map=device_map)
|
| 90 |
|
| 91 |
+
instruction="Write a Python function to display the first and last elements of a list."
|
| 92 |
+
input=""
|
| 93 |
|
| 94 |
prompt = f"""### Instruction:
|
| 95 |
Use the Task below and the Input given to write the Response, which is a programming code that can solve the Task.
|
| 96 |
|
| 97 |
### Task:
|
| 98 |
+
{instruction}
|
| 99 |
|
| 100 |
### Input:
|
| 101 |
+
{input}
|
| 102 |
|
| 103 |
### Response:
|
| 104 |
"""
|
|
|
|
| 109 |
|
| 110 |
print(f"Prompt:\n{prompt}\n")
|
| 111 |
print(f"Generated instruction:\n{tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0][len(prompt):]}")
|
|
|
|
| 112 |
|
| 113 |
```
|
| 114 |
|