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")# 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
| 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と延長。 | |
| 学習記録はこちら | |
| https://wandb.ai/tahomatx/huggingface/runs/xyy19rbx | |
| Instruction-Answer例 | |
| ※ モデルは、Instructionの後に、Answerを追記します。入力は、Instruction部分までを入力します。 | |
| ``` | |
| ### Instruction: | |
| 東京駅について説明してください。 | |
| ### Context: | |
| ### Answer: | |
| 東急東横線・神楽坂駅から徒歩約10分のところに位置している。改札口は1ヶ所のみで、乗車券は駅前ロータリーに設置されており、自動券売機等の設備はない。出入口は1番から4番までの合計6ヵ所あり、それぞれのホームには駐輪場が設けられている(2019年3月現在)。 ⁇ 無人駅である。 ⁇ 簡易委託駅であったが、2018年3月31日をもって廃止され、有人駅時代の駅舎は取り壊されてしまった。 | |
| JR東日本ステーションサービスによる業務 | |
| ``` | |
| ``` | |
| ### Instruction: | |
| ドラえもんについて説明してください。 | |
| ### Context: | |
| ### Answer: | |
| 2007年10月1日から2008年3月31日まで放送された約5分の短編ドラマ。主演は声優の山口智充、脚本・演出は鈴木亜美子。原作とは異なるストーリーが展開されており、登場人物の設定もそれに合わせて変更され ている。 | |
| ``` | |
| サンプルコードです。 | |
| ```python | |
| from transformers import OpenLlamaForCausalLM, LlamaTokenizer, GenerationConfig, TextStreamer, AutoModelForCausalLM | |
| import torch | |
| import random | |
| import numpy as np | |
| import time | |
| # | |
| # 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-v2" | |
| text = """### Instruction: | |
| 東京駅について説明してください。 | |
| ### Context: | |
| ### Answer: | |
| """ | |
| with torch.no_grad(): | |
| tokenizer = LlamaTokenizer.from_pretrained(model_id) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_id, | |
| device_map="auto", | |
| torch_dtype=torch.bfloat16, | |
| # load_in_8bit=True, | |
| ) | |
| 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() | |
| tokenized_input = tokenizer(text, return_tensors="pt").to('cuda') | |
| 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) | |
| ``` | |