Skip to content

Latest commit

 

History

History
110 lines (64 loc) · 3.74 KB

File metadata and controls

110 lines (64 loc) · 3.74 KB

Hugging Face で Phi ファミリーを使用する

Hugging Face は、豊富なデータとオープンソースモデルリソースを提供する非常に人気のあるAIコミュニティです。Microsoft、Meta、Mistral、Apple、Google など、さまざまな企業が Hugging Face を通じてオープンソースの LLM や SLM を公開しています。

Microsoft Phi ファミリーは Hugging Face 上で公開されています。開発者はシナリオやビジネスに応じて対応する Phi ファミリーのモデルをダウンロードできます。Hugging Face 上で Phi の Pytorch モデルをデプロイするだけでなく、GGUF や ONNX フォーマットを使用した量子化モデルも公開しており、エンドユーザーに選択肢を提供しています。

Hugging Face でモデルをダウンロードする

以下のリンクから Phi ファミリーのモデルをダウンロードできます:

モデルは、Hugging Face CLI SDK をインストールするか、git clone を使用してダウンロードできます。

Hugging Face CLI を使用して Phi ファミリーのモデルをダウンロードする

  • Hugging Face CLI のインストール
pip install -U "huggingface_hub[cli]"
  • huggingface-cli を使用してログイン

ユーザーアクセストークン設定ページ から取得し、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 ファミリーのモデルをダウンロードする

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])

It seems like you are asking to translate the text into "mo." Could you clarify what "mo" refers to? Are you referring to a specific language or dialect? For example, are you referring to Māori, Montenegrin, or something else? Let me know, and I will assist you accordingly!