pytorch
PyTorchを活用し、画像認識や自然言語処理、表形式データ向けのニューラルネットワークを構築・学習・展開し、高速化や分散学習、実運用に向けたモデル出力まで支援するSkill。
📜 元の英語説明(参考)
Assists with building, training, and deploying neural networks using PyTorch. Use when designing architectures for computer vision, NLP, or tabular data, optimizing training with mixed precision and distributed strategies, or exporting models for production inference. Trigger words: pytorch, torch, neural network, deep learning, training loop, cuda.
🇯🇵 日本人クリエイター向け解説
PyTorchを活用し、画像認識や自然言語処理、表形式データ向けのニューラルネットワークを構築・学習・展開し、高速化や分散学習、実運用に向けたモデル出力まで支援するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o pytorch.zip https://jpskill.com/download/15307.zip && unzip -o pytorch.zip && rm pytorch.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15307.zip -OutFile "$d\pytorch.zip"; Expand-Archive "$d\pytorch.zip" -DestinationPath $d -Force; ri "$d\pytorch.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
pytorch.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
pytorchフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
PyTorch
概要
PyTorchは、動的な計算グラフと自動微分を用いてニューラルネットワークを構築およびトレーニングするための深層学習フレームワークです。GPUアクセラレーションによるテンソル演算、アーキテクチャを定義するためのnn.Module、効率的なデータローディングのためのDataLoader、パフォーマンス向上のための混合精度トレーニング、および本番環境へのデプロイのためのエクスポートツール(TorchScript、ONNX)を提供します。
指示
- モデルを定義する際は、レイヤー用に
__init__、計算用にforwardを持つnn.Moduleをサブクラス化し、単純なスタックにはnn.Sequential、複雑なアーキテクチャにはカスタムのforwardロジックを使用します。 - トレーニングする際は、標準的なループ(順伝播、損失計算、
loss.backward()、optimizer.step()、optimizer.zero_grad())を実装し、安定性のためにclip_grad_norm_による勾配クリッピングを行います。 - データをロードする際は、
__len__と__getitem__を持つDatasetをサブクラス化し、GPUトレーニングのスループットのためにnum_workers=4とpin_memory=Trueを指定してDataLoaderを使用します。 - パフォーマンスを最適化する際は、PyTorch 2.0以降で
torch.compile(model)を使用して20〜50%の高速化、torch.amp.autocast()による混合精度を使用してメモリを半分にしスループットを2倍にし、マルチGPUトレーニングにはDistributedDataParallelを使用します。 - 転移学習を行う際は、
torchvision.modelsまたはHugging Faceから事前学習済みのモデルをロードし、バックボーンをフリーズし、タスクに合わせて分類器ヘッドを置き換えます。 - デプロイする際は、本番環境向けには
torch.export()またはtorch.jit.trace()、フレームワーク間の互換性のためにはtorch.onnx.export()、INT8推論の高速化のためにはtorch.quantizationを使用します。
例
例1:画像分類のためのビジョンモデルのファインチューニング
ユーザーリクエスト: 「製品画像を分類するために、事前学習済みのResNetをファインチューニングしてください」
アクション:
resnet50(weights=ResNet50_Weights.DEFAULT)をロードし、最後の分類器を除くすべてのレイヤーをフリーズします。- 分類器ヘッドを
nn.Linear(2048, num_classes)に置き換えます。 - 画像拡張変換(RandomCrop、ColorJitter、Normalize)を使用してDataLoaderを設定します。
- AdamW、CosineAnnealingLRスケジューラ、および混合精度でトレーニングします。
出力: 本番環境品質の精度と効率的な混合精度トレーニングを備えた、ファインチューニングされた画像分類器。
例2:Hugging Faceを使用したテキスト分類モデルのトレーニング
ユーザーリクエスト: 「事前学習済みのトランスフォーマーを使用して、感情分析モデルを構築してください」
アクション:
- 分類ヘッドを持つ
AutoModel.from_pretrained("bert-base-uncased")をロードします。 AutoTokenizerを使用してデータセットをトークン化し、DataLoaderを作成します。- AdamW、線形ウォームアップスケジューラ、および勾配クリッピングでファインチューニングします。
- トレーニング済みのモデルを
torch.export()でエクスポートして、本番環境でのサービングを行います。
出力: カスタムデータでファインチューニングされ、本番環境での推論のためにエクスポートされた感情分析モデル。
ガイドライン
- PyTorch 2.0以降では、
torch.compile(model)を1行で使用するだけで、20〜50%の高速化が可能です。 - 最新のアーキテクチャで正しい重み減衰を実装するには、
Adamの代わりにAdamWを使用してください。 - GPUトレーニングでは、メモリを半分にしスループットを2倍にするために、混合精度(
torch.amp)を使用してください。 - データセットをデバイスに依存しないようにするために、Datasetではなくトレーニングループ内でデータをデバイスに移動します。
- 不要な勾配計算を防ぐために、推論中は
model.eval()とtorch.no_grad()を使用してください。 - GPUでトレーニングする際は、CPUからGPUへのデータ転送を高速化するために、DataLoaderで
pin_memory=Trueを使用してください。 - コードの変更に移植可能なため、モデル全体ではなく
model.state_dict()を保存してください。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
PyTorch
Overview
PyTorch is a deep learning framework for building and training neural networks with dynamic computation graphs and automatic differentiation. It provides tensor operations with GPU acceleration, nn.Module for defining architectures, DataLoader for efficient data loading, mixed precision training for performance, and export tools (TorchScript, ONNX) for production deployment.
Instructions
- When defining models, subclass
nn.Modulewith__init__for layers andforwardfor computation, usingnn.Sequentialfor simple stacks and custom forward logic for complex architectures. - When training, implement the standard loop: forward pass, loss computation,
loss.backward(),optimizer.step(),optimizer.zero_grad(), with gradient clipping viaclip_grad_norm_for stability. - When loading data, subclass
Datasetwith__len__and__getitem__, then useDataLoaderwithnum_workers=4andpin_memory=Truefor GPU training throughput. - When optimizing performance, use
torch.compile(model)on PyTorch 2.0+ for 20-50% speedup, mixed precision withtorch.amp.autocast()for halved memory and doubled throughput, andDistributedDataParallelfor multi-GPU training. - When doing transfer learning, load pretrained models from
torchvision.modelsor Hugging Face, freeze the backbone, and replace the classifier head for your task. - When deploying, use
torch.export()ortorch.jit.trace()for production,torch.onnx.export()for cross-framework compatibility, andtorch.quantizationfor INT8 inference speedup.
Examples
Example 1: Fine-tune a vision model for image classification
User request: "Fine-tune a pretrained ResNet for classifying product images"
Actions:
- Load
resnet50(weights=ResNet50_Weights.DEFAULT)and freeze all layers except the final classifier - Replace the classifier head with
nn.Linear(2048, num_classes) - Set up DataLoader with image augmentation transforms (RandomCrop, ColorJitter, Normalize)
- Train with AdamW, CosineAnnealingLR scheduler, and mixed precision
Output: A fine-tuned image classifier with production-quality accuracy and efficient mixed-precision training.
Example 2: Train a text classification model with Hugging Face
User request: "Build a sentiment analysis model using a pretrained transformer"
Actions:
- Load
AutoModel.from_pretrained("bert-base-uncased")with a classification head - Tokenize the dataset using
AutoTokenizerand create a DataLoader - Fine-tune with AdamW, linear warmup scheduler, and gradient clipping
- Export the trained model with
torch.export()for production serving
Output: A sentiment analysis model fine-tuned on custom data and exported for production inference.
Guidelines
- Use
torch.compile(model)on PyTorch 2.0+ for a free 20-50% speedup with one line. - Use
AdamWoverAdamfor correct weight decay implementation with modern architectures. - Use mixed precision (
torch.amp) for any GPU training to halve memory and double throughput. - Move data to device in the training loop, not in the Dataset, to keep Dataset device-agnostic.
- Use
model.eval()andtorch.no_grad()during inference to prevent unnecessary gradient computation. - Use
pin_memory=Truein DataLoader when training on GPU to speed up CPU-to-GPU data transfer. - Save
model.state_dict()not the full model since state dicts are portable across code changes.