google-research-datasets/paws
Viewer • Updated • 751k • 92.4k • 39
How to use aerner/lm-v1 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="aerner/lm-v1") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("aerner/lm-v1")
model = AutoModelForCausalLM.from_pretrained("aerner/lm-v1")How to use aerner/lm-v1 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "aerner/lm-v1"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "aerner/lm-v1",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/aerner/lm-v1
How to use aerner/lm-v1 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "aerner/lm-v1" \
--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": "aerner/lm-v1",
"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 "aerner/lm-v1" \
--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": "aerner/lm-v1",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use aerner/lm-v1 with Docker Model Runner:
docker model run hf.co/aerner/lm-v1
事前学習から全部日本語で学習させたモデルです。 LLaMAベースで、24GBのVRAMで事前学習できる規模に小さなモデルです。 なかなか動作は高速です。
事前学習からちゃんとした日本語を食べさせてあげて、丁寧に育てたら良い子に育つのか実験しました。 ハッキリ言って、知識を持てるほど学習していないし(小さすぎてできないし)、特に役に立つ回答はしてくれませんが、 結構なんでやねん!!!ってツッコみたくなる文章を書いてくれます。 日本語に関しては、一応ちゃんとしてるよ。
サンプルコード。モデルのロードは少し時間が掛かりますが、Inferenceは結構速いです。 GenerationConfigが必須。モデルが小さいので、beam searchや repeat関係は結構重要。
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
import torch
import time
import random
import numpy as np
#
# Fix seed
#
seed = 42
random.seed(seed)
# Numpy
np.random.seed(seed)
# Pytorch
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.backends.cudnn.deterministic = True
torch.use_deterministic_algorithms = True
torch.set_default_dtype(torch.bfloat16)
model_id = "aerner/lm-v1"
text = """### Instruction:
東京駅について説明してください。
### Context:
### Answer:
"""
with torch.no_grad():
tokenizer = AutoTokenizer.from_pretrained(model_id)
tokenized_input = tokenizer(text, return_tensors="pt").to('cuda')
model = AutoModelForCausalLM.from_pretrained(
model_id, device_map="auto", torch_dtype=torch.bfloat16)
generation_config = GenerationConfig(
max_new_tokens=256,
min_new_tokens=1,
early_stopping=True,
do_sample=True,
num_beams=8,
temperature=1.0,
top_p=0.6,
penalty_alpha=0.4,
no_repeat_ngram_size=4,
repetition_penalty=1.4,
remove_invalid_values=True,
num_return_sequences=1,
)
start = time.time()
generation_output = model.generate(
input_ids=tokenized_input['input_ids'],
generation_config=generation_config,
return_dict_in_generate=True,
output_scores=True,
)
for s in generation_output.sequences:
output = tokenizer.decode(s)
print(output)
print(time.time() - start)