Instructions to use Datascience-Lab/GPT2-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Datascience-Lab/GPT2-small with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Datascience-Lab/GPT2-small")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Datascience-Lab/GPT2-small") model = AutoModelForCausalLM.from_pretrained("Datascience-Lab/GPT2-small") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Datascience-Lab/GPT2-small with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Datascience-Lab/GPT2-small" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Datascience-Lab/GPT2-small", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Datascience-Lab/GPT2-small
- SGLang
How to use Datascience-Lab/GPT2-small 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 "Datascience-Lab/GPT2-small" \ --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": "Datascience-Lab/GPT2-small", "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 "Datascience-Lab/GPT2-small" \ --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": "Datascience-Lab/GPT2-small", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Datascience-Lab/GPT2-small with Docker Model Runner:
docker model run hf.co/Datascience-Lab/GPT2-small
File size: 1,855 Bytes
ad6850d 276eb8e ad6850d 276eb8e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | ---
license: apache-2.0
tags: [gpt2]
language: ko
---
# KoGPT2-small
| Model | Batch Size | Tokenizer | Vocab Size | Max Length | Parameter Size |
|:---: | :------: | :-----: | :------: | :----: | :------: |
|GPT2 | 64 | BPE | 30,000 | 1024 | 108M |
# DataSet
- AIhub - ์น๋ฐ์ดํฐ ๊ธฐ๋ฐ ํ๊ตญ์ด ๋ง๋ญ์น ๋ฐ์ดํฐ (4.8M)
- KoWiki dump 230701 (1.4M)
# Inference Example
```python
from transformers import AutoTokenizer, GPT2LMHeadModel
text = "์ถ๊ทผ์ด ํ๋ค๋ฉด"
tokenizer = AutoTokenizer.from_pretrained('Datascience-Lab/GPT2-small')
model = GPT2LMHeadModel.from_pretrained('Datascience-Lab/GPT2-small')
inputs = tokenizer.encode_plus(text, return_tensors='pt', add_special_tokens=False)
outputs = model.generate(inputs['input_ids'], max_length=128,
repetition_penalty=2.0,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id,
bos_token_id=tokenizer.bos_token_id,
use_cache=True,
temperature = 0.5)
outputs = tokenizer.decode(outputs[0], skip_special_tokens=True)
# ์ถ๋ ฅ ๊ฒฐ๊ณผ : '์ถ๊ทผ์ด ํ๋ค๋ฉด ์ถ๊ทผ์ ํ์ง ์๋ ๊ฒ์ด ์ข๋ค. ํ์ง๋ง ์ถํด๊ทผ ์๊ฐ์ ๋ฆ์ถ๋ ๊ฒ์ ์คํ๋ ค ๊ฑด๊ฐ์ ์ข์ง ์๋ค.. ํนํ๋ ์ฅ์๊ฐ์ ์
๋ฌด๋ก ์ธํด ํผ๋ก๊ฐ ์์ด๊ณ ๋ฉด์ญ๋ ฅ์ด ๋จ์ด์ง๋ฉด, ํผ๋ก๊ฐ์ด ์ฌํด์ ธ์ ์ ๋ค๊ธฐ ์ด๋ ค์ด ๊ฒฝ์ฐ๊ฐ ๋ง๋ค. ์ด๋ฐ ๊ฒฝ์ฐ๋ผ๋ฉด ํ์๋ณด๋ค ๋ ๋ง์ ์์ผ๋ก ๊ณผ์์ ํ๊ฑฐ๋ ๋ฌด๋ฆฌํ ๋ค์ด์ดํธ๋ฅผ ํ ์ ์๋ค. ๋ฐ๋ผ์ ์๋จ ์กฐ์ ๊ณผ ํจ๊ป ์์ ๋ณด์ถฉ์ ์ ๊ฒฝ ์จ์ผ ํ๋ค. ๋ํ ๊ณผ๋ํ ์์์ด ์ฒด์ค ๊ฐ๋์ ๋์์ ์ฃผ๋ฏ๋ก ์ ์ ํ ์ด๋๋์ ์ ์งํ๋ ๊ฒ๋ ์ค์ํ๋ค.'
``` |