Chuyển đến nội dung
Skillpedia
Agent51k · #3548

pytorch-lightning

Skill này làm gì

PyTorch Lightning là công cụ giúp tổ chức mã học máy (mạng nơ-ron) để việc huấn luyện dễ hơn, nhất là trên máy có nhiều GPU hoặc TPU. Nó tự động hóa nhiều tác vụ lặp lại.

Khi nào nên dùng

  • ✓Khi xây dựng và huấn luyện mạng nơ-ron với PyTorch.
  • ✓Khi bạn cần dùng nhiều GPU hoặc TPU để tăng tốc huấn luyện.
  • ✓Khi muốn tổ chức mã học máy của bạn một cách có cấu trúc hơn.

Liên kết skill

https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/pytorch-lightning/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/pytorch-lightning/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm thế nào để thiết lập PyTorch Lightning để huấn luyện mô hình của tôi trên 4 GPU?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ chia mã của bạn thành các phần logic (như định nghĩa mô hình, vòng lặp huấn luyện và quản lý dữ liệu) và dùng một “Trainer” để xử lý toàn bộ quá trình huấn luyện, kể cả việc dùng nhiều thiết bị.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

PyTorch Lightning

Overview

PyTorch Lightning is a deep learning framework that organizes PyTorch code to eliminate boilerplate while maintaining full flexibility. Automate training workflows, multi-device orchestration, and implement best practices for neural network training and scaling across multiple GPUs/TPUs.

Reviewed release: Lightning 2.6.6, including its checkpoint-loading security fixes. CPU tests use Python 3.11, Torch 2.14.1 and Lightning 2.6.6. Use import lightning as L with the lightning distribution. The alternative pytorch-lightning distribution exposes import pytorch_lightning as pl; do not mix class namespaces within one application. GPU, TPU, multi-node and online logger examples are source-verified illustrations, not executed training validation.

Installation

uv pip install "lightning==2.6.6"

Optional extras:

uv pip install "lightning[extra]==2.6.6"    # loggers, strategies, etc.
uv pip install wandb mlflow        # specific loggers as needed

When to Use This Skill

This skill should be used when:

  • Building, training, or deploying neural networks using PyTorch Lightning
  • Organizing PyTorch code into LightningModules
  • Configuring Trainers for multi-GPU/TPU training
  • Implementing data pipelines with LightningDataModules
  • Working with callbacks, logging, and distributed training strategies (DDP, FSDP, DeepSpeed)
  • Structuring deep learning projects professionally

Core Capabilities

1. LightningModule - Model Definition

Organize PyTorch models into six logical sections:

  1. Initialization - __init__() and setup()
  2. Training Loop - training_step(batch, batch_idx)
  3. Validation Loop - validation_step(batch, batch_idx)
  4. Test Loop - test_step(batch, batch_idx)
  5. Prediction - predict_step(batch, batch_idx)
  6. Optimizer Configuration - configure_optimizers()

Quick template reference: See scripts/template_lightning_module.py for a complete boilerplate.

Detailed documentation: Read references/lightning_module.md for comprehensive method documentation, hooks, properties, and best practices.

2. Trainer - Training Automation

The Trainer automates the training loop, device management, gradient operations, and callbacks. Key features:

  • Multi-GPU/TPU support with strategy selection (DDP, FSDP, DeepSpeed)
  • Automatic mixed precision training
  • Gradient accumulation and clipping
  • Checkpointing and early stopping
  • Progress bars and logging

Quick setup reference: See scripts/quick_trainer_setup.py for common Trainer configurations.

Detailed documentation: Read references/trainer.md for all parameters, methods, and configuration options.

3. LightningDataModule - Data Pipeline Organization

Encapsulate all data processing steps in a reusable class:

  1. prepare_data() - Download/cache on local rank zero per node by default; use global rank zero with shared storage when configured
  2. setup() - Create datasets and apply transforms (per-GPU)
  3. train_dataloader() - Return training DataLoader
  4. val_dataloader() - Return validation DataLoader
  5. test_dataloader() - Return test DataLoader

Quick template reference: See scripts/template_datamodule.py for a complete boilerplate.

Detailed documentation: Read references/data_module.md for method details and usage patterns.

4. Callbacks - Extensible Training Logic

Add custom functionality at specific training hooks without modifying your LightningModule. Built-in callbacks include:

  • ModelCheckpoint - Save best/latest models
  • EarlyStopping - Stop when metrics plateau
  • LearningRateMonitor - Track LR scheduler changes
  • BatchSizeFinder - Auto-determine optimal batch size

Detailed documentation: Read references/callbacks.md for built-in callbacks and custom callback creation.

5. Logging - Experiment Tracking

Integrate with multiple logging platforms:

  • CSV locally; TensorBoard is the default only when its optional package is installed
  • Weights & Biases (WandbLogger)
  • MLflow (MLFlowLogger)
  • Comet (CometLogger)
  • CSV (CSVLogger)

NeptuneLogger was removed in Lightning 2.6.4; the Neptune service shut down March 5, 2026. The bundled helpers use local CSV logging; cloud tracking and model artifact uploads require an intentional choice.

…

Câu hỏi thường gặp

LightningModule là gì?

Đó là cách tổ chức mô hình mạng nơ-ron thành các phần rõ ràng, như khởi tạo, huấn luyện, kiểm định, kiểm tra và cấu hình bộ tối ưu.

Trainer làm gì?

Trainer tự động hóa vòng lặp huấn luyện, quản lý thiết bị (GPU/TPU) và xử lý các việc như lưu mô hình và theo dõi tiến trình.

Công cụ xử lý dữ liệu như thế nào?

Bằng LightningDataModule, giúp tổ chức việc tải, chuẩn bị và nạp dữ liệu cho huấn luyện, kiểm định và kiểm tra.

Chi tiết

Mô tả gốc của tác giả

Deep learning framework (PyTorch Lightning / lightning package). Organize PyTorch code into LightningModules, configure Trainers for multi-GPU/TPU, implement data pipelines, callbacks, logging (W&B, TensorBoard, MLflow), distributed training (DDP, FSDP, DeepSpeed), for scalable neural network training.

repo: K-Dense-AI/scientific-agent-skills

Độ phổ biến

Sao GitHub
51k
Vị trí xếp hạng
#3548
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự