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 test_quickstart.py from naniltx/codonGPT: direct link, hf CLI and curl.
- Browser
- Download file 3.62 kB
-
https://huggingface.co/naniltx/codonGPT/resolve/refs%2Fpr%2F4/test_quickstart.py
- Command line
-
hf download hf://naniltx/codonGPT@refs/pr/4/test_quickstart.py
-
curl -L -o test_quickstart.py https://huggingface.co/naniltx/codonGPT/resolve/refs%2Fpr%2F4/test_quickstart.py
3.62 kB
| #!/usr/bin/env python3 | |
| """ | |
| Test the simplified quickstart guide examples | |
| """ | |
| import torch | |
| from transformers import GPT2LMHeadModel | |
| print("Testing simplified CodonGPT quickstart guide...") | |
| try: | |
| # Test 1: Download custom components (simulate what users would do) | |
| print("\n1. Testing custom component downloads...") | |
| from huggingface_hub import hf_hub_download | |
| # Download custom tokenizer and processor to current directory | |
| hf_hub_download(repo_id="naniltx/codonGPT", filename="tokenizer.py", local_dir="./") | |
| hf_hub_download(repo_id="naniltx/codonGPT", filename="synonymous_logit_processor.py", local_dir="./") | |
| print("β Custom components downloaded successfully") | |
| # Test 2: Import custom components | |
| print("\n2. Testing custom component imports...") | |
| from tokenizer import CodonTokenizer | |
| from synonymous_logit_processor import SynonymMaskingLogitsProcessor | |
| print("β Custom components imported successfully") | |
| # Test 3: Load model directly from HF | |
| print("\n3. Testing direct model loading from Hugging Face...") | |
| model = GPT2LMHeadModel.from_pretrained("naniltx/codonGPT") | |
| model.eval() | |
| print("β Model loaded directly from HF successfully") | |
| # Test 4: Load custom tokenizer | |
| print("\n4. Testing custom tokenizer...") | |
| tokenizer = CodonTokenizer() | |
| print(f"β Tokenizer loaded successfully (vocab size: {tokenizer.vocab_size})") | |
| # Test 5: Basic sequence generation | |
| print("\n5. Testing basic sequence generation...") | |
| input_sequence = "ATGAAACCC" | |
| input_codons = [input_sequence[i:i+3] for i in range(0, len(input_sequence), 3)] | |
| input_tokens = [tokenizer.bos_token_id] + tokenizer.convert_tokens_to_ids(input_codons) | |
| input_tensor = torch.tensor([input_tokens]) | |
| with torch.no_grad(): | |
| outputs = model.generate( | |
| input_tensor, | |
| max_length=input_tensor.size(1) + 3, | |
| temperature=1.0, | |
| do_sample=True, | |
| pad_token_id=tokenizer.pad_token_id, | |
| eos_token_id=tokenizer.eos_token_id | |
| ) | |
| generated_tokens = outputs[0][input_tensor.size(1):].tolist() | |
| generated_codons = [tokenizer.decode([token_id]) for token_id in generated_tokens | |
| if token_id not in [tokenizer.pad_token_id, tokenizer.eos_token_id]] | |
| generated_sequence = ''.join(generated_codons) | |
| print(f"β Input sequence: {input_sequence}") | |
| print(f"β Generated sequence: {generated_sequence}") | |
| # Test 6: Synonym-aware generation | |
| print("\n6. Testing synonym-aware generation...") | |
| from synonymous_logit_processor import generate_candidate_codons_with_generate | |
| from Bio.Seq import Seq | |
| initial_codons = ["ATG", "AAA", "CCC"] | |
| optimized_codons = generate_candidate_codons_with_generate( | |
| initial_codons, | |
| model=model, | |
| tokenizer=tokenizer, | |
| temperature=1.0, | |
| top_k=50, | |
| top_p=0.9 | |
| ) | |
| print(f"β Original: {initial_codons}") | |
| print(f"β Optimized: {optimized_codons}") | |
| # Verify amino acid preservation | |
| original_aa = ''.join([str(Seq(codon).translate()) for codon in initial_codons]) | |
| optimized_aa = ''.join([str(Seq(codon).translate()) for codon in optimized_codons]) | |
| print(f"β Original AA: {original_aa}") | |
| print(f"β Optimized AA: {optimized_aa}") | |
| print(f"β AA preserved: {original_aa == optimized_aa}") | |
| print("\nπ All simplified quickstart tests passed!") | |
| except Exception as e: | |
| print(f"\nβ Test failed with error: {e}") | |
| import traceback | |
| traceback.print_exc() |