Skip to content

feat: unified memory estimator with mlxcel inspect and generate/serve preflight #56

Closed

Description

@inureyes

Part of #52

Goal

Combine weights (sub-issue A) + KV cache (sub-issue B) + runtime headroom (calibrated via sub-issue C) into one estimator, surface it through a dedicated mlxcel inspect subcommand and an --estimate-memory preflight on generate/serve, and abort (with override) when a model won't fit.

Depends on

#53 (weights), #54 (KV cache), #55 (MLX FFI). This is the integration capstone for the epic.

Scope / implementation

  • estimate_total_memory(model_dir, ctx_len, batch, quant, kv_dtype) -> MemoryEstimate { weights, kv_cache, runtime_headroom, total, available, fits } in a shared module (e.g. src/execution/memory_estimate.rs), reachable from the single-device load path (not only distributed).
  • Runtime/activation headroom: derive an empirical factor calibrated from get_peak_memory() (sub-issue C) across a couple of real loads instead of a guess; document the assumption.
  • mlxcel inspect <model> subcommand (new variant in enum Commands, src/main.rs): read-only — prints the full breakdown vs available unified memory and fits/doesn't-fit. No generation.
  • --estimate-memory flag on generate / serve (next to --recommend-quant): runs the same estimate as a preflight; aborts with a clear, actionable error when total > available; --force / --no-memory-check overrides.
  • After a successful load, compare the estimate against get_active_memory() and log the delta (feeds future calibration).

Integration (required for completion — epic capstone)

  • mlxcel inspect, the --estimate-memory preflight, and --recommend-quant all consume the one estimator (no duplicate logic).
  • Preflight abort + override verified on a real over-capacity scenario (e.g. an artificially low limit via sub-issue C's set_memory_limit, or a model larger than that limit).
  • Docs: inspect / --estimate-memory / override flags documented (CLI help + README/docs).

Acceptance criteria

  • mlxcel inspect <model> --max-tokens N prints weights / KV / headroom / total / available / fits without running generation; numbers match sub-issues A and B.
  • mlxcel generate --estimate-memory aborts an over-capacity case with a clear error and respects --force.
  • Post-load estimate-vs-active_memory() delta is logged and within a documented tolerance for a tested model.

Activity

  1. added
    type:enhancement
    area:cli
    area:core
    priority:medium
    status:ready
    on May 21, 2026
  2. added
    status:in-progress
    status:review
    status:done
    and removed
    status:ready
    status:in-progress
    status:review
    on May 21, 2026
  3. self-assigned this
    on May 29, 2026
  4. added this to the 0.1 milestone on Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:cliarea:corepriority:mediumstatus:donetype:enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions