Instructions to use niwz/Mini-Chinese-Phi3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use niwz/Mini-Chinese-Phi3 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="niwz/Mini-Chinese-Phi3") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, MiniPhi3 tokenizer = AutoTokenizer.from_pretrained("niwz/Mini-Chinese-Phi3") model = MiniPhi3.from_pretrained("niwz/Mini-Chinese-Phi3", 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 niwz/Mini-Chinese-Phi3 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "niwz/Mini-Chinese-Phi3" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "niwz/Mini-Chinese-Phi3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/niwz/Mini-Chinese-Phi3
- SGLang
How to use niwz/Mini-Chinese-Phi3 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 "niwz/Mini-Chinese-Phi3" \ --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": "niwz/Mini-Chinese-Phi3", "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 "niwz/Mini-Chinese-Phi3" \ --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": "niwz/Mini-Chinese-Phi3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use niwz/Mini-Chinese-Phi3 with Docker Model Runner:
docker model run hf.co/niwz/Mini-Chinese-Phi3
|
Download README.md from niwz/Mini-Chinese-Phi3: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/niwz/Mini-Chinese-Phi3/resolve/main/README.md
- Command line
-
hf download hf://niwz/Mini-Chinese-Phi3/README.md
-
curl -L -o README.md https://huggingface.co/niwz/Mini-Chinese-Phi3/resolve/main/README.md
1.13 kB
metadata
license: mit
datasets:
- Skywork/SkyPile-150B
- llm-wizard/alpaca-gpt4-data-zh
- BelleGroup/train_2M_CN
- BelleGroup/train_1M_CN
language:
- zh
pipeline_tag: text-generation
Mini-Chinese-Phi3是一个基于phi3模型结构的小型对话模型,总参数量约0.13B,使用常见的中文语料进行预训练和微调。主要内容包括了
- 数据集的整理与简单清洗
- 中文词表预训练
- 基于phi3结构的模型预训练
- 基于预训练模型的指令微调(SFT),包括了全量微调和LoRA微调
- 基于指令微调模型的直接偏好优化(DPO)
- 模型评测 (待做)
项目中的所有训练过程均在两张3090显卡上进行,使用DeepSpeed框架和Flash Attention 2进行加速,预训练用时约40小时,SFT和DPO微调共用时约8小时。本项目是我在学习LLM过程中的一个简单实践,同时也希望能够帮助到同样初学大模型的小伙伴。
项目训练细节等已在Github上开源,欢迎大家提出宝贵意见和建议。项目地址