model-train-oom-analysis

Diagnose NPU out-of-memory failures in PyTorch training via log classification, static estimation, and snapshot analysis.

Updated Sep 15, 2026
One-click install
npx skills add https://github.com/WangWindow/CANN-BatchMatMulMaxsum --skill model-train-oom-analysis-wangwindow
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: model-train-oom-analysis
Source: https://github.com/WangWindow/CANN-BatchMatMulMaxsum/tree/main/.agents/skills/model-train-oom-analysis
Command: npx skills add https://github.com/WangWindow/CANN-BatchMatMulMaxsum --skill model-train-oom-analysis-wangwindow

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Training large models on Ascend NPU often crashes with out-of-memory errors, and engineers struggle to determine whether the root cause is an oversized configuration, temporary workspace/HCCL buffer pressure, memory fragmentation, or a gradual memory leak. This Skill provides a systematic workflow to classify the OOM type from logs, statically estimate memory demand, analyze memory snapshots, and produce targeted optimization recommendations. ## Core Features & Use Cases - OOM Classification Workflow: Categorizes failures by source (NPUWorkspaceAllocator, HCCL communication, NPUCachingAllocator) and timing (step 0-2 configuration issue vs. late-step progressive leak) to route the diagnosis correctly. - Static Memory Estimation: Estimates parameter, gradient, optimizer state, activation, and temporary buffer memory against device capacity before collecting any runtime data. - Snapshot Deep Analysis: Ships an analyze_snapshot.py script that parses PyTorch memory snapshot pickle files into six dimensions: allocation overview, semantic category breakdown, peak analysis, timeline/leak detection, fragmentation depth, and top-N large allocations, plus multi-snapshot comparison. - Optimization Decision Matrix: Maps each diagnosis to concrete fixes such as memory waterline ratios, activation checkpointing, swap optimizer, parallelism adjustments, and leak-fix code review checklists. - Use Case: A training run crashes at step 15 with 'NPU out of memory'. The Skill identifies it as a suspected leak, compares snapshots across steps to confirm monotonic growth in communication buffers, and points to missing wait_tensor calls after async redistribute in the parallelization code. ## Quick Start Ask the assistant to diagnose your NPU training OOM by providing the full error log, training configuration, and NPU device memory size.

Frequently Asked Questions about model-train-oom-analysis

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I diagnose NPU out of memory errors in PyTorch training?

Start by classifying the OOM from training logs: workspace allocator and HCCL errors indicate temporary memory pressure, while CachingAllocator errors need static estimation first. Then estimate whether the configuration exceeds device memory, and collect a memory snapshot for deeper analysis if the cause remains unclear.

How to analyze a PyTorch memory snapshot pickle file?

Run the included analyze_snapshot.py script on the .pickle file to get allocation overview, semantic category breakdown, peak analysis, timeline phases, fragmentation metrics, and top-N large allocations. It also supports comparing two or more snapshots to detect leaks or measure optimization effects.

Why does training OOM at a later step instead of step one?

OOM occurring after many steps usually indicates a memory leak rather than an oversized configuration. Compare snapshots from multiple steps to find monotonically growing categories, then review code for unwaited async communication tensors, retained tensor references, or unreleased autograd saves.

What should I do when workspace allocator or HCCL memory runs out?

Limit the PTA caching allocator's share of device memory using a memory waterline such as torch_npu_memory_ratio set to 0.85-0.95, implemented via torch.npu.set_per_process_memory_fraction. This reserves space for temporary workspace and communication buffers.

Can this Skill fix training loss divergence or NaN issues?

No, it only covers OOM and memory-related diagnosis. Accuracy problems such as loss deviation or NaN/Inf are out of scope and should be handled by a dedicated accuracy debugging skill instead.

Does the OOM analysis workflow work with frameworks other than torchtitan-npu?

Yes, the methodology is framework-agnostic: memory estimation formulas, snapshot analysis dimensions, and the optimization matrix apply generally. Only the example config paths and CLI overrides are torchtitan-npu specific and should be mapped to your framework's equivalents.