Text Generation
Transformers
PyTorch
TensorFlow
JAX
LiteRT
Rust
ONNX
Safetensors
English
gpt2
exbert
text-generation-inference
Instructions to use jduhmbd/gpt2-test with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jduhmbd/gpt2-test with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="jduhmbd/gpt2-test")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("jduhmbd/gpt2-test") model = AutoModelForCausalLM.from_pretrained("jduhmbd/gpt2-test", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use jduhmbd/gpt2-test with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "jduhmbd/gpt2-test" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "jduhmbd/gpt2-test", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/jduhmbd/gpt2-test
- SGLang
How to use jduhmbd/gpt2-test 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 "jduhmbd/gpt2-test" \ --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": "jduhmbd/gpt2-test", "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 "jduhmbd/gpt2-test" \ --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": "jduhmbd/gpt2-test", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use jduhmbd/gpt2-test with Docker Model Runner:
docker model run hf.co/jduhmbd/gpt2-test
| from typing import Dict, List, Any | |
| import torch | |
| from transformers import pipeline, set_seed | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| self.pipeline = pipeline( | |
| "text-generation", | |
| model="openai-community/gpt2", | |
| device_map='auto', | |
| #trust_remote_code=True, | |
| model_kwargs={ | |
| "load_in_4bit": True | |
| }, | |
| # batch_size=1, | |
| ) | |
| # model.generation_config | |
| def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: | |
| """ | |
| data args: | |
| inputs (:obj: `str`) | |
| parameters (:obj: `Dict`) | |
| Return: | |
| A :obj:`list` | `dict`: will be serialized and returned | |
| """ | |
| # get inputs | |
| inputs = data.pop("inputs", "") | |
| # get additional date field | |
| params = data.pop("parameters", ()) | |
| if not params: | |
| params = dict() | |
| set_seed(42) | |
| # run normal prediction | |
| generation = self.pipeline(inputs, **params) | |
| # **generate_kwargs https://huggingface.co/docs/transformers/generation_strategies#customize-text-generation, | |
| # https://huggingface.co/docs/transformers/generation_strategies#customize-text-generation | |
| return generation | |
| # Returns | |
| # A list or a list of list of dict | |
| # Returns one of the following dictionaries (cannot return a combination of both generated_text and generated_token_ids): | |
| # generated_text (str, present when return_text=True) — The generated text. | |
| # generated_token_ids (torch.Tensor or tf.Tensor, present when return_tensors=True) — The token ids of the generated text. |