barbaroo/Sprotin_parallel
Viewer • Updated • 126k • 37
How to use barbaroo/gptsw3-6.7B-translation-en-fo with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="barbaroo/gptsw3-6.7B-translation-en-fo") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("barbaroo/gptsw3-6.7B-translation-en-fo")
model = AutoModelForCausalLM.from_pretrained("barbaroo/gptsw3-6.7B-translation-en-fo", device_map="auto")How to use barbaroo/gptsw3-6.7B-translation-en-fo with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "barbaroo/gptsw3-6.7B-translation-en-fo"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "barbaroo/gptsw3-6.7B-translation-en-fo",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/barbaroo/gptsw3-6.7B-translation-en-fo
How to use barbaroo/gptsw3-6.7B-translation-en-fo with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "barbaroo/gptsw3-6.7B-translation-en-fo" \
--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": "barbaroo/gptsw3-6.7B-translation-en-fo",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "barbaroo/gptsw3-6.7B-translation-en-fo" \
--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": "barbaroo/gptsw3-6.7B-translation-en-fo",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use barbaroo/gptsw3-6.7B-translation-en-fo with Docker Model Runner:
docker model run hf.co/barbaroo/gptsw3-6.7B-translation-en-fo
This model is the merged version of the PEFT adapter barbaroo/gptsw3_translate_synth_6.7B with its base model.
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
import re
import pandas as pd
# Model repo
MODEL_NAME = "barbaroo/gptsw3-6.7B-translation-en-fo"
# Quantization config (8-bit)
bnb_config = BitsAndBytesConfig(
load_in_8bit=True
)
# Initialize tokenizer & model
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(
MODEL_NAME,
quantization_config=bnb_config,
device_map="auto",
)
model.eval()
# Alpaca-style prompt template
alpaca_prompt = """
### Instruction:
{}
### Input:
{}
### Response:
{}"""
EOS_TOKEN = tokenizer.eos_token
print("EOS token:", EOS_TOKEN)
# Example sentences
sentences = ["I love Faroese!"]
translations = []
for sentence in sentences:
inputs = tokenizer(
[
alpaca_prompt.format(
"Translate this sentence from English to Faroese:",
sentence,
"",
)
],
return_tensors="pt"
).to("cuda")
outputs = model.generate(
**inputs,
max_new_tokens=500,
use_cache=True,
do_sample=True,
temperature=0.1,
top_p=1,
)
output_string = tokenizer.batch_decode(outputs, skip_special_tokens=False)[0]
try:
response = output_string.split("Response:\n", 1)[1]
translation = response.replace(EOS_TOKEN, "")
except IndexError:
translation = ""
translations.append(translation)
print(translation)
Hyperparameters:
Base model
AI-Sweden-Models/gpt-sw3-6.7b-v2