Text Generation
Transformers
Safetensors
Chinese
qwen3
traditional-chinese-medicine
lingdan-v2
base
conversational
text-generation-inference
Instructions to use TCMLLM/Lingdan-4B-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TCMLLM/Lingdan-4B-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="TCMLLM/Lingdan-4B-Base") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("TCMLLM/Lingdan-4B-Base") model = AutoModelForCausalLM.from_pretrained("TCMLLM/Lingdan-4B-Base", 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use TCMLLM/Lingdan-4B-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "TCMLLM/Lingdan-4B-Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TCMLLM/Lingdan-4B-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/TCMLLM/Lingdan-4B-Base
- SGLang
How to use TCMLLM/Lingdan-4B-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 "TCMLLM/Lingdan-4B-Base" \ --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": "TCMLLM/Lingdan-4B-Base", "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 "TCMLLM/Lingdan-4B-Base" \ --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": "TCMLLM/Lingdan-4B-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use TCMLLM/Lingdan-4B-Base with Docker Model Runner:
docker model run hf.co/TCMLLM/Lingdan-4B-Base
File size: 6,932 Bytes
37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 9c62a2e 275ef44 37e0814 22b6010 5292509 275ef44 37e0814 22b6010 37e0814 275ef44 37e0814 d8f30f8 37e0814 275ef44 37e0814 d8f30f8 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 275ef44 37e0814 22b6010 37e0814 22b6010 37e0814 275ef44 37e0814 22b6010 37e0814 275ef44 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | ---
language:
- zh
license: apache-2.0
library_name: transformers
pipeline_tag: text-generation
tags:
- qwen3
- traditional-chinese-medicine
- lingdan-v2
- base
---
# Lingdan-4B-Base
<p align="center">
<img width="420" src="https://raw.githubusercontent.com/TCMAI-BJTU/Lingdan-V2/main/assets/logo.png" alt="Lingdan-V2 logo" />
</p>
<p align="center"><strong>Lingdan-V2: Large Language Models for Clinically Grounded Reasoning in Traditional Chinese Medicine</strong></p>
<p align="center">
<a href="https://lingdan.chat/">
<img src="https://img.shields.io/badge/OPEN_LINGDAN--V2_ONLINE-lingdan.chat-F28C28?style=for-the-badge&logo=googlechrome&logoColor=white" alt="Open the Lingdan-V2 online demo" />
</a>
</p>
<p align="center">
<a href="https://arxiv.org/abs/2610.14705"><img src="https://img.shields.io/badge/arXiv-2610.14705-B31B1B?logo=arxiv&logoColor=white" alt="Lingdan-V2 paper on arXiv" /></a>
<a href="https://huggingface.co/collections/TCMLLM/lingdan-v2"><img src="https://img.shields.io/badge/Models-Hugging_Face-FFD21E?logo=huggingface&logoColor=black" alt="Hugging Face models" /></a>
<a href="https://modelscope.cn/collections/TCMAIBJTU/Lingdan-V2"><img src="https://img.shields.io/badge/Models-ModelScope-624AFF" alt="ModelScope models" /></a>
<a href="https://github.com/TCMAI-BJTU/LingLan"><img src="https://img.shields.io/badge/Benchmark-LingLan-2A8F5B" alt="LingLan benchmark" /></a>
<img src="https://img.shields.io/badge/Model_scales-4B_%7C_8B_%7C_14B-0B5394" alt="Model scales: 4B, 8B, and 14B" />
<a href="https://github.com/TCMAI-BJTU/Lingdan-V2/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-Apache--2.0-D22128" alt="Apache License 2.0" /></a>
</p>
[Paper](https://arxiv.org/abs/2610.14705) · [Model](#model-details) · [Quickstart](#quickstart) · [vLLM](#vllm-deployment) · [Citation](#citation)
## Model Details
**Lingdan-4B-Base** is a Qwen3-based TCM model in the [Lingdan-V2 family](https://github.com/TCMAI-BJTU/Lingdan-V2).
| Field | Value |
| --- | --- |
| Parameter scale | 4B |
| Architecture family | Qwen3 causal language model |
| Training stage | Continued pretraining (CPT) |
| Starting checkpoint / backbone | Qwen3 4B backbone |
| Intended use | Text completion, domain research, and further fine-tuning |
| Platform model ID | `TCMLLM/Lingdan-4B-Base` |
### Training History
This checkpoint includes the following training stages, in order:
| Stage | Objective | Training data |
| --- | --- | --- |
| CPT — continued pretraining | TCM-domain knowledge acquisition | 16.62B tokens |
## Quickstart
Use Transformers ≥4.51.0; see the [Qwen3 quickstart](https://qwen.readthedocs.io/en/stable/getting_started/quickstart.html).
```bash
pip install -U torch transformers accelerate
```
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "TCMLLM/Lingdan-4B-Base"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto",
).eval()
# Base checkpoints are intended for completion and further fine-tuning.
text = "中医辨证论治的基本概念是"
inputs = tokenizer([text], return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=1024,
do_sample=True,
temperature=0.6,
top_p=0.95,
top_k=20,
)
new_tokens = outputs[0, inputs.input_ids.shape[1]:]
print(tokenizer.decode(new_tokens, skip_special_tokens=True))
```
## vLLM Deployment
Install vLLM in a GPU environment with compatible CUDA/PyTorch; see the [Qwen3 vLLM guide](https://qwen.readthedocs.io/en/stable/deployment/vllm.html).
```bash
pip install -U "vllm>=0.9.0" openai
```
### Start the Server
**Hugging Face:**
```bash
export VLLM_USE_MODELSCOPE=false
vllm serve TCMLLM/Lingdan-4B-Base \
--served-model-name Lingdan-4B-Base \
--host 127.0.0.1 \
--port 8000 \
--max-model-len 16384
```
Replace the repository ID with a local model directory to reuse downloaded files. For two GPUs, append `--tensor-parallel-size 2`. Adjust the 16,384-token context limit (input + output) to available GPU memory.
### Completion Client
```python
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="EMPTY")
response = client.completions.create(
model="Lingdan-4B-Base",
prompt="中医辨证论治的基本特点是",
max_tokens=512,
temperature=0.6,
top_p=0.95,
extra_body={"top_k": 20},
)
print(response.choices[0].text)
```
`EMPTY` is a placeholder for the local server started without API-key authentication.
## Data Privacy and Responsible Use
Lingdan-V2 is for research and does not replace qualified clinical judgment. Private clinical data are not released. Retrospective prescription agreement is not evidence of clinical safety or effectiveness; use de-identified inputs and professional review for any clinical application.
## License
Lingdan-V2 model weights and project-owned documentation and images are released under the [Apache License 2.0](https://github.com/TCMAI-BJTU/Lingdan-V2/blob/main/LICENSE). See [NOTICE](https://github.com/TCMAI-BJTU/Lingdan-V2/blob/main/NOTICE) for attribution notices. Third-party data and materials remain subject to their original terms.
## Citation
Please cite Lingdan-V2 and the earlier Lingdan work:
```bibtex
@misc{hua2026lingdanv2,
title = {{Lingdan-V2}: Large language models for clinically grounded reasoning in traditional Chinese medicine},
author = {Hua, Rui and Wei, Yu and Jin, Ziri and Sun, Zhuo and Chang, Kai and Xia, Jianan and Shu, Zixin and Li, Xiaodong and Jia, Dongmei and Dong, Fei and Zhang, Runshun and Yu, Jian and Xu, Hao and Yu, Haibin and Li, Jiansheng and Liu, Baoyan and Wang, Wenjia and Zhou, Xuezhong},
year = {2026},
eprint = {2610.14705},
archivePrefix = {arXiv},
primaryClass = {cs.CL},
url = {https://arxiv.org/abs/2610.14705}
}
@article{hua2024lingdan,
title={Lingdan: enhancing encoding of traditional Chinese medicine knowledge for clinical reasoning tasks with large language models},
author={Hua, Rui and Dong, Xin and Wei, Yu and Shu, Zixin and Yang, Pengcheng and Hu, Yunhui and Zhou, Shuiping and Sun, He and Yan, Kaijing and Yan, Xijun and others},
journal={Journal of the American Medical Informatics Association},
volume={31},
number={9},
pages={2019--2029},
year={2024},
publisher={Oxford University Press}
}
```
## Related Links
[Paper](https://arxiv.org/abs/2610.14705) · [GitHub](https://github.com/TCMAI-BJTU/Lingdan-V2) · [Hugging Face collection](https://huggingface.co/collections/TCMLLM/lingdan-v2) · [ModelScope collection](https://modelscope.cn/collections/TCMAIBJTU/Lingdan-V2) · [LingLan benchmark](https://github.com/TCMAI-BJTU/LingLan)
For task prompts and thinking-mode chat, see the [SFT/R1 guide](https://github.com/TCMAI-BJTU/Lingdan-V2#task-prompts).
|