Instructions to use aerner/lm-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use aerner/lm-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="aerner/lm-v2")# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("aerner/lm-v2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use aerner/lm-v2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "aerner/lm-v2" # 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-v2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/aerner/lm-v2
- SGLang
How to use aerner/lm-v2 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 "aerner/lm-v2" \ --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-v2", "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 "aerner/lm-v2" \ --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-v2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use aerner/lm-v2 with Docker Model Runner:
docker model run hf.co/aerner/lm-v2
|
Download README.md from aerner/lm-v2: direct link, hf CLI and curl.
- Browser
- Download file 2.58 kB
-
https://huggingface.co/aerner/lm-v2/resolve/refs%2Fpr%2F3/README.md
- Command line
-
hf download hf://aerner/lm-v2@refs/pr/3/README.md
-
curl -L -o README.md https://huggingface.co/aerner/lm-v2/resolve/refs%2Fpr%2F3/README.md
2.58 kB
metadata
datasets:
- snow_simplified_japanese_corpus
- mkqa
- llm-book/aio_v2
- paws
- lmqg/qg_jaquad
- SkelterLabsInc/JaQuAD
- karakuri-ai/dolly-15k-ja
- MBZUAI/Bactrian-X
- GEM/wiki_lingua
- csebuetnlp/xlsum
language:
- ja
Aerner LM-v2
事前学習から全部日本語で学習させたモデルのバージョン2です。 LLaMAベースで、24GBのVRAMで事前学習できる規模に小さなモデルです。
Flash Attentionが使用されているOpenLLaMAを使用しています。 Wikipediaのデータが中心なので、回答はWikipediaっぽい感じになります。
V1に比べると、モノや場所などの概念を持っているようないないような。 データセットはV1と同じですが、学習ステップ数が76,000と延長。
サンプルコード。モデルのロードは少し時間が掛かりますが、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)