Text Generation
Transformers
PyTorch
Safetensors
English
prot2text
feature-extraction
Causal Language Modeling
GPT2
ESM2
Proteins
GNN
custom_code
Instructions to use habdine/Esm2Text-Base-v1-1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use habdine/Esm2Text-Base-v1-1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="habdine/Esm2Text-Base-v1-1", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("habdine/Esm2Text-Base-v1-1", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use habdine/Esm2Text-Base-v1-1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "habdine/Esm2Text-Base-v1-1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "habdine/Esm2Text-Base-v1-1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/habdine/Esm2Text-Base-v1-1
- SGLang
How to use habdine/Esm2Text-Base-v1-1 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 "habdine/Esm2Text-Base-v1-1" \ --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": "habdine/Esm2Text-Base-v1-1", "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 "habdine/Esm2Text-Base-v1-1" \ --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": "habdine/Esm2Text-Base-v1-1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use habdine/Esm2Text-Base-v1-1 with Docker Model Runner:
docker model run hf.co/habdine/Esm2Text-Base-v1-1
Update modeling_prot2text.py
Browse files- modeling_prot2text.py +28 -6
modeling_prot2text.py
CHANGED
|
@@ -123,9 +123,17 @@ class Prot2TextModel(PreTrainedModel):
|
|
| 123 |
|
| 124 |
@torch.no_grad()
|
| 125 |
def generate_protein_description(self,
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
):
|
| 130 |
|
| 131 |
if self.config.esm and not self.config.rgcn and protein_sequence==None:
|
|
@@ -147,9 +155,23 @@ class Prot2TextModel(PreTrainedModel):
|
|
| 147 |
inputs = {k: v.to(device=device, non_blocking=True) if hasattr(v, 'to') else v for k, v in inputs.items()}
|
| 148 |
encoder_state = dict()
|
| 149 |
encoder_state['hidden_states'] = self(**inputs, get_graph_emb=True, output_attentions=True)
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
@torch.no_grad()
|
| 155 |
def generate(self,
|
|
|
|
| 123 |
|
| 124 |
@torch.no_grad()
|
| 125 |
def generate_protein_description(self,
|
| 126 |
+
protein_sequence=None,
|
| 127 |
+
tokenizer=None,
|
| 128 |
+
device='cpu',
|
| 129 |
+
streamer=None,
|
| 130 |
+
max_new_tokens=None,
|
| 131 |
+
do_sample=None,
|
| 132 |
+
top_p=None,
|
| 133 |
+
top_k=None,
|
| 134 |
+
temperature=None,
|
| 135 |
+
num_beams=1,
|
| 136 |
+
repetition_penalty=None
|
| 137 |
):
|
| 138 |
|
| 139 |
if self.config.esm and not self.config.rgcn and protein_sequence==None:
|
|
|
|
| 155 |
inputs = {k: v.to(device=device, non_blocking=True) if hasattr(v, 'to') else v for k, v in inputs.items()}
|
| 156 |
encoder_state = dict()
|
| 157 |
encoder_state['hidden_states'] = self(**inputs, get_graph_emb=True, output_attentions=True)
|
| 158 |
+
if streamer is None:
|
| 159 |
+
generated = tokenizer.batch_decode(self.decoder.generate(input_ids=inputs['decoder_input_ids'], encoder_outputs=encoder_state, use_cache=True), skip_special_tokens=True)
|
| 160 |
+
return generated[0].replace('<|stop_token|>', '').replace('<|graph_token|>', '')
|
| 161 |
+
else:
|
| 162 |
+
return self.decoder.generate(input_ids=inputs['decoder_input_ids'],
|
| 163 |
+
encoder_outputs=encoder_state,
|
| 164 |
+
use_cache=True,
|
| 165 |
+
streamer=streamer,
|
| 166 |
+
max_new_tokens=max_new_tokens,
|
| 167 |
+
do_sample=do_sample,
|
| 168 |
+
top_p=top_p,
|
| 169 |
+
top_k=top_k,
|
| 170 |
+
temperature=temperature,
|
| 171 |
+
num_beams=1,
|
| 172 |
+
repetition_penalty=repetition_penalty)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
|
| 176 |
@torch.no_grad()
|
| 177 |
def generate(self,
|