Skip to content

feat(cli): detect an incomplete or interrupted model download and re-fetch instead of failing at load #465

Closed

Description

@pjb7687

Summary

If a model download is interrupted (for example with ctrl+c), the next mlxcel run <repo-id> loads the partial local snapshot and fails with Error: Weight not found: <tensor> instead of noticing the snapshot is incomplete and re-fetching it. The user has to know to delete the directory by hand.

Background

The downloader already stages each file to a tempfile and atomically renames it, and it has a full completeness gate snapshot_complete() that requires config.json plus every wanted file present and non-zero. But the load/resolve path uses a weaker "snapshot exists" check (essentially: is config.json present). An interrupted download that got config.json and only some of the safetensors shards therefore passes the resolver, the re-download is skipped, and loading dies at the first missing weight.

Proposed Solution

Before loading a pre-existing local snapshot, verify it against the same completeness gate the downloader uses (all files in the safetensors index / the repo wanted-set present and non-zero), not just config.json presence. On incompleteness, resume the download (re-fetch only the missing / zero-byte files, which download_repo already supports by skipping complete files) or, failing that, clean the partial snapshot and re-download, then load. Surface a clear message ("incomplete download detected, re-fetching N missing files") rather than a bare Weight not found.

Implementation Notes

  • Reuse the strong gate on the load path: snapshot_complete() at src/downloader/mod.rs:911 (config.json + non-zero files; tests at src/downloader/tests.rs:443-459).
  • Strengthen the weaker load-side gate: src/downloader/resolver.rs:55,75 (currently mirrors only config.json presence).
  • Download reuse / resume: src/downloader/mod.rs:693 (else if snapshot_complete(...)), staging+rename at :448,524,576, stale-partial cleanup cleanup_stale_partials at :362-374. Routing an incomplete local dir back through download_repo should resume cheaply because complete files are skipped.
  • Current failure surface: Weight not found at src/lib/mlxcel-core/src/layers.rs:125 (and peer call sites), which is where the incomplete snapshot currently blows up.

Acceptance Criteria

  • Interrupting a download and then re-running mlxcel run <repo-id> completes the download (resume) or cleans and re-downloads, then loads successfully, instead of Weight not found.
  • The load/resolve path uses the full completeness gate (index / wanted-set + non-zero), not just config.json presence.
  • A clear message names the incomplete-snapshot condition and the re-fetch action.
  • The same protection covers mlxcel serve / mlxcel-server auto-download (relates to fix(serve): mlxcel serve aborts with a nested-runtime panic when auto-downloading a missing model #463).
  • Regression coverage for the incomplete-snapshot to resume/redownload path.

Original Suggestion

Title: feat: autodetact and cleanup premature downloaded model

Problem / motivation

When a model downloading is interrupted, for example, with ctrl+c, mlxcel just throws an error it cannot find a required file:

% mlxcel run mlx-community/gemma-4-31B-it-qat-OptiQ-4bit
Runtime device: Apple GPU (Metal)
Loading model from "/Users/parkj/.cache/mlxcel/models/mlx-community/gemma-4-31B-it-qat-OptiQ-4bit"...
Error: Weight not found: language_model.model.layers.10.self_attn.k_proj.weight

Instead, it would be better to clean up such a model and download it again.

Proposed solution

As described, it would be better to clean up such a model and download it again.

Alternatives considered

No response

Scope

CLI behavior (mlxcel)

Acceptance criteria

No response

Additional context

No response

Pre-submission checks

  • I searched existing issues and discussions and did not find a duplicate

Activity

  1. added
    status:ready
    type:enhancement
    on Jun 28, 2026
  2. added
    type:bug
    and removed
    type:enhancement
    on Jul 2, 2026
  3. changed the title [-]feat: autodetact and cleanup premature downloaded model[/-] [+]fix: resume or repair incomplete model-store downloads[/+] on Jul 2, 2026
  4. added
    priority:medium
    area:cli
    area:models
    on Jul 2, 2026
  5. changed the title [-]fix: resume or repair incomplete model-store downloads[/-] [+]feat(cli): detect an incomplete or interrupted model download and re-fetch instead of failing at load[/+] on Jul 2, 2026
  6. added
    type:enhancement
    status:in-progress
    status:review
    status:done
    and removed
    type:bug
    status:ready
    status:in-progress
    status:review
    on Jul 2, 2026
  7. self-assigned this
    on Jul 4, 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:modelspriority:mediumstatus:donetype:enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions