Text Generation
Transformers
Safetensors
English
Chinese
qwen2
BioQwen
0.5B
Biomedical
Multi-Tasks
conversational
text-generation-inference
Instructions to use liyinghong/BioQwen-0.5B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use liyinghong/BioQwen-0.5B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="liyinghong/BioQwen-0.5B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("liyinghong/BioQwen-0.5B") model = AutoModelForCausalLM.from_pretrained("liyinghong/BioQwen-0.5B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use liyinghong/BioQwen-0.5B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "liyinghong/BioQwen-0.5B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "liyinghong/BioQwen-0.5B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/liyinghong/BioQwen-0.5B
- SGLang
How to use liyinghong/BioQwen-0.5B 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 "liyinghong/BioQwen-0.5B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "liyinghong/BioQwen-0.5B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "liyinghong/BioQwen-0.5B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "liyinghong/BioQwen-0.5B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use liyinghong/BioQwen-0.5B with Docker Model Runner:
docker model run hf.co/liyinghong/BioQwen-0.5B
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
datasets:
|
| 4 |
+
- yueqingyou/BioQwen
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
- zh
|
| 8 |
+
tags:
|
| 9 |
+
- BioQwen
|
| 10 |
+
- 0.5B
|
| 11 |
+
- Biomedical
|
| 12 |
+
- Multi-Tasks
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# BioQwen: A Small-Parameter, High-Performance Bilingual Model for Biomedical Multi-Tasks
|
| 16 |
+
|
| 17 |
+
For model inference, please refer to the following example code:
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
import torch
|
| 21 |
+
import transformers
|
| 22 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 23 |
+
|
| 24 |
+
transformers.logging.set_verbosity_error()
|
| 25 |
+
max_length = 512
|
| 26 |
+
model_path = 'yueqingyou/BioQwen-0.5B'
|
| 27 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, use_fast=True)
|
| 28 |
+
model = AutoModelForCausalLM.from_pretrained(model_path, device_map='auto', torch_dtype=torch.bfloat16, attn_implementation='flash_attention_2').eval()
|
| 29 |
+
|
| 30 |
+
def predict(prompt):
|
| 31 |
+
zh_system = "你是千问生物智能助手,一个专注于生物领域的先进人工智能。"
|
| 32 |
+
en_system = "You are BioQwen, an advanced AI specializing in the field of biology."
|
| 33 |
+
|
| 34 |
+
english_count, chinese_count = 0, 0
|
| 35 |
+
for char in prompt:
|
| 36 |
+
if '\u4e00' <= char <= '\u9fff':
|
| 37 |
+
chinese_count += 1
|
| 38 |
+
elif 'a' <= char.lower() <= 'z':
|
| 39 |
+
english_count += 1
|
| 40 |
+
lang = 'zh' if chinese_count > english_count else 'en'
|
| 41 |
+
|
| 42 |
+
messages = [
|
| 43 |
+
{"role": "system", "content": zh_system if lang == 'zh' else en_system},
|
| 44 |
+
{"role": "user", "content": prompt}
|
| 45 |
+
]
|
| 46 |
+
text = tokenizer.apply_chat_template(
|
| 47 |
+
messages,
|
| 48 |
+
tokenize=False,
|
| 49 |
+
add_generation_prompt=True
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
model_inputs = tokenizer([text], return_tensors="pt").to('cuda')
|
| 53 |
+
|
| 54 |
+
with torch.no_grad():
|
| 55 |
+
generated_ids = model.generate(
|
| 56 |
+
model_inputs.input_ids,
|
| 57 |
+
max_new_tokens=max_length,
|
| 58 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 59 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 60 |
+
do_sample=True,
|
| 61 |
+
top_p = 0.9,
|
| 62 |
+
temperature = 0.3,
|
| 63 |
+
repetition_penalty = 1.1
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
generated_ids = [
|
| 67 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 68 |
+
]
|
| 69 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 70 |
+
|
| 71 |
+
return response.strip()
|
| 72 |
+
|
| 73 |
+
prompt = 'I am suffering from irregular periods. I am currently taking medication Levothyroxine 50. My T3 is 0.87 ng/mL, T4 is 8.30 ug/dL, TSH is 2.43 uIU/mL. I am 34 years old, weigh 75 kg, and 5 feet tall. Please advice.'
|
| 74 |
+
print(f'Question:\t{prompt}\n\nAnswer:\t{predict(prompt)}')
|
| 75 |
+
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
For more detailed information and code, please refer to [GitHub](https://github.com/yueqingyou/BioQwen).
|