Text Generation
Transformers
Safetensors
Swedish
Danish
Norwegian
llama
conversational
text-generation-inference
Instructions to use AI-Sweden-Models/Llama-3-8B-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AI-Sweden-Models/Llama-3-8B-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AI-Sweden-Models/Llama-3-8B-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("AI-Sweden-Models/Llama-3-8B-instruct") model = AutoModelForCausalLM.from_pretrained("AI-Sweden-Models/Llama-3-8B-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 AI-Sweden-Models/Llama-3-8B-instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AI-Sweden-Models/Llama-3-8B-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": "AI-Sweden-Models/Llama-3-8B-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/AI-Sweden-Models/Llama-3-8B-instruct
- SGLang
How to use AI-Sweden-Models/Llama-3-8B-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 "AI-Sweden-Models/Llama-3-8B-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": "AI-Sweden-Models/Llama-3-8B-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 "AI-Sweden-Models/Llama-3-8B-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": "AI-Sweden-Models/Llama-3-8B-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use AI-Sweden-Models/Llama-3-8B-instruct with Docker Model Runner:
docker model run hf.co/AI-Sweden-Models/Llama-3-8B-instruct
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
---
|
| 4 |
+
|
| 5 |
+
#### Transformers pipeline
|
| 6 |
+
|
| 7 |
+
```python
|
| 8 |
+
import transformers
|
| 9 |
+
import torch
|
| 10 |
+
|
| 11 |
+
model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
|
| 12 |
+
|
| 13 |
+
pipeline = transformers.pipeline(
|
| 14 |
+
"text-generation",
|
| 15 |
+
model=model_id,
|
| 16 |
+
model_kwargs={"torch_dtype": torch.bfloat16},
|
| 17 |
+
device_map="auto",
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
messages = [
|
| 21 |
+
{"role": "system", "content": "Du är en snäll maskin."},
|
| 22 |
+
{"role": "user", "content": "Vem är du?"},
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
terminators = [
|
| 26 |
+
pipeline.tokenizer.eos_token_id,
|
| 27 |
+
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
| 28 |
+
]
|
| 29 |
+
|
| 30 |
+
outputs = pipeline(
|
| 31 |
+
messages,
|
| 32 |
+
max_new_tokens=256,
|
| 33 |
+
eos_token_id=terminators,
|
| 34 |
+
do_sample=True,
|
| 35 |
+
temperature=0.6,
|
| 36 |
+
top_p=0.9,
|
| 37 |
+
)
|
| 38 |
+
print(outputs[0]["generated_text"][-1])
|
| 39 |
+
```
|