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")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("naniltx/codonGPT") model = AutoModelForCausalLM.from_pretrained("naniltx/codonGPT", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- 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
Download tokenizer.py from naniltx/codonGPT: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/naniltx/codonGPT/resolve/refs%2Fpr%2F3/tokenizer.py
- Command line
-
hf download hf://naniltx/codonGPT@refs/pr/3/tokenizer.py
-
curl -L -o tokenizer.py https://huggingface.co/naniltx/codonGPT/resolve/refs%2Fpr%2F3/tokenizer.py
1.46 kB
| # tokenizer.py | |
| from transformers import PreTrainedTokenizer | |
| from itertools import product | |
| import json | |
| import os | |
| class CodonTokenizer(PreTrainedTokenizer): | |
| def __init__(self, **kwargs): | |
| bases = ['A', 'T', 'G', 'C'] | |
| codons = [''.join(p) for p in product(bases, repeat=3)] | |
| special_tokens = ['[PAD]', '[BOS]', '[EOS]'] | |
| self.vocab_list = special_tokens + codons | |
| self.codon2id = {token: idx for idx, token in enumerate(self.vocab_list)} | |
| self.id2codon = {idx: token for token, idx in self.codon2id.items()} | |
| kwargs['bos_token'] = '[BOS]' | |
| kwargs['eos_token'] = '[EOS]' | |
| kwargs['pad_token'] = '[PAD]' | |
| super().__init__(**kwargs) | |
| def _tokenize(self, text): | |
| return [text[i:i+3] for i in range(0, len(text), 3)] | |
| def _convert_token_to_id(self, token): | |
| return self.codon2id.get(token, self.codon2id['[PAD]']) | |
| def _convert_id_to_token(self, idx): | |
| return self.id2codon.get(idx, '[PAD]') | |
| def convert_tokens_to_string(self, tokens): | |
| return ''.join(tokens) | |
| def get_vocab(self): | |
| return self.codon2id | |
| def vocab_size(self): | |
| return len(self.codon2id) | |
| def save_vocabulary(self, save_directory, filename_prefix=None): | |
| path = os.path.join(save_directory, (filename_prefix or "") + "vocab.json") | |
| with open(path, "w") as f: | |
| json.dump(self.codon2id, f) | |
| return (path,) |