yzlnew/infra-skills/megatron-memory-estimator
Claude Code and agent skill by yzlnew/infra-skills
- community
Checking that the SKILL.md file is still in the repository.
Estimate GPU memory usage for Megatron-based MoE (Mixture of Experts) and dense models. Use when users need to (1) estimate memory from HuggingFace model configs (DeepSeek-V3, Qwen, etc.), (2) plan GPU resource allocation for training, (3) compare different parallelism strategies (TP/PP/EP/CP), (4) determine if a model fits in available GPU memory, or (5) optimize training configurations for memory efficiency.
Install
npx vskill@latest install yzlnew/infra-skills/megatron-memory-estimatorSKILL.md
Megatron Memory Estimator
Estimate GPU memory usage for Megatron-based models directly from HuggingFace configs or custom specifications.
Quick Start
Option 1: From HuggingFace Model (Recommended)
Estimate directly from HuggingFace model paths:
Option 2: From Local HF Config
Option 3: Quick Parameter Testing
Available Scripts
estimate_from_hf.py (Primary Script)
Automatically converts HuggingFace configs to Megatron format and estimates memory.
Key Arguments:
model_path: HF model path or local config.json path--tp N: Tensor parallel size (default: 1)--pp N: Pipeline parallel size (default: 1)--ep N: Expert parallel size (default: 1, for MoE)--cp N: Context parallel size (default: 1)--etp N: Expert tensor parallel size (optional)--vpp N: Virtual pipeline parallel size (optional)--micro-batch-size N: Micro batch size (default: 1)--seq-length N: Sequence length (default: 4096)--num-gpus N: Total GPU count (default: 8)--recompute-granularity {full,selective}: Enable activation checkpointing--num-layers-in-first-pipeline-stage N: Number of layers in the first pipeline stage (use when model layers cannot be evenly divided by--pp)--num-layers-in-last-pipeline-stage N: Number of layers in the last pipeline stage (use when model layers cannot be evenly divided by--pp)--verbose: Show detailed model breakdown--json: Output as JSON
Examples:
Common Workflows
Find Optimal Parallelism for a Model
Optimize for Memory Efficiency
Progressive memory reduction:
Check if Model Fits Available GPUs
Understanding Output
The estimator shows:
Memory Components:
- Weights + Gradients: Parameters and gradients (2+2=4 bytes/param in FP16)
- Optimizer States: Adam momentum + variance (8 bytes/param)
- Activations: Forward pass activations stored for backward
GPU Fit Guidelines:
- < 40 GB: A100 40GB, A100 80GB, H100
- < 80 GB: A100 80GB, H100 80GB
- \> 80 GB: H200 141GB or consider more parallelism or smaller batch
Memory Optimization Techniques
Ranked by effectiveness:
- Enable Distributed Optimizer (included by default)
- Shards optimizer states across data parallel ranks
- ~6 bytes/param saving
- Activation Recomputation (
--recompute-granularity full)
- 50-70% activation memory reduction
- Trade compute for memory
- Increase Expert Parallelism (MoE only) (
--ep N)
- Linear memory reduction for expert layers
- Minimal performance impact
- Increase Pipeline Parallelism (
--pp N)
- Splits model across more stages
- Some pipeline bubble overhead
- Reduce Batch Size (
--micro-batch-size 1)
- Direct activation memory reduction
- Impacts throughput
Supported Models
The script automatically handles:
- DeepSeek: DeepSeek-V2, DeepSeek-V3
- Qwen: Qwen2.5, Qwen3 (dense and MoE)
- Moonlight: Kimi models
- Any HuggingFace model with config.json
Setup & Troubleshooting
Because this tool relies on Megatron-LM components, you need to add both the tool directory and Megatron-LM to your PYTHONPATH.
Recommended Setup:
If you encounter ImportError: No module named 'megatron_memory_estimator', ensure the root directory of this skill is in your PYTHONPATH.
Dependencies
Required:
mbridge: HuggingFace to Megatron config bridgetransformers: HuggingFace transformers librarytorch: PyTorch (CPU version sufficient)megatron-core: Megatron core library
Installation:
For full Megatron-LM support (optional):
Reference Documentation
For detailed configuration options:
references/configuration_guide.md: All configuration parametersreferences/parallelism_strategies.md: Parallelism strategy guide
Notes
- Estimates are theoretical based on model architecture
- Actual memory may vary ±10-15% due to framework overhead
- Always leave 10-20% memory headroom for safety
- Test on small scale before full deployment
- MoE models: Expert parallelism (EP) is critical for memory efficiency
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingmegatron-memory-estimator/SKILL.md
Popularity
- Repository stars
- 122
- Repository forks
- 6
- 7-day trend score
- 24
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 2 May 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/yzlnew/infra-skills/megatron-memory-estimator)