← Back to Pull requests

fix(estimator): correct multi-GPU memory estimates #163

Closed
unknown closed this pull request without merging on Nov 12, 2026 04:57 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 16:20 UTC
Author

What

The memory estimator underestimates or misreports per-GPU VRAM when num_gpus > 1:

  • sft/osft: FSDP's per-GPU unit gather isn't counted, so multi-GPU estimates are too low.

  • lora/qlora: model splitting (device_map="balanced") isn't modeled. Every term is divided by num_gpus, even though one process runs the whole micro-batch.

  • qlora: the pre-quantized 8-bit bound compares a whole-model size against a per-GPU subtotal.
  • Why and fixes

  • FSDP gather: while computing a unit, every GPU gathers the whole unit on top of its 1/N shard. The new opt-in count_fsdp_gather adds 4 × max(root_unit, decoder_block) parameters (16-bit weight + gradient), as DeepSpeed's estimate_zero3_model_states_mem_needs does. The root unit is the embeddings, plus the lm_head when it isn't tied.

  • Model splitting: in a single-process split, each GPU sees the full micro-batch but holds activations only for its own layers. The new opt-in enable_model_splitting stops dividing tokens_per_gpu and divides only the layer activations. Output logits stay whole, because the last GPU holds all of them.

  • QLoRA bound: divide the 8-bit model size by num_gpus before the comparison, so both sides are per GPU.
  • Changes

  • BasicEstimator: new count_fsdp_gather argument (default False); _calc_additional now returns the gather term when it's enabled and num_gpus > 1; stores trust_remote_code.

  • LoRAEstimator / QLoRAEstimator: new enable_model_splitting argument (default False); _resolve_tokens_per_gpu and a new _calc_intermediate_activations override handle split mode.

  • QLoRAEstimator._apply_overhead: per-GPU offload comparison.

  • OSFTEstimator, OSFTEstimatorExperimental, estimate(): pass the new flags through and document them.

  • With defaults, sft/osft/lora results are unchanged. qlora results can change when num_gpus > 1.
  • Test

  • Tested the osft and lora cases end to end.
  • <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Memory estimates can account for FSDP gather memory when enabled.
    LoRA and QLoRA estimates can account for model splitting across GPUs and report per-GPU memory.
    LoRA estimates reflect full per-process micro-batches and replicated models when splitting is disabled.
    LoRA and QLoRA estimates support configurable target modules and fused-loss selection, including related output-head memory.
    Estimates account for dense, multimodal, and mixture-of-experts configurations, QLoRA weight precision, and decoder-layer working memory.
    Model-size information can be cached in the user’s cache directory; estimates remain available if caching fails.
    Documentation
    * Clarified estimate calibration, batch-size interpretation, model splitting, and cache behavior.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 372 lines (+279 / -93) across 4 files Reviewer: xingliu-netizen Review duration: 2197m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 372 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.354
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #163"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.8% (MEDIUM) · Higher = larger blast radius
    42.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.9% · Safe to merge
    16.9%