Instructions to use knok/japanese-distilgpt2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use knok/japanese-distilgpt2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="knok/japanese-distilgpt2")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("knok/japanese-distilgpt2", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use knok/japanese-distilgpt2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "knok/japanese-distilgpt2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "knok/japanese-distilgpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/knok/japanese-distilgpt2
- SGLang
How to use knok/japanese-distilgpt2 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 "knok/japanese-distilgpt2" \ --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": "knok/japanese-distilgpt2", "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 "knok/japanese-distilgpt2" \ --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": "knok/japanese-distilgpt2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use knok/japanese-distilgpt2 with Docker Model Runner:
docker model run hf.co/knok/japanese-distilgpt2
日本語 gpt2 蒸留モデル
このモデルはrinna/japanese-gpt2-meduimを教師として蒸留したものです。 蒸留には、HuggigFace Transformersのコードをベースとし、りんなの訓練コードと組み合わせてデータ扱うよう改造したものを使っています。
訓練用コード: https://github.com/knok/japanese-pretrained-models
学習に関して
学習に当たり、Google Startup Programにて提供されたクレジットを用いました。 a2-highgpu-4インスタンス(A100 x 4)を使って4か月程度、何度かのresumeを挟んで訓練させました。
精度について
Wikipediaをコーパスとし、perplexity 40 程度となります。 rinna/japanese-gpt2-meduim を直接使った場合、27 程度なので、そこまで及びません。 何度か複数のパラメータで訓練の再開を試みたものの、かえって損失が上昇してしまう状態となってしまったので、現状のものを公開しています。
トークナイザについて
トークナイザは rinna/japanese-gpt2-meduim を使ってください。
Japanese GPT-2 model
This model is a dillated model from rinna/japanese-gpt2-medium. To train, I combined HuggingFace Transformers code and rinna gpt2 train code.
The code is available at: https://github.com/knok/japanese-pretrained-models
training environment
To train, I used GCP credit offered by Google Startup Progam. Using a2-highgpu-4 instance (A100 x4), it takes about 4 months with some stopping and resume training.
perplexity
The model gets about 40 perplexity with Wikipedia corpus. The teacher model rinna/japanese-gpt2-meduim gets about 27 perplexity, so the student model is worse.
tokenizer
The repository don't have tokenizer, so you shoud use rinna/japanese-gpt2-medium.
LICENSE
MIT (same as rinna/japanese-gpt2-medium)
- Downloads last month
- 17