Instructions to use meta-llama/Llama-3.1-70B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use meta-llama/Llama-3.1-70B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="meta-llama/Llama-3.1-70B-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.1-70B-Instruct") model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.1-70B-Instruct", device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use meta-llama/Llama-3.1-70B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "meta-llama/Llama-3.1-70B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "meta-llama/Llama-3.1-70B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/meta-llama/Llama-3.1-70B-Instruct
- SGLang
How to use meta-llama/Llama-3.1-70B-Instruct 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/Llama-3.1-70B-Instruct" \ --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": "meta-llama/Llama-3.1-70B-Instruct", "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 "meta-llama/Llama-3.1-70B-Instruct" \ --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": "meta-llama/Llama-3.1-70B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use meta-llama/Llama-3.1-70B-Instruct with Docker Model Runner:
docker model run hf.co/meta-llama/Llama-3.1-70B-Instruct
Issue with Tokenizer when deploying with TGI
Hey all, I am having an issue with tokenization when trying to deploy Llama 3.1 70B.
I am running this command from CLI. I am running 4x A100 40GB.
sudo docker run --gpus all --shm-size 128g -p 8080:80 -v $volume:/data -v $host_cache_dir:/root/.cache/huggingface -e HUGGINGFACE_TOKEN=$HUGGINGFACE_TOKEN -e RANK=0 -e WORLD_SIZE=1 -e MASTER_ADDR=localhost -e MASTER_PORT=29500 -e CUDA_VISIBLE_DEVICES=0,1,2,3 ghcr.io/huggingface/text-generation-inference:2.2.0 --model-id $model --sharded true --quantize eetq --cuda-memory-fraction 0.6
Deployment Arguments:model_id: "meta-llama/Meta-Llama-3.1-70B-Instruct", revision: None, validation_workers: 2, sharded: Some( true, ), num_shard: None, quantize: Some( Eetq, ), speculate: None, dtype: None, trust_remote_code: false, max_concurrent_requests: 128, max_best_of: 2, max_stop_sequences: 4, max_top_n_tokens: 5, max_input_tokens: None, max_input_length: None, max_total_tokens: None, waiting_served_ratio: 0.3, max_batch_prefill_tokens: None, max_batch_total_tokens: None, max_waiting_tokens: 20, max_batch_size: None, cuda_graphs: None, hostname: "0541246362b8", port: 80, shard_uds_path: "/tmp/text-generation-server", master_addr: "localhost", master_port: 29500, huggingface_hub_cache: Some( "/data", ), weights_cache_override: None, disable_custom_kernels: false, cuda_memory_fraction: 0.6, rope_scaling: None, rope_factor: None, json_output: false, otlp_endpoint: None, otlp_service_name: "text-generation-inference.router", cors_allow_origin: [], watermark_gamma: None, watermark_delta: None, ngrok: false, ngrok_authtoken: None, ngrok_edge: None, tokenizer_config_path: None, disable_grammar_support: false, env: false, max_client_batch_size: 4, lora_adapters: None, disable_usage_stats: false, disable_crash_reports: false, }
This runs properly, but whenever I try to generate a response from /generate, I am getting this response:
data: {"index":1,"token":{"id":52107,"text":"\\\\","logprob":0.0,"special":false},"top_tokens":[{"id":52107,"text":"\\\\","logprob":0.0,"special":false}],"generated_text":null,"details":null}
data: {"index":2,"token":{"id":52107,"text":"\\\\","logprob":0.0,"special":false},"top_tokens":[{"id":52107,"text":"\\\\","logprob":0.0,"special":false}],"generated_text":null,"details":null}
...
my initial thoughts were issues with the tokenizer, so I tested the /tokenize endpoint:
[
{
"id": 5159,
"text": "",
"start": 0,
"stop": 0
},
{
"id": 836,
"text": "",
"start": 2,
"stop": 2
},
{
"id": 374,
"text": "",
"start": 7,
"stop": 7
},
{
"id": 78118,
"text": "",
"start": 10,
"stop": 10
},
{
"id": 323,
"text": "",
"start": 18,
"stop": 18
},
okay, so the fact that the text was not popping up was that there must have been an issue with the tokenizer. I then downloaded the tokenizer.json from the model files and manually set it when running the model using the --tokenizer-config-path, but it still did not fix the issue. Has anyone ran into a similar issue?
any help would be greatly appreciated.
Yes I can confirm this is an issue. Though the file you probably need to specify is tokenizer_config.json, however TGI is not using the file for some reason.