Instructions to use microsoft/biogpt with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/biogpt with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="microsoft/biogpt")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("microsoft/biogpt") model = AutoModelForCausalLM.from_pretrained("microsoft/biogpt", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use microsoft/biogpt with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/biogpt" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/biogpt", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/microsoft/biogpt
- SGLang
How to use microsoft/biogpt 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 "microsoft/biogpt" \ --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": "microsoft/biogpt", "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 "microsoft/biogpt" \ --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": "microsoft/biogpt", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use microsoft/biogpt with Docker Model Runner:
docker model run hf.co/microsoft/biogpt
BioGptTokenizer vs AutoTokenizer
In the model card, the sample code uses BioGptTokenizer instead of the usual transformers.AutoTokenizer.
Comparing the encoded inputs of the two tokenizers, the IDs seem to be the same for the texts I used.
The model instantiated from BioGptForCausalLM.from_pretrained("microsoft/biogpt") takes the encoded input from either tokenize no problem but the output keys are different.
For AutoTokenizer I get odict_keys(['last_hidden_state', 'past_key_values']), but for BioGptTokenizer I get odict_keys(['logits', 'past_key_values']).
Are last_hidden_state and logits token embeddings or something else?
I get torch.Size([1, n, 1024]) torch.Size([1, n, 42384]) where n is the number of input tokens.
Hi,
If you use
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("microsoft/biogpt")
print(type(tokenizer))
you'll see that it automatically maps to a BioGptTokenizer. So both are equivalent (Auto tokenizer uses the fast tokenizer by default, if there is one).
Do you have a reproducible code snippet that shows that you get different keys in the output dictionary depending on the tokenizer? That shouldn't be the case.
Yes you are right. In the case with odict_keys(['last_hidden_state', 'past_key_values']) I was loading the bare model BioGptModel.from_pretrained("microsoft/biogpt") without the head. I mistakenly thought it was the tokenizer.
The bare model is sufficient for getting the input embeddings as I don't need it transformed back into the vocabulary. Is my understanding correct?
Yes, BioGptModel will only output the "last hidden states" (also called embeddings) for each of the text tokens (input_ids) being passed through it.
BioGptForCausalLM on the other hand will add a classifier head on top of BioGptModel that maps those last hidden states to token indices.
Thanks for clearing it up!