본문으로 건너뛰기
cccskills
무료GitHub에 공개

nemo-mbridge-perf-cpu-offloading

Validate and use CPU offloading in Megatron Bridge, including layer-level activation offloading and fractional optimizer state offloading with HybridDeviceOptimizer.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(6)

  • SKILL.md9.1 KB
  • BENCHMARK.md4.2 KB
  • card.yaml8.0 KB
  • evals/evals.json1.4 KB
  • skill-card.md3.8 KB
  • skill.oms.sig4.7 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

CPU Offloading

References

  • Stable docs: @docs/training/cpu-offloading.md
  • Structured metadata: @skills/nemo-mbridge-perf-cpu-offloading/card.yaml

What It Is

Two independent mechanisms to move data from GPU to CPU memory:

MechanismConfig namespaceWhat gets offloadedPP restriction
Activation offloadingmodel.cpu_offloading*Activations (and optionally weights) per transformer layerPP must be 1
Optimizer offloadingoptimizer.optimizer_cpu_offloadAdam optimizer states (momentum + variance) via HybridDeviceOptimizerNone

Quick Decision

SituationRecommendation
Large MoE model (30B+), needs PP > 1Optimizer offloading — activation offloading is blocked by PP=1
Small/medium model, PP=1 fits, activation memory dominatesActivation offloading
Want tunable memory-speed tradeoffOptimizer offloading with fractional optimizer_offload_fraction
Throughput is top priorityDon't enable — offloading always adds overhead
CUDA graphs are neededOnly optimizer offloading — activation offloading is incompatible
Memory pressure is moderateOptimizer offload at 25–50% fraction for best efficiency

Enablement

Optimizer CPU offloading (recommended for large models)

cfg.optimizer.optimizer_cpu_offload = True
cfg.optimizer.optimizer_offload_fraction = 1.0
cfg.optimizer.overlap_cpu_optimizer_d2h_h2d = True

CLI overrides:

optimizer.optimizer_cpu_offload=True \
optimizer.optimizer_offload_fraction=0.5 \
optimizer.overlap_cpu_optimizer_d2h_h2d=True

Activation CPU offloading (small/medium models only)

cfg.model.cpu_offloading = True
cfg.model.cpu_offloading_num_layers = 16
cfg.model.cpu_offloading_activations = True
cfg.model.cpu_offloading_weights = False

cfg.model.pipeline_model_parallel_size = 1
cfg.model.recompute_granularity = None
cfg.model.cuda_graph_impl = "none"

Config Parameter Reference

Optimizer offloading

ParameterDefaultDescription
optimizer_cpu_offloadFalseMaster switch
optimizer_offload_fraction0.0Fraction of optimizer states on CPU (0.0–1.0)
overlap_cpu_optimizer_d2h_h2dFalseOverlap GPU↔CPU transfers with compute
use_torch_optimizer_for_cpu_offloadFalseUse torch.optim instead of fused optimizer for CPU portion

Activation offloading

ParameterDefaultDescription
cpu_offloadingFalseMaster switch
cpu_offloading_num_layers0Number of transformer layers to offload (0 to num_layers-1)
cpu_offloading_activationsTrueOffload activations
cpu_offloading_weightsFalseOffload weights
cpu_offloading_double_bufferingFalseDouble-buffer across layers while reloading

Compatibility And Constraints

Activation offloading

  • pipeline_model_parallel_size must be 1
  • recompute_granularity must be None
  • Cannot combine with fine_grained_activation_offloading
  • Cannot combine with CUDA graphs
  • cpu_offloading_num_layers must be in [0, num_layers-1)

Optimizer offloading

  • Requires use_distributed_optimizer = True (default in most recipes)
  • No PP, recompute, or CUDA graph restrictions
  • optimizer_offload_fraction must be in [0.0, 1.0]

Practical: large MoE models

Activation offloading is blocked for Qwen3-30B-A3B and similar large MoE models. The PP=1 constraint means each GPU holds all 48 layers; model weights + optimizer states alone (~70 GB) exceed H100 80 GB capacity.

Minimal Runnable Command

uv run python scripts/training/run_recipe.py \
  --recipe qwen3_30b_a3b_pretrain_config \
  optimizer.optimizer_cpu_offload=True \
  optimizer.optimizer_offload_fraction=0.5 \
  train.train_iters=20 \
  train.global_batch_size=8 \
  train.micro_batch_size=1

Verification

Unit tests

uv run python -m pytest \
  tests/unit_tests/models/test_gpt_full_te_layer_autocast_spec.py -k "cpu_offload" \
  tests/unit_tests/peft/test_utils.py -k "cpu_offload" -q

Success criteria

  • Config validation passes for the selected offloading mode
  • Training completes without OOM or NCCL errors
  • Loss matches the non-offloaded baseline (max delta < 0.001)
  • Memory usage drops proportionally to offload fraction

Code Anchors

MCore activation offload constraints

        if self.cpu_offloading and (
            self.cpu_offloading_num_layers < 0 or self.cpu_offloading_num_layers >= self.num_layers
        ):
            raise ValueError(...)

        if self.cpu_offloading and self.pipeline_model_parallel_size > 1:
            raise ValueError(
                "Currently there is no support for Pipeline parallelism with CPU offloading"
            )

        if self.cpu_offloading and self.recompute_granularity is not None:
            raise ValueError(
                "CPU offloading does not work when activation recomputation is enabled"
            )

