Text Generation
Transformers
Safetensors
llama
text-generation-inference
8-bit precision
bitsandbytes
Instructions to use Duxiaoman-DI/XuanYuan-13B-Chat-8bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Duxiaoman-DI/XuanYuan-13B-Chat-8bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Duxiaoman-DI/XuanYuan-13B-Chat-8bit")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Duxiaoman-DI/XuanYuan-13B-Chat-8bit") model = AutoModelForCausalLM.from_pretrained("Duxiaoman-DI/XuanYuan-13B-Chat-8bit", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Duxiaoman-DI/XuanYuan-13B-Chat-8bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Duxiaoman-DI/XuanYuan-13B-Chat-8bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Duxiaoman-DI/XuanYuan-13B-Chat-8bit", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Duxiaoman-DI/XuanYuan-13B-Chat-8bit
- SGLang
How to use Duxiaoman-DI/XuanYuan-13B-Chat-8bit 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 "Duxiaoman-DI/XuanYuan-13B-Chat-8bit" \ --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": "Duxiaoman-DI/XuanYuan-13B-Chat-8bit", "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 "Duxiaoman-DI/XuanYuan-13B-Chat-8bit" \ --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": "Duxiaoman-DI/XuanYuan-13B-Chat-8bit", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Duxiaoman-DI/XuanYuan-13B-Chat-8bit with Docker Model Runner:
docker model run hf.co/Duxiaoman-DI/XuanYuan-13B-Chat-8bit
量化部署
为了降低用户在本地使用XuanYuan的成本,降低显存需求,我们提供量化好的XuanYuan-13B-Chat模型8bit和4bit模型。
8bit模型:
在8bit量化算法上,我们使用目前社区广泛使用的bitsandbytes库。
import torch
from transformers import LlamaForCausalLM, LlamaTokenizer
model_name_or_path = "/your/model/path"
tokenizer = LlamaTokenizer.from_pretrained(model_name_or_path, use_fast=False, legacy=True)
model = LlamaForCausalLM.from_pretrained(model_name_or_path,torch_dtype=torch.float16, device_map="auto")
inputs = tokenizer("问题:李时珍是哪一个朝代的人?回答:", return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=64, repetition_penalty=1.1)
outputs = tokenizer.decode(outputs.cpu()[0][len(inputs.input_ids[0]):], skip_special_tokens=True)
print(outputs)
4bit模型:
在4bit量化算法上,我们使用auto-gptq工具。
import torch
from transformers import LlamaForCausalLM, LlamaTokenizer
from auto_gptq import AutoGPTQForCausalLM
model_name_or_path = "/your/model/path"
tokenizer = LlamaTokenizer.from_pretrained(model_name_or_path, use_fast=False, legacy=True)
model = AutoGPTQForCausalLM.from_quantized(model_name_or_path,torch_dtype=torch.float16, device_map="auto")
inputs = tokenizer("问题:李时珍是哪一个朝代的人?回答:", return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=64, repetition_penalty=1.1)
outputs = tokenizer.decode(outputs.cpu()[0][len(inputs.input_ids[0]):], skip_special_tokens=True)
print(outputs)
在vllm下使用4bit模型:
普通huggingface的推理脚本运行gptq量化的4bit模型,推理的速度很慢,并不实用。而最新版本的vllm已经支持包含gptq在内的多种量化模型的加载,vllm依靠量化的加速算子以及pagedAttention,continue batching以及一些调度机制,可以实现至少10倍的推理吞吐的提升。 您可以安装最新版本的vllm并使用以下脚本使用我们的4bit量化模型:
from vllm import LLM, SamplingParams
sampling_params = SamplingParams(temperature=0.7, top_p=0.95,max_tokens=256)
llm = LLM(model="/your/model/path", quantization="gptq", dtype="float16")
prompts = "问题:李时珍是哪一个时代的人?回答:"
result = llm.generate(prompts, sampling_params)
result_output = [[output.outputs[0].text,output.outputs[0].token_ids] for output in result]
print('generated_result', result_output[0])
- Downloads last month
- 4