Skip to content

Latest commit

 

History

History
111 lines (65 loc) · 3.26 KB

File metadata and controls

111 lines (65 loc) · 3.26 KB

在 Hugging Face 上使用 Phi Family

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 格式供終端用戶選擇。

在 Hugging Face 上下載模型

你可以透過以下連結下載 Phi Family 模型:

你可以使用多種方式下載模型,例如安裝 Hugging Face CLI SDK 或使用 git clone

使用 Hugging Face CLI 下載 Phi Family 模型

  • 安裝 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 下載 Phi Family 模型

你也可以使用 git clone 下載模型:

git lfs install

git clone https://huggingface.co/microsoft/phi-4

範例 - 推論 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 進行翻譯。雖然我們努力確保翻譯的準確性,但請注意,自動翻譯可能包含錯誤或不準確之處。原始語言的文件應被視為權威來源。對於關鍵信息,建議使用專業人工翻譯。我們對因使用此翻譯而引起的任何誤解或錯誤解釋不承擔責任。