Instructions to use baichuan-inc/Baichuan2-13B-Chat with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use baichuan-inc/Baichuan2-13B-Chat with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="baichuan-inc/Baichuan2-13B-Chat", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("baichuan-inc/Baichuan2-13B-Chat", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use baichuan-inc/Baichuan2-13B-Chat with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "baichuan-inc/Baichuan2-13B-Chat" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "baichuan-inc/Baichuan2-13B-Chat", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/baichuan-inc/Baichuan2-13B-Chat
- SGLang
How to use baichuan-inc/Baichuan2-13B-Chat 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 "baichuan-inc/Baichuan2-13B-Chat" \ --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": "baichuan-inc/Baichuan2-13B-Chat", "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 "baichuan-inc/Baichuan2-13B-Chat" \ --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": "baichuan-inc/Baichuan2-13B-Chat", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use baichuan-inc/Baichuan2-13B-Chat with Docker Model Runner:
docker model run hf.co/baichuan-inc/Baichuan2-13B-Chat
AttributeError: 'BaichuanTokenizer' object has no attribute 'sp_model'
AttributeError: 'BaichuanTokenizer' object has no attribute 'sp_model',
how to add support to latest transofmers? 4.34?
transfomers 4.34 doesn't work for me either. Degrading to 4.33.1 works in my case
Since vllm==0.2.1 requires transformers==4.34.1 support for mistral, I don't think downgrading is a good idea, could contributors fix this bug or tell me anything I could do for a temporary fix ?
Since vllm==0.2.1 requires transformers==4.34.1 support for mistral, I don't think downgrading is a good idea, could contributors fix this bug or tell me anything I could do for a temporary fix ?
solved with reference: https://github.com/huggingface/transformers/issues/26340#issuecomment-1766794575 , this may fix this bug for now.
Since vllm==0.2.1 requires transformers==4.34.1 support for mistral, I don't think downgrading is a good idea, could contributors fix this bug or tell me anything I could do for a temporary fix ?
solved with reference: https://github.com/huggingface/transformers/issues/26340#issuecomment-1766794575 , this may fix this bug for now.
It didn't work for me
update
tokenization_baichuan.py :
https://github.com/huggingface/transformers/issues/26340
You should file an issue on the model repos and tell them to rearrange the tokenizer init so that self.sp_model is created before calling super().init()
this solved the problem for me, edit tokenization_baichuan.py, in __init__, find super().__init__ function call and move it to the end of __init__
I solved the problem By
- pip install transformers==4.34.0
- move super().init like this
self.vocab_file = vocab_file
self.add_bos_token = add_bos_token
self.add_eos_token = add_eos_token
self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
self.sp_model.Load(vocab_file)
super().init(
bos_token=bos_token,
eos_token=eos_token,
unk_token=unk_token,
pad_token=pad_token,
add_bos_token=add_bos_token,
add_eos_token=add_eos_token,
sp_model_kwargs=self.sp_model_kwargs,
clean_up_tokenization_spaces=clean_up_tokenization_spaces,
**kwargs,
)
AttributeError: 'BaichuanTokenizer' object has no attribute 'sp_model',
how to add support to latest transofmers? 4.34?
solution:
https://github.com/vllm-project/vllm/issues/1403#issuecomment-1767503058