Hugging Face 是一個非常受歡迎的 AI 社區,擁有豐富的數據和開源模型資源。不同的廠商會通過 Hugging Face 發佈開源的 LLM 和 SLM,例如 Microsoft、Meta、Mistral、Apple、Google 等。
Microsoft 的 Phi Family 已經在 Hugging Face 上發佈。開發者可以根據場景和業務需求下載相應的 Phi Family 模型。除了在 Hugging Face 部署 Phi Pytorch 模型外,我們還提供了量化模型,使用 GGUF 和 ONNX 格式,為最終用戶提供更多選擇。
你可以通過以下鏈接下載 Phi Family 模型:
-
Phi-1 / 1.5 https://huggingface.co/collections/microsoft/phi-1-6626e29134744e94e222d572
-
Phi-3 / 3.5 https://huggingface.co/collections/microsoft/phi-3-6626e15e9585a200d2d761e3
-
Phi-4 https://huggingface.co/collections/microsoft/phi-4-677e9380e514feb5577a40e4
你可以通過不同的方法下載模型,例如安裝 Hugging Face CLI SDK 或使用 git clone。
- 安裝 Hugging Face CLI
pip install -U "huggingface_hub[cli]"
- 使用 huggingface-cli 登錄
通過 Settings 頁面 的 User Access Token 登錄 Hugging Face。
huggingface-cli login --token $HF_TOKEN --add-to-git-credential
- 下載
你可以下載模型並將其保存到緩存中:
huggingface-cli download microsoft/phi-4
你也可以將模型保存到指定位置:
huggingface-cli download microsoft/phi-4 --local-dir $YOUR_PATH
你也可以使用 git clone 來下載模型:
git lfs install
git clone https://huggingface.co/microsoft/phi-4
- 安裝 transformers 庫
pip install transformers -U
- 在 VSCode 中運行以下代碼
import transformers
pipeline = transformers.pipeline(
"text-generation",
model="microsoft/phi-4",
model_kwargs={"torch_dtype": "auto"},
device_map="auto",
)
messages = [
{"role": "user", "content": "I have $20,000 in my savings account, where I receive a 4% profit per year and payments twice a year. Can you please tell me how long it will take for me to become a millionaire? Also, can you please explain the math step by step as if you were explaining it to an uneducated person?"},
]
outputs = pipeline(messages, max_new_tokens=2048)
print(outputs[0]["generated_text"][-1])
免責聲明:
此文件使用AI翻譯服務 Co-op Translator 翻譯而成。我們致力於提供準確的翻譯,但請注意,自動翻譯可能包含錯誤或不準確之處。應以原文作為權威來源。對於重要資訊,建議尋求專業人工翻譯。我們對因使用此翻譯而引起的任何誤解或誤釋不承擔責任。