Instructions to use aframson/RDPDLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use aframson/RDPDLM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="aframson/RDPDLM", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("aframson/RDPDLM", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use aframson/RDPDLM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "aframson/RDPDLM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "aframson/RDPDLM", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/aframson/RDPDLM
- SGLang
How to use aframson/RDPDLM 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 "aframson/RDPDLM" \ --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": "aframson/RDPDLM", "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 "aframson/RDPDLM" \ --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": "aframson/RDPDLM", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use aframson/RDPDLM with Docker Model Runner:
docker model run hf.co/aframson/RDPDLM
File size: 2,047 Bytes
5376a3f | 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 42 43 44 45 46 47 48 49 50 | import torch
import torch.nn as nn
import torch.nn.functional as F
from transformers.modeling_utils import PreTrainedModel
# Define your custom language model class
class OBILanguageModel(PreTrainedModel):
def __init__(self, config):
super(OBILanguageModel,self).__init__(config)
self.token_embedding_table = nn.Embedding(config.vocab_size, config.hidden_size) # Use length of SentencePiece vocab
self.position_embedding_table = nn.Embedding(config.block_size, config.hidden_size)
self.transformer = nn.Transformer(
d_model=config.hidden_size,
nhead=config.num_attention_heads,
num_encoder_layers=config.num_hidden_layers,
num_decoder_layers=config.num_hidden_layers,
dim_feedforward=4 * config.hidden_size,
dropout=config.hidden_dropout_prob,
activation='gelu'
)
self.ln1 = nn.LayerNorm(config.hidden_size)
self.ln2 = nn.LayerNorm(config.hidden_size)
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size) # Use length of SentencePiece vocab
def forward(self, idx, targets=None):
tok_emb = self.token_embedding_table(idx)
pos_emb = self.position_embedding_table(torch.arange(idx.size(1), device='cpu'))
x = tok_emb + pos_emb
x = self.transformer(x, x)
x = self.ln1(x)
x = self.ln2(x)
logits = self.lm_head(x)
if targets is None:
loss = None
else:
loss = F.cross_entropy(logits.view(-1, self.config.vocab_size), targets.view(-1))
return logits, loss
def generate(self, idx, max_new_tokens):
for _ in range(max_new_tokens):
idx_cond = idx[:, -self.config.block_size:]
logits, loss = self(idx_cond)
logits = logits[:, -1, :]
probs = F.softmax(logits, dim=-1)
idx_next = torch.multinomial(probs, num_samples=1)
idx = torch.cat((idx, idx_next), dim=1)
return idx
|