Text Generation
Transformers
PyTorch
Safetensors
code
llama
llama-2
conversational
text-generation-inference
Instructions to use codellama/CodeLlama-70b-Instruct-hf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use codellama/CodeLlama-70b-Instruct-hf with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="codellama/CodeLlama-70b-Instruct-hf") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("codellama/CodeLlama-70b-Instruct-hf") model = AutoModelForCausalLM.from_pretrained("codellama/CodeLlama-70b-Instruct-hf") 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 codellama/CodeLlama-70b-Instruct-hf with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "codellama/CodeLlama-70b-Instruct-hf" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "codellama/CodeLlama-70b-Instruct-hf", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/codellama/CodeLlama-70b-Instruct-hf
- SGLang
How to use codellama/CodeLlama-70b-Instruct-hf 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 "codellama/CodeLlama-70b-Instruct-hf" \ --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": "codellama/CodeLlama-70b-Instruct-hf", "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 "codellama/CodeLlama-70b-Instruct-hf" \ --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": "codellama/CodeLlama-70b-Instruct-hf", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use codellama/CodeLlama-70b-Instruct-hf with Docker Model Runner:
docker model run hf.co/codellama/CodeLlama-70b-Instruct-hf
Add <step> token, chat template
#5
by pcuenq HF Staff - opened
- added_tokens.json +3 -0
- tokenizer.json +11 -3
- tokenizer_config.json +9 -0
added_tokens.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"<step>": 32015
|
| 3 |
+
}
|
tokenizer.json
CHANGED
|
@@ -29,6 +29,15 @@
|
|
| 29 |
"rstrip": false,
|
| 30 |
"normalized": false,
|
| 31 |
"special": true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
],
|
| 34 |
"normalizer": {
|
|
@@ -32149,8 +32158,7 @@
|
|
| 32149 |
"β<EOT><EOT>": 32011,
|
| 32150 |
"β<EOT><EOT><EOT>": 32012,
|
| 32151 |
"β<EOT><EOT><EOT><EOT>": 32013,
|
| 32152 |
-
"β<EOT><EOT><EOT><EOT><EOT>": 32014
|
| 32153 |
-
"<step>": 32015
|
| 32154 |
},
|
| 32155 |
"merges": [
|
| 32156 |
"β t",
|
|
@@ -93415,4 +93423,4 @@
|
|
| 93415 |
"β<EOT >"
|
| 93416 |
]
|
| 93417 |
}
|
| 93418 |
-
}
|
|
|
|
| 29 |
"rstrip": false,
|
| 30 |
"normalized": false,
|
| 31 |
"special": true
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"id": 32015,
|
| 35 |
+
"content": "<step>",
|
| 36 |
+
"single_word": true,
|
| 37 |
+
"lstrip": true,
|
| 38 |
+
"rstrip": true,
|
| 39 |
+
"normalized": false,
|
| 40 |
+
"special": false
|
| 41 |
}
|
| 42 |
],
|
| 43 |
"normalizer": {
|
|
|
|
| 32158 |
"β<EOT><EOT>": 32011,
|
| 32159 |
"β<EOT><EOT><EOT>": 32012,
|
| 32160 |
"β<EOT><EOT><EOT><EOT>": 32013,
|
| 32161 |
+
"β<EOT><EOT><EOT><EOT><EOT>": 32014
|
|
|
|
| 32162 |
},
|
| 32163 |
"merges": [
|
| 32164 |
"β t",
|
|
|
|
| 93423 |
"β<EOT >"
|
| 93424 |
]
|
| 93425 |
}
|
| 93426 |
+
}
|
tokenizer_config.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"add_bos_token": true,
|
| 3 |
"add_eos_token": false,
|
|
|
|
| 4 |
"added_tokens_decoder": {
|
| 5 |
"0": {
|
| 6 |
"content": "<unk>",
|
|
@@ -25,6 +26,14 @@
|
|
| 25 |
"rstrip": false,
|
| 26 |
"single_word": false,
|
| 27 |
"special": true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
},
|
| 30 |
"bos_token": "<s>",
|
|
|
|
| 1 |
{
|
| 2 |
"add_bos_token": true,
|
| 3 |
"add_eos_token": false,
|
| 4 |
+
"chat_template": "{% if messages[0]['role'] == 'system' %}{% set user_index = 1 %}{% else %}{% set user_index = 0 %}{% endif %}{% for message in messages %}{% if (message['role'] == 'user') != ((loop.index0 + user_index) % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if loop.index0 == 0 %}{{ '<s>' }}{% endif %}{% set content = 'Source: ' + message['role'] + '\n\n ' + message['content'].strip() %}{{ content + ' <step> ' }}{% endfor %}{{'Source: assistant\nDestination: user\n\n '}}",
|
| 5 |
"added_tokens_decoder": {
|
| 6 |
"0": {
|
| 7 |
"content": "<unk>",
|
|
|
|
| 26 |
"rstrip": false,
|
| 27 |
"single_word": false,
|
| 28 |
"special": true
|
| 29 |
+
},
|
| 30 |
+
"32015": {
|
| 31 |
+
"content": "<step>",
|
| 32 |
+
"lstrip": true,
|
| 33 |
+
"normalized": false,
|
| 34 |
+
"rstrip": true,
|
| 35 |
+
"single_word": true,
|
| 36 |
+
"special": false
|
| 37 |
}
|
| 38 |
},
|
| 39 |
"bos_token": "<s>",
|