MCore CUDA graph incompatibility

            if self.cpu_offloading:
                raise ValueError("CUDA graphs not supported with CPU offloading.")

MCore fine-grained offloading mutual exclusion

        if self.fine_grained_activation_offloading:
            assert (
                not self.cpu_offloading
            ), "fine_grained_activation_offloading cannot be enabled with cpu_offloading."

MCore HybridDeviceOptimizer instantiation

        if config.optimizer_cpu_offload:
            # ... setup cpu/gpu optimizer classes ...
            optimizer = HybridDeviceOptimizer(
                param_groups,
                offload_fraction=config.optimizer_offload_fraction,
                cpu_optimizer_cls=cpu_optimizer_cls,
                gpu_optimizer_cls=gpu_optimizer_cls,
                overlap_cpu_optimizer_d2h_h2d=config.overlap_cpu_optimizer_d2h_h2d,
                pin_cpu_grads=config.pin_cpu_grads,
                pin_cpu_params=config.pin_cpu_params,
            )

Bridge CUDA graph guard

        assert not config.cpu_offloading and config.recompute_granularity is None, "Cudagraphs not supported"

Bridge activation offloading in PEFT

        if self.config.cpu_offloading and self.config.cpu_offloading_activations:
            x.activation_offloading = True
        x, _ = self.linear_in(x)
        x = self.activation(x)
        if self.config.cpu_offloading and self.config.cpu_offloading_activations:
            x.activation_offloading = True
        x, _ = self.linear_out(x)

Failure Diagnosis

SymptomLikely CauseHow To ConfirmFix
Currently there is no support for Pipeline parallelism with CPU offloadingActivation offload + PP > 1Check pipeline_model_parallel_sizeSet PP=1 or use optimizer offloading
CPU offloading does not work when activation recomputation is enabledActivation offload + recomputeCheck recompute_granularitySet recompute_granularity=null
fine_grained_activation_offloading cannot be enabled with cpu_offloadingBoth offloading modes enabledCheck both flagsUse one or the other
CUDA graphs not supported with CPU offloadingCUDA graphs + activation offloadCheck cuda_graph_implSet cuda_graph_impl="none"
OOM with activation offloadingModel too large for PP=1Check allocated memory vs 80 GBUse optimizer offloading with PP > 1
Extreme slowdown (>4x)100% optimizer offload, CPU Adam bottleneckCompare iter time at different fractionsReduce fraction or enable overlap_cpu_optimizer_d2h_h2d
OOM at partial optimizer offloadInsufficient offload for this configCheck memory at different fractionsIncrease fraction or add PP

Known Limitations

  • Activation offloading requires PP=1, making it impractical for large models (30B+ MoE) that need pipeline parallelism.
  • Optimizer offloading throughput penalty scales linearly (~1.9x at 25%, ~4.2x at 100% for Qwen3-30B-A3B).
  • D2H/H2D overlap provides only ~7% speedup because CPU Adam compute is the dominant bottleneck.
  • fine_grained_activation_offloading is a separate module-level approach that works with PP > 1 but cannot be combined with layer-level cpu_offloading.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Official NVIDIA-authored guidance for NVIDIA cuDF GPU DataFrames, pandas acceleration, dask-cuDF, ETL, joins, groupby, CSV/Parquet I/O, nullable semantics, and multi-GPU DataFrame workloads.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

NVIDIA/skills3.7천2026년 10월 18일 업데이트

Customize NVIDIA Nemotron Voice Agent's Generic Pipecat example for healthcare appointment, five-field patient intake, or custom tool-calling workflows without a separate backend.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

NVIDIA/skills3.7천2026년 10월 18일 업데이트

Calibrate a new dataset from live RTSP camera streams via the AutoMagicCalib REST API. Use when the user provides RTSP URLs or asks to calibrate live cameras; VIOS records clips, AMC ingests them, then runs calibration.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

NVIDIA/skills3.7천2026년 10월 18일 업데이트

Run end-to-end calibration on the shipped sample dataset (sdg_08_2_sample_data_010926.zip) against a running AMC microservice. Use when user says 'test sample dataset', 'run sample calibration', 'verify AMC install', or 'launch and test'.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

NVIDIA/skills3.7천2026년 10월 18일 업데이트

Calibrates pre-recorded `cam_*.mp4` datasets through the AutoMagicCalib REST API. Use for user-supplied local MP4s; route live RTSP streams to `amc-run-rtsp-calibration`.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

NVIDIA/skills3.7천2026년 10월 18일 업데이트

Launch AutoMagicCalib microservice and web UI from NGC release images via Docker Compose. Use when user says 'deploy auto calibration', 'launch auto calibration', 'launch AMC', 'start MS+UI', or 'set up auto-magic-calib'. Requires NGC API key.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

NVIDIA/skills3.7천2026년 10월 18일 업데이트

NVIDIA의 스킬 모두 보기

이 스킬의 문제 신고