Skillpedia
الوكلاء51k · #3548

pytorch-lightning

ما الذي تفعله

PyTorch Lightning أداة تساعد على تنظيم كود تعلم الآلة (الشبكات العصبية) لتسهيل تدريبها، خاصة على الحواسيب التي تحتوي على عدة بطاقات GPU أو TPU. وتؤتمت كثيراً من المهام المتكررة.

متى تستخدمها

  • ✓عندما تبني الشبكات العصبية وتدربها باستخدام PyTorch.
  • ✓عندما تحتاج إلى استخدام عدة بطاقات GPU أو TPU لتسريع التدريب.
  • ✓عندما تريد تنظيم كود تعلم الآلة لديك بطريقة أكثر تنظيماً.

رابط المهارة

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

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/pytorch-lightning/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“كيف أضبط PyTorch Lightning لتدريب نموذجي على 4 بطاقات GPU؟”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

تقسم المهارة الكود إلى أجزاء منطقية (مثل تعريف النموذج وحلقة التدريب وإدارة البيانات)، وتستخدم «Trainer» لإدارة عملية التدريب كاملة، بما في ذلك استخدام أجهزة متعددة.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

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.

…

الأسئلة الشائعة

ما هو LightningModule؟

هو طريقة لتنظيم نموذج الشبكة العصبية في أقسام واضحة، مثل التهيئة والتدريب والتحقق والاختبار وإعداد المُحسِّن.

ماذا يفعل Trainer؟

يؤتمت Trainer حلقة التدريب، ويدير الأجهزة (GPU وTPU)، ويتولى أموراً مثل حفظ النموذج ومتابعة التقدم.

كيف يتعامل مع البيانات؟

باستخدام LightningDataModule، الذي ينظم تنزيل البيانات وتجهيزها وتحميلها للتدريب والتحقق والاختبار.

التفاصيل

الوصف الأصلي من المؤلف

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

الشعبية

نجوم GitHub
51k
الترتيب
#3548
الترخيص
MIT
آخر تحديث
15‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة