Instructions to use rmihaylov/gpt2-medium-bg with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use rmihaylov/gpt2-medium-bg with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="rmihaylov/gpt2-medium-bg", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("rmihaylov/gpt2-medium-bg", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("rmihaylov/gpt2-medium-bg", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use rmihaylov/gpt2-medium-bg with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "rmihaylov/gpt2-medium-bg" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "rmihaylov/gpt2-medium-bg", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/rmihaylov/gpt2-medium-bg
- SGLang
How to use rmihaylov/gpt2-medium-bg 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 "rmihaylov/gpt2-medium-bg" \ --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": "rmihaylov/gpt2-medium-bg", "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 "rmihaylov/gpt2-medium-bg" \ --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": "rmihaylov/gpt2-medium-bg", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use rmihaylov/gpt2-medium-bg with Docker Model Runner:
docker model run hf.co/rmihaylov/gpt2-medium-bg
| from torch import nn | |
| from transformers import GPT2LMHeadModel as GPT2LMHeadModelBase | |
| from transformers.models.gpt2.modeling_gpt2 import GPT2Block as GPT2BlockBase | |
| class GPT2Block(GPT2BlockBase): | |
| def forward(self, x, layer_past=None, | |
| attention_mask=None, head_mask=None, use_cache=False, | |
| encoder_hidden_states=None, encoder_attention_mask=None, output_attentions=None): | |
| x = self.ln_1(x) | |
| output_attn = self.attn( | |
| x, layer_past=layer_past, | |
| attention_mask=attention_mask, | |
| head_mask=head_mask, | |
| use_cache=use_cache) | |
| a = output_attn[0] | |
| x = x + a | |
| m = self.mlp(self.ln_2(x)) | |
| x = x + m | |
| outputs = (x,) + output_attn[1:] | |
| return outputs | |
| class GPT2LMHeadModel(GPT2LMHeadModelBase): | |
| def __init__(self, config): | |
| super().__init__(config) | |
| self.transformer.h = nn.ModuleList([GPT2Block(config, layer_idx) for layer_idx in range(config.n_layer)]) |