Instructions to use naniltx/codonGPT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use naniltx/codonGPT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="naniltx/codonGPT")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("naniltx/codonGPT") model = AutoModelForCausalLM.from_pretrained("naniltx/codonGPT") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use naniltx/codonGPT with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "naniltx/codonGPT" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "naniltx/codonGPT", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/naniltx/codonGPT
- SGLang
How to use naniltx/codonGPT 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 "naniltx/codonGPT" \ --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": "naniltx/codonGPT", "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 "naniltx/codonGPT" \ --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": "naniltx/codonGPT", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use naniltx/codonGPT with Docker Model Runner:
docker model run hf.co/naniltx/codonGPT
Create tokenizer.py
Browse files- tokenizer.py +46 -0
tokenizer.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# tokenizer.py
|
| 2 |
+
|
| 3 |
+
from transformers import PreTrainedTokenizer
|
| 4 |
+
from itertools import product
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
class CodonTokenizer(PreTrainedTokenizer):
|
| 9 |
+
def __init__(self, **kwargs):
|
| 10 |
+
bases = ['A', 'T', 'G', 'C']
|
| 11 |
+
codons = [''.join(p) for p in product(bases, repeat=3)]
|
| 12 |
+
special_tokens = ['[PAD]', '[BOS]', '[EOS]']
|
| 13 |
+
self.vocab_list = special_tokens + codons
|
| 14 |
+
|
| 15 |
+
self.codon2id = {token: idx for idx, token in enumerate(self.vocab_list)}
|
| 16 |
+
self.id2codon = {idx: token for token, idx in self.codon2id.items()}
|
| 17 |
+
|
| 18 |
+
kwargs['bos_token'] = '[BOS]'
|
| 19 |
+
kwargs['eos_token'] = '[EOS]'
|
| 20 |
+
kwargs['pad_token'] = '[PAD]'
|
| 21 |
+
super().__init__(**kwargs)
|
| 22 |
+
|
| 23 |
+
def _tokenize(self, text):
|
| 24 |
+
return [text[i:i+3] for i in range(0, len(text), 3)]
|
| 25 |
+
|
| 26 |
+
def _convert_token_to_id(self, token):
|
| 27 |
+
return self.codon2id.get(token, self.codon2id['[PAD]'])
|
| 28 |
+
|
| 29 |
+
def _convert_id_to_token(self, idx):
|
| 30 |
+
return self.id2codon.get(idx, '[PAD]')
|
| 31 |
+
|
| 32 |
+
def convert_tokens_to_string(self, tokens):
|
| 33 |
+
return ''.join(tokens)
|
| 34 |
+
|
| 35 |
+
def get_vocab(self):
|
| 36 |
+
return self.codon2id
|
| 37 |
+
|
| 38 |
+
@property
|
| 39 |
+
def vocab_size(self):
|
| 40 |
+
return len(self.codon2id)
|
| 41 |
+
|
| 42 |
+
def save_vocabulary(self, save_directory, filename_prefix=None):
|
| 43 |
+
path = os.path.join(save_directory, (filename_prefix or "") + "vocab.json")
|
| 44 |
+
with open(path, "w") as f:
|
| 45 |
+
json.dump(self.codon2id, f)
|
| 46 |
+
return (path,)
|