jpskill.com
🛠️ 開発・MCP コミュニティ

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本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
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
🪟 Windows (PowerShell)
$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. 1. 下の青いボタンを押して pytorch.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → pytorch フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

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=4pin_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をファインチューニングしてください」

アクション:

  1. resnet50(weights=ResNet50_Weights.DEFAULT)をロードし、最後の分類器を除くすべてのレイヤーをフリーズします。
  2. 分類器ヘッドをnn.Linear(2048, num_classes)に置き換えます。
  3. 画像拡張変換(RandomCrop、ColorJitter、Normalize)を使用してDataLoaderを設定します。
  4. AdamW、CosineAnnealingLRスケジューラ、および混合精度でトレーニングします。

出力: 本番環境品質の精度と効率的な混合精度トレーニングを備えた、ファインチューニングされた画像分類器。

例2:Hugging Faceを使用したテキスト分類モデルのトレーニング

ユーザーリクエスト: 「事前学習済みのトランスフォーマーを使用して、感情分析モデルを構築してください」

アクション:

  1. 分類ヘッドを持つAutoModel.from_pretrained("bert-base-uncased")をロードします。
  2. AutoTokenizerを使用してデータセットをトークン化し、DataLoaderを作成します。
  3. AdamW、線形ウォームアップスケジューラ、および勾配クリッピングでファインチューニングします。
  4. トレーニング済みのモデルを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.Module with __init__ for layers and forward for computation, using nn.Sequential for 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 via clip_grad_norm_ for stability.
  • When loading data, subclass Dataset with __len__ and __getitem__, then use DataLoader with num_workers=4 and pin_memory=True for GPU training throughput.
  • When optimizing performance, use torch.compile(model) on PyTorch 2.0+ for 20-50% speedup, mixed precision with torch.amp.autocast() for halved memory and doubled throughput, and DistributedDataParallel for multi-GPU training.
  • When doing transfer learning, load pretrained models from torchvision.models or Hugging Face, freeze the backbone, and replace the classifier head for your task.
  • When deploying, use torch.export() or torch.jit.trace() for production, torch.onnx.export() for cross-framework compatibility, and torch.quantization for 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:

  1. Load resnet50(weights=ResNet50_Weights.DEFAULT) and freeze all layers except the final classifier
  2. Replace the classifier head with nn.Linear(2048, num_classes)
  3. Set up DataLoader with image augmentation transforms (RandomCrop, ColorJitter, Normalize)
  4. 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:

  1. Load AutoModel.from_pretrained("bert-base-uncased") with a classification head
  2. Tokenize the dataset using AutoTokenizer and create a DataLoader
  3. Fine-tune with AdamW, linear warmup scheduler, and gradient clipping
  4. 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 AdamW over Adam for 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() and torch.no_grad() during inference to prevent unnecessary gradient computation.
  • Use pin_memory=True in 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.