Instructions to use baotoan2002/GPT-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use baotoan2002/GPT-2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="baotoan2002/GPT-2")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("baotoan2002/GPT-2") model = AutoModelForCausalLM.from_pretrained("baotoan2002/GPT-2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use baotoan2002/GPT-2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "baotoan2002/GPT-2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "baotoan2002/GPT-2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/baotoan2002/GPT-2
- SGLang
How to use baotoan2002/GPT-2 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 "baotoan2002/GPT-2" \ --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": "baotoan2002/GPT-2", "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 "baotoan2002/GPT-2" \ --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": "baotoan2002/GPT-2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use baotoan2002/GPT-2 with Docker Model Runner:
docker model run hf.co/baotoan2002/GPT-2
Commit ·
f9affc0
1
Parent(s): 356707e
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
| 1 |
---
|
| 2 |
license: openrail
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: openrail
|
| 3 |
+
metrics:
|
| 4 |
+
- bleu
|
| 5 |
+
library_name: adapter-transformers
|
| 6 |
+
pipeline_tag: text-generation
|
| 7 |
+
tags:
|
| 8 |
+
- code
|
| 9 |
---
|
| 10 |
+
|
| 11 |
+
## Text Generation Using GPT-2 in Hugging Face
|
| 12 |
+
This repository provides an example of how to use the GPT-2 language model in Hugging Face for text generation tasks. GPT-2 is a powerful natural language processing model that can generate human-like text, and Hugging Face is a popular open-source library for working with NLP models.
|
| 13 |
+
|
| 14 |
+
## Requirements
|
| 15 |
+
Python 3.6 or higher
|
| 16 |
+
Hugging Face transformers library
|
| 17 |
+
PyTorch or TensorFlow
|
| 18 |
+
|
| 19 |
+
## Installation
|
| 20 |
+
Clone this repository: git clone ```https://github.com/sonyway01/Deep-Learning/Final%20Project```
|
| 21 |
+
Navigate to the repository directory: ```cd Final Project```
|
| 22 |
+
Install the required libraries: ```pip install -r requirements.txt```
|
| 23 |
+
|
| 24 |
+
## Usage
|
| 25 |
+
Download the GPT-2 pre-trained model: ```python download_model.py```
|
| 26 |
+
Edit the ```generate_text.py``` file to include your desired prompt and generate settings.
|
| 27 |
+
Run the ```generate_text.py file``` to generate text: ```python generate_text.py```
|
| 28 |
+
Customization
|
| 29 |
+
You can customize the GPT-2 model and the text generation settings by editing the ```generate_text.py``` file. For example, you can change the prompt text, the number of tokens to generate, the temperature setting for the model, and more.
|
| 30 |
+
|
| 31 |
+
## References
|
| 32 |
+
Hugging Face Transformers library: ```https://github.com/huggingface/transformers```
|
| 33 |
+
GPT-2 model by me: ```https://huggingface.co/baotoan2002/GPT-2```
|
| 34 |
+
OpenAI GPT-2 model: ```https://openai.com/models/gpt-2/```
|
| 35 |
+
|
| 36 |
+
## License
|
| 37 |
+
This repository is licensed under the [openrail] License. See the LICENSE file for details.
|
| 38 |
+
|
| 39 |
+
## Acknowledgments
|
| 40 |
+
Special thanks to the Hugging Face team for their excellent work on the Transformers library.
|
| 41 |
+
Thanks to OpenAI for providing the pre-trained GPT-2 model.
|