Instructions to use AI-Sweden-Models/gpt-sw3-6.7b-v2-translator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AI-Sweden-Models/gpt-sw3-6.7b-v2-translator with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AI-Sweden-Models/gpt-sw3-6.7b-v2-translator")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("AI-Sweden-Models/gpt-sw3-6.7b-v2-translator") model = AutoModelForCausalLM.from_pretrained("AI-Sweden-Models/gpt-sw3-6.7b-v2-translator") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use AI-Sweden-Models/gpt-sw3-6.7b-v2-translator with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AI-Sweden-Models/gpt-sw3-6.7b-v2-translator" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AI-Sweden-Models/gpt-sw3-6.7b-v2-translator", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/AI-Sweden-Models/gpt-sw3-6.7b-v2-translator
- SGLang
How to use AI-Sweden-Models/gpt-sw3-6.7b-v2-translator 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/gpt-sw3-6.7b-v2-translator" \ --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": "AI-Sweden-Models/gpt-sw3-6.7b-v2-translator", "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 "AI-Sweden-Models/gpt-sw3-6.7b-v2-translator" \ --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": "AI-Sweden-Models/gpt-sw3-6.7b-v2-translator", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use AI-Sweden-Models/gpt-sw3-6.7b-v2-translator with Docker Model Runner:
docker model run hf.co/AI-Sweden-Models/gpt-sw3-6.7b-v2-translator
Model Card for gpt-sw3-6.7b-v2-translator
The gpt-sw3-6.7b-v2-translator is a finetuned version of gpt-sw3-6.7b-v2-instruct on a carefully selected translation pair dataset that was gathered by AI Sweden.
Intended usage:
Translate text data from English to Swedish, or Swedish to English.
How to use:
import torch
from transformers import pipeline, StoppingCriteriaList, StoppingCriteria
device = "cuda" if torch.cuda.is_available() else "cpu"
# (Optional) - define a stopping criteria
# We ideally want the model to stop generate once the response from the Bot is generated
class StopOnTokenCriteria(StoppingCriteria):
def __init__(self, stop_token_id):
self.stop_token_id = stop_token_id
def __call__(self, input_ids, scores, **kwargs):
return input_ids[0, -1] == self.stop_token_id
pipe = pipeline(
task="text-generation",
model="AI-Sweden-Models/gpt-sw3-6.7b-v2-translator",
device=device
)
stop_on_token_criteria = StopOnTokenCriteria(stop_token_id=pipe.tokenizer.bos_token_id)
text = "I like to eat ice cream in the summer."
# This will translate English to Swedish
# To translate from Swedish to English the prompt would be:
# prompt = f"<|endoftext|><s>User: Översätt till Engelska från Svenska\n{text}<s>Bot:"
prompt = f"<|endoftext|><s>User: Översätt till Svenska från Engelska\n{text}<s>Bot:"
input_tokens = pipe.tokenizer(prompt, return_tensors="pt").input_ids.to(device)
max_model_length = 2048
dynamic_max_length = max_model_length - input_tokens.shape[1]
response = pipe(
prompt,
max_length=dynamic_max_length,
truncation=True,
stopping_criteria=StoppingCriteriaList([stop_on_token_criteria])
)
print(response[0]["generated_text"].split("<s>Bot: ")[-1])
>>> "Jag tycker om att äta glass på sommaren."
Training & Data:
The training was done on 1 NVIDIA DGX using DeepSpeed ZeRO 3 for three epochs on roughly 4GB of carefully selected translation data. It is a full finetune of all of the model parameters.
| Epoch | Training Loss | Evaluation Loss |
|---|---|---|
| 1 | 1.309 | 1.281 |
| 2 | 1.161 | 1.242 |
| 3 | 1.053 | 1.219 |
- Downloads last month
- 279
Model tree for AI-Sweden-Models/gpt-sw3-6.7b-v2-translator
Base model
AI-Sweden-Models/gpt-sw3-6.7b-v2