Text Generation
Transformers
Safetensors
PyTorch
English
llama
facebook
meta
llama-3
text-generation-inference
Instructions to use meta-llama/Meta-Llama-3-8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use meta-llama/Meta-Llama-3-8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="meta-llama/Meta-Llama-3-8B")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B") model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B") - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use meta-llama/Meta-Llama-3-8B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "meta-llama/Meta-Llama-3-8B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "meta-llama/Meta-Llama-3-8B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/meta-llama/Meta-Llama-3-8B
- SGLang
How to use meta-llama/Meta-Llama-3-8B 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 "meta-llama/Meta-Llama-3-8B" \ --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": "meta-llama/Meta-Llama-3-8B", "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 "meta-llama/Meta-Llama-3-8B" \ --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": "meta-llama/Meta-Llama-3-8B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use meta-llama/Meta-Llama-3-8B with Docker Model Runner:
docker model run hf.co/meta-llama/Meta-Llama-3-8B
Tokenizer doesn't add EOS token even when explicitly requested
#90
by johngiorgi - opened
I can't seem to get the tokenizer to add the EOS token, even when I explicitly request it. Reproduction below with a fresh download of the tokenizer:
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
"meta-llama/Meta-Llama-3-8B",
add_eos_token=True,
force_download=True,
token=True
)
tokenizer.tokenize("this is a test", add_special_tokens=True)
>>> ['<|begin_of_text|>', 'this', 'Ġis', 'Ġa', 'Ġtest']
I am on transformers==4.40.1 and tokenizers==0.19.1
This is awful. I hope it gets resolved soon!
Try this:
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
model, token=os.environ["HUGGING_FACE_TOKEN"], cache_dir=Settings.CACHE_DIR,
)
stopping_ids = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
llm = HuggingFaceLLM(
model_name=model,
model_kwargs={
"token": os.environ["HUGGING_FACE_TOKEN"],
"torch_dtype": torch.bfloat16,
},
generate_kwargs={
"do_sample": True,
"temperature": 0.01,
"top_p": 0.9,
},
tokenizer_name=model,
tokenizer_kwargs={"token": os.environ["HUGGING_FACE_TOKEN"]},
stopping_ids=stopping_ids,
)
osanseviero changed discussion status to closed
@osanseviero Why was this closed? And with zero explanation? This is still an issue—with both the base model and the instruct model:
['<|begin_of_text|>', 'this', 'Ġis', 'Ġa', 'Ġtest']