hugging-face-cli について
Hugging Face Hub を操作する `hf` コマンドラインインターフェースを案内するスキルです。リポジトリやキャッシュの管理、ダウンロードとアップロード、Hub の閲覧、ジョブとエンドポイントを扱います。
主な機能
- 01認証とトークンの管理
- 02リポジトリファイルのダウンロードとアップロード
- 03Hub リポジトリの作成と管理
- 04モデル、データセット、Spaces の閲覧
- 05キャッシュ、ジョブ、エンドポイントの管理
活用シーン
- 01モデルをローカルディレクトリにダウンロード
- 02モデルやデータセットのファイルを Hub に公開
- 03キャッシュの確認や計算ジョブの管理
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ huggingface/ skills --skill hugging-face-cliインストール後、Claude Code で/hugging-face-cliを入力して読み込まれたか確認します。
同梱ファイルreferences/commands.mdreferences/examples.md
詳細
Hugging Face CLI
hf CLI では、ターミナルから Hugging Face Hub に直接アクセスして、リポジトリ、キャッシュ、コンピューティングリソースをダウンロード、アップロード、管理できます。
コマンド早見表
| タスク | コマンド |
|---|---|
| ログイン | hf auth login |
| モデルをダウンロード | hf download <repo_id> |
| フォルダーにダウンロード | hf download <repo_id> --local-dir ./path |
| フォルダーをアップロード | hf upload <repo_id> . . |
| リポジトリを作成 | hf repo create <name> |
| タグを作成 | hf repo tag create <repo_id> <tag> |
| ファイルを削除 | hf repo-files delete <repo_id> <files> |
| キャッシュを一覧表示 | hf cache ls |
| キャッシュから削除 | hf cache rm <repo_or_revision> |
| モデルを一覧表示 | hf models ls |
| モデル情報を取得 | hf models info <model_id> |
| データセットを一覧表示 | hf datasets ls |
| データセット情報を取得 | hf datasets info <dataset_id> |
| スペースを一覧表示 | hf spaces ls |
| スペース情報を取得 | hf spaces info <space_id> |
| エンドポイントを一覧表示 | hf endpoints ls |
| GPU ジョブを実行 | hf jobs run --flavor a10g-small <image> <cmd> |
| 環境情報 | hf env |
主なコマンド
認証
hf auth login # Interactive login
hf auth login --token $HF_TOKEN # Non-interactive
hf auth whoami # Check current user
hf auth list # List stored tokens
hf auth switch # Switch between tokens
hf auth logout # Log out
ダウンロード
hf download <repo_id> # Full repo to cache
hf download <repo_id> file.safetensors # Specific file
hf download <repo_id> --local-dir ./models # To local directory
hf download <repo_id> --include "*.safetensors" # Filter by pattern
hf download <repo_id> --repo-type dataset # Dataset
hf download <repo_id> --revision v1.0 # Specific version
アップロード
hf upload <repo_id> . . # Current dir to root
hf upload <repo_id> ./models /weights # Folder to path
hf upload <repo_id> model.safetensors # Single file
hf upload <repo_id> . . --repo-type dataset # Dataset
hf upload <repo_id> . . --create-pr # Create PR
hf upload <repo_id> . . --commit-message="msg" # Custom message
リポジトリの管理
hf repo create <name> # Create model repo
hf repo create <name> --repo-type dataset # Create dataset
hf repo create <name> --private # Private repo
hf repo create <name> --repo-type space --space_sdk gradio # Gradio space
hf repo delete <repo_id> # Delete repo
hf repo move <from_id> <to_id> # Move repo to new namespace
hf repo settings <repo_id> --private true # Update repo settings
hf repo list --repo-type model # List repos
hf repo branch create <repo_id> release-v1 # Create branch
hf repo branch delete <repo_id> release-v1 # Delete branch
hf repo tag create <repo_id> v1.0 # Create tag
hf repo tag list <repo_id> # List tags
hf repo tag delete <repo_id> v1.0 # Delete tag
リポジトリからファイルを削除
hf repo-files delete <repo_id> folder/ # Delete folder
hf repo-files delete <repo_id> "*.txt" # Delete with pattern
キャッシュの管理
hf cache ls # List cached repos
hf cache ls --revisions # Include individual revisions
hf cache rm model/gpt2 # Remove cached repo
hf cache rm <revision_hash> # Remove cached revision
hf cache prune # Remove detached revisions
hf cache verify gpt2 # Verify checksums from cache
Hub の閲覧
# Models
hf models ls # List top trending models
hf models ls --search "MiniMax" --author MiniMaxAI # Search models
hf models ls --filter "text-generation" --limit 20 # Filter by task
hf models info MiniMaxAI/MiniMax-M2.1 # Get model info
# Datasets
hf datasets ls # List top trending datasets
hf datasets ls --search "finepdfs" --sort downloads # Search datasets
hf datasets info HuggingFaceFW/finepdfs # Get dataset info
# Spaces
hf spaces ls # List top trending spaces
hf spaces ls --filter "3d" --limit 10 # Filter by 3D modeling spaces
hf spaces info enzostvs/deepsite # Get space info
ジョブ(クラウドコンピューティング)
hf jobs run python:3.12 python script.py # Run on CPU
hf jobs run --flavor a10g-small <image> <cmd> # Run on GPU
hf jobs run --secrets HF_TOKEN <image> <cmd> # With HF token
hf jobs ps # List jobs
hf jobs logs <job_id> # View logs
hf jobs cancel <job_id> # Cancel job
推論エンドポイント
hf endpoints ls # List endpoints
hf endpoints deploy my-endpoint \
--repo openai/gpt-oss-120b \
--framework vllm \
--accelerator gpu \
--instance-size x4 \
--instance-type nvidia-a10g \
--region us-east-1 \
--vendor aws
hf endpoints describe my-endpoint # Show endpoint details
hf endpoints pause my-endpoint # Pause endpoint
hf endpoints resume my-endpoint # Resume endpoint
hf endpoints scale-to-zero my-endpoint # Scale to zero
hf endpoints delete my-endpoint --yes # Delete endpoint
GPU フレーバー: cpu-basic、cpu-upgrade、cpu-xl、t4-small、t4-medium、l4x1、l4x4、l40sx1、l40sx4、l40sx8、a10g-small、a10g-large、a10g-largex2、a10g-largex4、a100-large、h100、h100x8
よく使われるパターン
モデルをダウンロードしてローカルで使用
# Download to local directory for deployment
hf download meta-llama/Llama-3.2-1B-Instruct --local-dir ./model
# Or use cache and get path
MODEL_PATH=$(hf download meta-llama/Llama-3.2-1B-Instruct --quiet)
モデル/データセットを公開
hf repo create my-username/my-model --private
hf upload my-username/my-model ./output . --commit-message="Initial release"
hf repo tag create my-username/my-model v1.0
スペースをローカルと同期
hf upload my-username/my-space . . --repo-type space \
--exclude="logs/*" --delete="*" --commit-message="Sync"
キャッシュの使用状況を確認
hf cache ls # See all cached repos and sizes
hf cache rm model/gpt2 # Remove a repo from cache
主なオプション
--repo-type:model(デフォルト)、dataset、space--revision:ブランチ、タグ、またはコミットハッシュ--token:認証情報を上書き--quiet:必要最小限の情報(パス/URL)のみを出力
参考資料
- コマンドの完全なリファレンス:references/commands.mdを参照
- ワークフローの例:references/examples.mdを参照
コメント
Markdown 対応