Instructions to use pere/llama3-reasoning-template-single with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use pere/llama3-reasoning-template-single with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="pere/llama3-reasoning-template-single")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("pere/llama3-reasoning-template-single") model = AutoModelForCausalLM.from_pretrained("pere/llama3-reasoning-template-single") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use pere/llama3-reasoning-template-single with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "pere/llama3-reasoning-template-single" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pere/llama3-reasoning-template-single", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/pere/llama3-reasoning-template-single
- SGLang
How to use pere/llama3-reasoning-template-single 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 "pere/llama3-reasoning-template-single" \ --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": "pere/llama3-reasoning-template-single", "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 "pere/llama3-reasoning-template-single" \ --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": "pere/llama3-reasoning-template-single", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use pere/llama3-reasoning-template-single with Docker Model Runner:
docker model run hf.co/pere/llama3-reasoning-template-single
Modified Llama3.x-tokenizer
This is a modified version of the Llama3.x tokenizer. It is made especially for reasoning.
The following tokens are replaced:
| Token ID | Token |
|---|---|
| 128013 | <|think|> |
| 128014 | <|/think|> |
| 128015 | <|answer|> |
| 128016 | <|/answer|> |
The script (replace_reserved_tokens.py) for changing the tokens are also included in this repo.
Verification
You can verify that the tokenizer is working correctly by using this script:
#####################################
# Check if the tokenizer is correct #
#####################################
import torch
from transformers import AutoTokenizer
from tabulate import tabulate
# Tokenize the text
text = "<|think|>think<|/think|><|answer|>answer<|/answer|>"
tokenizer = AutoTokenizer.from_pretrained(model_id)
tokens = tokenizer(text, return_tensors="pt")
token_ids = tokens["input_ids"].squeeze().tolist()
decoded_tokens = [tokenizer.decode([tid]) for tid in token_ids]
# Create table
table_data = list(zip(token_ids, decoded_tokens))
print(tabulate(table_data, headers=["Token ID", "Token"], tablefmt="grid"))
Credits
This tokenizer is created by Per Egil Kummervold and is part of the NoTraM-project.
- Downloads last month
- 3