Text Generation
Transformers
Safetensors
t5
text2text-generation
biology
single-cell
single-cell analysis
text-generation-inference
Instructions to use zjunlp/chatcell-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zjunlp/chatcell-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="zjunlp/chatcell-base")# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("zjunlp/chatcell-base") model = AutoModelForSeq2SeqLM.from_pretrained("zjunlp/chatcell-base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use zjunlp/chatcell-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "zjunlp/chatcell-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zjunlp/chatcell-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/zjunlp/chatcell-base
- SGLang
How to use zjunlp/chatcell-base 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 "zjunlp/chatcell-base" \ --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": "zjunlp/chatcell-base", "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 "zjunlp/chatcell-base" \ --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": "zjunlp/chatcell-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use zjunlp/chatcell-base with Docker Model Runner:
docker model run hf.co/zjunlp/chatcell-base
Create handler.py
Browse files- handler.py +36 -0
handler.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, List
|
| 2 |
+
from transformers import (
|
| 3 |
+
AutoTokenizer,
|
| 4 |
+
AutoModelForSeq2SeqLM,
|
| 5 |
+
)
|
| 6 |
+
|
| 7 |
+
# in line with the default config of the model
|
| 8 |
+
CONFIG = {
|
| 9 |
+
'max_length': 512,
|
| 10 |
+
'num_return_sequences': 1,
|
| 11 |
+
'no_repeat_ngram_size': 2,
|
| 12 |
+
'top_k': 50,
|
| 13 |
+
'top_p': 0.95,
|
| 14 |
+
'do_sample': True,
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
class EndpointHandler:
|
| 18 |
+
def __init__(self, path: str = ""):
|
| 19 |
+
|
| 20 |
+
self.tokenizer = AutoTokenizer.from_pretrained(path)
|
| 21 |
+
self.model = AutoModelForSeq2SeqLM.from_pretrained(path)
|
| 22 |
+
|
| 23 |
+
def __call__(self, data: Dict[str, str]) -> List[Dict[str, str]]:
|
| 24 |
+
|
| 25 |
+
inputs = data.pop('inputs', None)
|
| 26 |
+
if inputs is None or inputs == '':
|
| 27 |
+
return [{'generated_text': 'No input provided'}]
|
| 28 |
+
|
| 29 |
+
# preprocess
|
| 30 |
+
input_ids = self.tokenizer(inputs, return_tensors="pt").input_ids
|
| 31 |
+
# inference
|
| 32 |
+
output_ids = self.model.generate(input_ids, **CONFIG)
|
| 33 |
+
# postprocess
|
| 34 |
+
response = self.tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 35 |
+
|
| 36 |
+
return [{'generated_text': response}]
|