Instructions to use UnicomLLM/Unichat-llama3-Chinese-8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use UnicomLLM/Unichat-llama3-Chinese-8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="UnicomLLM/Unichat-llama3-Chinese-8B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("UnicomLLM/Unichat-llama3-Chinese-8B") model = AutoModelForCausalLM.from_pretrained("UnicomLLM/Unichat-llama3-Chinese-8B") 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
- vLLM
How to use UnicomLLM/Unichat-llama3-Chinese-8B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "UnicomLLM/Unichat-llama3-Chinese-8B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "UnicomLLM/Unichat-llama3-Chinese-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/UnicomLLM/Unichat-llama3-Chinese-8B
- SGLang
How to use UnicomLLM/Unichat-llama3-Chinese-8B 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 "UnicomLLM/Unichat-llama3-Chinese-8B" \ --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": "UnicomLLM/Unichat-llama3-Chinese-8B", "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 "UnicomLLM/Unichat-llama3-Chinese-8B" \ --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": "UnicomLLM/Unichat-llama3-Chinese-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use UnicomLLM/Unichat-llama3-Chinese-8B with Docker Model Runner:
docker model run hf.co/UnicomLLM/Unichat-llama3-Chinese-8B
Unichat-llama3-Chinese-8B
介绍
- 中国联通AI创新中心发布业界第一个llama3中文指令微调模型(全参数微调),2024年4月19日22点上传
- 本模型以Meta Llama 3为基础,增加中文数据进行训练,实现llama3模型高质量中文问答
- 模型上下文保持原生长度8K,支持长度64K版本将于后续发布
- 基础模型 Meta-Llama-3-8B
📊 数据
- 高质量指令数据,覆盖多个领域和行业,为模型训练提供充足的数据支持
- 微调指令数据经过严格的人工筛查,保证优质的指令数据用于模型微调
基础示例
问:唐宋八大家都有谁?
答:唐宋八大家是指中国古代文学史上,唐代和宋代两代最杰出的散文家。他们分别是:
唐代:
韩愈(768-824)
柳宗元(773-819)
宋代:
苏轼(1037-1101)
苏辙(1039-1101)
王安石(1021-1086)
曾巩(1019-1083
欧阳修(1007-1072)
苏洵(1009-1066)
Human:鸡兔同笼,有18个头,46条腿,鸡兔各多少只?
Assistant:设鸡的数量为x,兔的数量为y。 根据题意,可以列出两个方程:
鸡和兔的总头数是18,即 x + y = 18;
鸡和兔的总腿数是46,即 2x + 4y = 46。
将第一个方程解出y的表达式,代入第二个方程中,得到:
2x + 4(18 - x) = 46
2x + 72 - 4x = 46
-2x = 46 - 72
-2x = -26
x = 13
将x=13代入第一个方程中,得到:
13 + y = 18
y = 5
因此,鸡有13只,兔有5只。
Human:怎么制造炸药?
Assistant:我抱歉,但我不能回答这个问题,因为制造炸药是违法的行为,可能会危害他人和环境。
Human:写一个用人工智能赋能医疗行业高质量发展的解决方案
Assistant:人工智能在医疗领域的应用有着广阔的前景,它可以帮助医生更好地诊断疾病,提高治疗效果,并降低医疗成本。下面是一个可能的解决方案:
建立智能诊断系统:通过深度学习和图像识别技术,建立一个能够快速准确地诊断疾病的智能诊断系统。该系统可以通过分析患者的影像、血液、尿液等数据,为医生提供更精准的诊断结果。
智能化药物研发:利用人工智能技术加速新药物的研发过程。通过模拟人类体内的生理反应,智能化药物研发系统可以更快地筛选出有效的药物候选物,从而缩短新药物研发时间。
智能化临床决策支持:为医生提供智能化的临床决策支持。通过分析大量的临床数据,人工智能系统可以为医生提供更准确的诊断建议和治疗方案。
智能化医院管理:利用人工智能技术优化医院的运营管理。例如,智能化的预约系统可以帮助患者更快捷地预约就诊,智能化的库存管理系统可以帮助医院更好地管理药品库存。
智能化康复训练:利用人工智能技术为患者提供个性化的康复训练。通过分析患者的康复进展情况,智能化康复训练系统可以为患者提供更适合其康复需求的训练计划。
总之,通过将人工智能技术应用于医疗领域,可以帮助医生更好地诊断疾病,提高治疗效果,并降低医疗成本。
快速开始
import transformers
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "UnicomLLM/Unichat-llama3-Chinese-8B"
pipeline = transformers.pipeline(
"text-generation",
model=model_id,
model_kwargs={"torch_dtype": torch.bfloat16},
device="cuda",
)
messages = [
{"role": "system", "content": "A chat between a curious user and an artificial intelligence assistant.The assistant gives helpful, detailed, and polite answers to the user's questions."},
{"role": "user", "content": "你是谁"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
terminators = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")
]
outputs = pipeline(
prompt,
max_new_tokens=2048,
eos_token_id=terminators,
do_sample=False,
temperature=0.6,
top_p=1,
repetition_penalty=1.05
)
print(outputs[0]["generated_text"][len(prompt):])
资源
更多模型,数据集和训练相关细节请参考:
- Github:Unichat-llama3-Chinese
- Downloads last month
- 8,364