Commit 5fdf590 for stable-diffusion.cpp

commit 5fdf590e4aa44598bdaeec3fbfa956aaed98b609
Author: leejet <leejet714@gmail.com>
Date:   Fri Dec 4 01:08:08 2026 +0800

    perf: prefetch file-backed weights during segmented execution (#2505)

diff --git a/docs/development/weights.md b/docs/development/weights.md
index 24851c6..678c826 100644
--- a/docs/development/weights.md
+++ b/docs/development/weights.md
@@ -184,6 +184,26 @@ with its scale; otherwise it stages synchronously. An upload of an original
 records the original's merged version when it is queued, and activation drops
 the upload when a merge in place changed the original since.

+The segment pipeline can also read a bounded batch from the next segment's
+model files while the current segment runs. The batch uses available RAM
+within the weight budget, up to 256 MiB including reader scratch. The
+execution thread authorizes the file paths and allocates the buffers. The
+reader owns a snapshot of the source metadata and writes into temporary host
+tensors. With a pinned host buffer and enough device capacity, the reader
+queues an upload as soon as the batch is ready. Otherwise the next segment
+stages from the host tensors. Weights whose storage location is still
+undecided can also read ahead. Their first load uses the prefetched bytes
+after choosing a storage location through the normal residency policy. ZIP
+entries use the synchronous reader because a shared entry can decompress to
+more bytes than the requested tensor.
+
+The execution thread waits for the batch before activation and joins it
+before discarding buffers or invalidating its sources. A completed host batch
+can be discarded when normal weight preparation needs its RAM. Parameters
+bound to a file mapping read from that mapping. The prefetched tensors
+are ordinary compute copies with the original weight epoch. LoRA preparation
+applies the current adapter version as needed.
+
 Request options cover the other callers:

 | Option | Used by |
diff --git a/docs/guides/performance.md b/docs/guides/performance.md
index cad93fe..1f504a2 100644
--- a/docs/guides/performance.md
+++ b/docs/guides/performance.md
@@ -157,6 +157,12 @@ two reusable host staging slots of up to 64 MiB each per device when available.

 When a graph has cut markers and its missing weights plus incremental compute workspace exceed the available device headroom, it runs its fixed segment list in order. An existing monolithic workspace can be reused without a new allocation. An explicit `--max-vram` budget includes resident managed weights, compute and cache buffers registered by runners sharing the device, and ggml's idle buffer pool. The current segment's weights are pinned during compute, and the next parameter-bearing segment is prefetched when the device supports asynchronous transfer. No opt-in streaming flag is required.

+For disk-backed weights, the runner can read a batch for the next segment
+while the current segment runs. It uploads the batch early when pinned host
+memory and space for both segments are available. When only one segment fits
+on the GPU, the next segment can still use the batch already read into RAM.
+Weights outside the read budget load on demand.
+
 When planning a new monolithic workspace allocation, the runner requires an
 additional 128 MiB in both available device memory and any explicit managed
 budget. New device allocations also reserve 512 MiB for backend scratch
diff --git a/src/core/segment_weight_pipeline.cpp b/src/core/segment_weight_pipeline.cpp
index 3dccda6..0f472db 100644
--- a/src/core/segment_weight_pipeline.cpp
+++ b/src/core/segment_weight_pipeline.cpp
@@ -60,21 +60,12 @@ namespace sd {
         return {segment_params_.rbegin(), segment_params_.rend()};
     }

-    void SegmentWeightPipeline::disable() {
-        clear();
-        enabled_ = false;
-    }
-
     void SegmentWeightPipeline::activate(size_t segment_index) {
-        if (!enabled_ || queued_segment_ == SIZE_MAX || queued_segment_ != segment_index) {
+        if (queued_segment_ != segment_index) {
             return;
         }
-
-        auto manager = residency_manager_.lock();
-        if (manager == nullptr ||
-            !manager->activate_prefetched_params(owner_id_, queued_params_)) {
-            disable();
-            return;
+        if (auto manager = residency_manager_.lock()) {
+            manager->activate_prefetched_params(owner_id_);
         }
         queued_params_.clear();
         queued_segment_ = SIZE_MAX;
@@ -104,6 +95,7 @@ namespace sd {

     bool SegmentWeightPipeline::segment_start(size_t segment_index, const std::function<bool()>& ensure_capacity) {
         GGML_ASSERT(pinned_params_.empty());
+        const bool prefetched = queued_segment_ == segment_index;
         activate(segment_index);
         if (!ensure_capacity()) {
             return false;
@@ -112,7 +104,7 @@ namespace sd {
         if (manager == nullptr) {
             return segment_params_[segment_index].empty();
         }
-        if (!manager->prepare_params(segment_params_[segment_index])) {
+        if (!manager->prepare_params(segment_params_[segment_index], prefetched ? owner_id_ : 0)) {
             return false;
         }
         pinned_params_ = segment_params_[segment_index];
@@ -154,51 +146,42 @@ namespace sd {

         auto manager = residency_manager_.lock();
         if (manager == nullptr) {
-            disable();
             return;
         }
-        const WeightResidencyInfo residency =
-            manager->inspect_compute_backend_params(params);
-        if (residency.missing_bytes == 0) {
-            return;
-        }
-        if (!residency.async_prefetch_supported) {
-            disable();
+        auto residency = manager->inspect_compute_backend_params(params);
+        if (residency.upload_params.empty() && residency.file_params.empty()) {
             return;
         }

-        PrefetchBuffer prefetch_buffer{residency.single_prefetch_buffer_type, residency.missing_bytes};
+        PrefetchBuffer prefetch_buffer{residency.single_prefetch_buffer_type, residency.upload_bytes};
         DeviceMemoryRequest backend_request        = request;
         backend_request.compute_backend            = compute_backend_;
         backend_request.owner_id                   = owner_id_;
-        backend_request.prefetch_buffer            = prefetch_buffer.type != nullptr ? &prefetch_buffer : nullptr;
+        backend_request.quiet                      = true;
         std::vector<ggml_tensor*> protected_params = segment_params_[segment_index];
         protected_params.insert(protected_params.end(), params.begin(), params.end());
-        if (!manager->ensure_compute_backend_capacity(backend_request,
-                                                      params,
-                                                      preferred_eviction_order(),
-                                                      protected_params)) {
-            disable();
-            return;
+        auto reserve = [&](const std::vector<ggml_tensor*>& upload, PrefetchBuffer* reuse) {
+            backend_request.prefetch_buffer = reuse;
+            return manager->ensure_compute_backend_capacity(backend_request, upload,
+                                                            preferred_eviction_order(), protected_params);
+        };
+
+        if (residency.async_file_upload) {
+            auto upload = residency.upload_params;
+            upload.insert(upload.end(), residency.file_upload_params.begin(), residency.file_upload_params.end());
+            residency.async_file_upload = reserve(upload, nullptr);
+        }
+        if (!residency.async_file_upload && !residency.upload_params.empty() &&
+            !reserve(residency.upload_params, prefetch_buffer.type ? &prefetch_buffer : nullptr)) {
+            residency.upload_params.clear();
+        }
+
+        const auto result = manager->prepare_prefetch_params(owner_id_, residency, &prefetch_buffer);
+        if (result == WeightPrefetchResult::Scheduled || result == WeightPrefetchResult::ScheduledAfterCompute) {
+            queued_params_        = std::move(params);
+            queued_segment_       = next_segment;
+            queued_after_compute_ = result == WeightPrefetchResult::ScheduledAfterCompute;
         }
-        const auto result = manager->prepare_prefetch_params(owner_id_, params, backend_request.prefetch_buffer);
-        switch (result) {
-            case WeightPrefetchResult::Scheduled:
-            case WeightPrefetchResult::ScheduledAfterCompute:
-                queued_params_        = std::move(params);
-                queued_segment_       = next_segment;
-                queued_after_compute_ = result == WeightPrefetchResult::ScheduledAfterCompute;
-                return;
-            case WeightPrefetchResult::AlreadyResident:
-                return;
-            case WeightPrefetchResult::Unsupported:
-                disable();
-                return;
-            case WeightPrefetchResult::Failed:
-                disable();
-                return;
-        }
-        disable();
     }

     void SegmentWeightPipeline::submit_next() {
diff --git a/src/core/segment_weight_pipeline.h b/src/core/segment_weight_pipeline.h
index b3f0b83..cbb82e8 100644
--- a/src/core/segment_weight_pipeline.h
+++ b/src/core/segment_weight_pipeline.h
@@ -35,7 +35,6 @@ namespace sd {

         size_t next_parameter_segment(size_t segment_index) const;
         std::vector<std::vector<ggml_tensor*>> preferred_eviction_order() const;
-        void disable();
         void activate(size_t segment_index);
         void clear();

diff --git a/src/device_residency_manager.h b/src/device_residency_manager.h
index e2d8b2f..0fe758e 100644
--- a/src/device_residency_manager.h
+++ b/src/device_residency_manager.h
@@ -21,14 +21,15 @@ namespace sd::weights {
 enum class WeightPrefetchResult {
     Scheduled,
     ScheduledAfterCompute,
-    AlreadyResident,
     Unsupported,
-    Failed,
 };

 struct WeightResidencyInfo {
-    bool async_prefetch_supported                          = false;
-    size_t missing_bytes                                   = 0;
+    std::vector<ggml_tensor*> upload_params;
+    std::vector<ggml_tensor*> file_params;
+    std::vector<ggml_tensor*> file_upload_params;
+    size_t upload_bytes                                    = 0;
+    bool async_file_upload                                 = false;
     ggml_backend_buffer_type_t single_prefetch_buffer_type = nullptr;
 };

@@ -184,8 +185,8 @@ public:
     virtual bool assign_compute_backend(const std::vector<ggml_tensor*>& tensors,
                                         ggml_backend_t compute_backend)       = 0;
     virtual ggml_tensor* resolve_param_tensor(ggml_tensor* tensor) const { return nullptr; }
-    virtual bool prepare_params(const std::vector<ggml_tensor*>& tensors)                 = 0;
-    virtual void release_compute_backend_params(const std::vector<ggml_tensor*>& tensors) = 0;
+    virtual bool prepare_params(const std::vector<ggml_tensor*>& tensors, uintptr_t prefetch_owner = 0) = 0;
+    virtual void release_compute_backend_params(const std::vector<ggml_tensor*>& tensors)               = 0;
     // Drops compute copies of weights whose params location is not the compute device.
     virtual void evict_compute_backend_params(const std::vector<ggml_tensor*>& tensors) = 0;
     virtual WeightResidencyInfo inspect_compute_backend_params(
@@ -216,19 +217,13 @@ public:
         const std::vector<ggml_tensor*>& protected_params) const { return {}; }
     // protected_params: weights of the request the action makes room for; nested reclaim keeps them.
     virtual bool evict_compute_backend_block(const WeightResidencyBlock& block, PrefetchBuffer* prefetch_buffer = nullptr, const std::vector<ggml_tensor*>* protected_params = nullptr) { return false; }
-    virtual WeightPrefetchResult prefetch_params(
-        uintptr_t owner_id,
-        const std::vector<ggml_tensor*>& tensors) = 0;
     virtual WeightPrefetchResult prepare_prefetch_params(
         uintptr_t owner_id,
-        const std::vector<ggml_tensor*>& tensors,
-        PrefetchBuffer* prefetch_buffer = nullptr) {
-        return prefetch_params(owner_id, tensors);
-    }
+        const WeightResidencyInfo& info,
+        PrefetchBuffer* prefetch_buffer) = 0;
     virtual void submit_prefetched_params(uintptr_t owner_id) {}
-    virtual bool activate_prefetched_params(uintptr_t owner_id,
-                                            const std::vector<ggml_tensor*>& tensors) = 0;
-    virtual void clear_prefetched_params(uintptr_t owner_id)                          = 0;
+    virtual void activate_prefetched_params(uintptr_t owner_id) = 0;
+    virtual void clear_prefetched_params(uintptr_t owner_id)    = 0;
 };

 // Transitional alias for model constructors that have not yet adopted the
diff --git a/src/model_loader.cpp b/src/model_loader.cpp
index 59a33b4..6eee683 100644
--- a/src/model_loader.cpp
+++ b/src/model_loader.cpp
@@ -1127,6 +1127,18 @@ std::vector<ggml_backend_buffer_t> ModelLoader::get_device_mmap_buffers() const
     return buffers;
 }

+static bool file_has_mmap_buffer(const ModelFileData& file, ggml_backend_buffer_t buffer) {
+    return buffer && (buffer == file.mmbuffer.get() ||
+                      std::any_of(file.device_mmbuffers.begin(), file.device_mmbuffers.end(),
+                                  [buffer](const auto& entry) { return entry.second.get() == buffer; }));
+}
+
+bool ModelLoader::is_mmap_buffer(ggml_backend_buffer_t buffer) const {
+    return std::any_of(file_data.begin(), file_data.end(), [buffer](const ModelFileData& file) {
+        return file_has_mmap_buffer(file, buffer);
+    });
+}
+
 bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb,
                                bool enable_mmap,
                                const std::set<std::string>* target_tensor_names,
@@ -1269,13 +1281,7 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb,
                         break;
                     }

-                    // skip mmapped tensors
-                    if (dst_tensor->buffer != nullptr && dst_tensor->buffer == fdata.mmbuffer.get()) {
-                        continue;
-                    }
-                    if (dst_tensor->buffer != nullptr &&
-                        std::any_of(fdata.device_mmbuffers.begin(), fdata.device_mmbuffers.end(),
-                                    [&](const auto& entry) { return entry.second.get() == dst_tensor->buffer; })) {
+                    if (file_has_mmap_buffer(fdata, dst_tensor->buffer)) {
                         continue;
                     }

@@ -1426,19 +1432,17 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb,
             });
         }

-        while (true) {
+        while (log_progress) {
             size_t current_idx = tensor_idx.load();
             if (current_idx >= tensors_to_process.size() || failed) {
                 break;
             }
             size_t curr_num       = total_tensors_processed + current_idx;
             float elapsed_seconds = (ggml_time_ms() - t_start) / 1000.0f;
-            if (log_progress && total_tensors_to_process > 0) {
-                pretty_bytes_progress(static_cast<int>(curr_num),
-                                      static_cast<int>(total_tensors_to_process),
-                                      bytes_processed.load(),
-                                      elapsed_seconds);
-            }
+            pretty_bytes_progress(static_cast<int>(curr_num),
+                                  static_cast<int>(total_tensors_to_process),
+                                  bytes_processed.load(),
+                                  elapsed_seconds);
             std::this_thread::sleep_for(std::chrono::milliseconds(total_tensors_to_process <= 4 ? 10 : 200));
         }

diff --git a/src/model_loader.h b/src/model_loader.h
index 86113be..c6198c3 100644
--- a/src/model_loader.h
+++ b/src/model_loader.h
@@ -80,7 +80,6 @@ private:
     static bool file_unchanged(const FileStamp& stamp);
     bool parse_file(const std::string& path, const std::string& prefix);
     bool add_file_impl(const std::string& path, const std::string& prefix, FileId* id, bool force, FileScope scope);
-    ModelLoader file_reader(FileId id, SDVersion version) const;
     void rebuild_catalog();
     void invalidate_file_data();

@@ -115,6 +114,7 @@ public:
     bool same_weight_file(FileId id, size_t index, const ModelLoader& other, FileId other_id, size_t other_index) const;
     std::string file_path(FileId id) const;
     std::map<std::string, std::string> file_metadata(FileId id) const;
+    ModelLoader file_reader(FileId id, SDVersion version) const;
     String2TensorStorage file_tensors(FileId id) const;
     String2TensorStorage file_tensors(FileId id, SDVersion version) const;
     bool load_file_tensors(FileId id, SDVersion version, on_new_tensor_cb_t callback, const std::set<std::string>& names, bool use_mmap = false) const;
@@ -144,6 +144,7 @@ public:
                                               bool writable                        = true,
                                               ggml_backend_dev_t device            = nullptr);
     std::vector<ggml_backend_buffer_t> get_device_mmap_buffers() const;
+    bool is_mmap_buffer(ggml_backend_buffer_t buffer) const;
     bool load_tensors(on_new_tensor_cb_t on_new_tensor_cb,
                       bool use_mmap                                    = false,
                       const std::set<std::string>* target_tensor_names = nullptr,
diff --git a/src/model_manager.cpp b/src/model_manager.cpp
index a8ac9b8..e90b285 100644
--- a/src/model_manager.cpp
+++ b/src/model_manager.cpp
@@ -684,7 +684,7 @@ bool ModelManager::validate_param_tensors(const std::vector<ggml_tensor*>& tenso
     return true;
 }

-bool ModelManager::load_tensors_to_params_backend(const std::vector<TensorState*>& states, bool* capacity_failure) {
+bool ModelManager::load_tensors_to_params_backend(const std::vector<TensorState*>& states, bool* capacity_failure, uintptr_t prefetch_owner) {
     std::vector<TensorState*> need_load;
     need_load.reserve(states.size());
     for (TensorState* state : states) {
@@ -729,7 +729,7 @@ bool ModelManager::load_tensors_to_params_backend(const std::vector<TensorState*

     const bool allocated = alloc_params_buffers(need_alloc, states, created_storage_blocks, capacity_failure);
     need_load.erase(std::remove_if(need_load.begin(), need_load.end(), stages_from_file), need_load.end());
-    if (!allocated || !load_tensors(need_load)) {
+    if (!allocated || !load_tensors(need_load, need_alloc, prefetch_owner)) {
         for (ParamsStorageBlock* block : created_storage_blocks) {
             if (block != nullptr) {
                 store_.free_params_storage_block(*block);
@@ -991,7 +991,9 @@ bool ModelManager::ensure_device_capacity(const DeviceMemoryRequest& request,
     return capacity_provider().reserve(request, required_params, preferred_eviction_order, protected_params, device_memory_error);
 }

-bool ModelManager::stage_tensors_to_compute_backend(const std::vector<TensorState*>& states, bool& capacity_failure) {
+bool ModelManager::stage_tensors_to_compute_backend(const std::vector<TensorState*>& states,
+                                                    bool& capacity_failure,
+                                                    uintptr_t prefetch_owner) {
     std::map<std::tuple<ggml_backend_t, ggml_backend_buffer_type_t, Resource*, ModelLoader::FileId>, std::vector<TensorState*>> states_by_staging_target;
     for (TensorState* state : states) {
         if (state == nullptr || should_ignore(*state) || (state->sources.empty() && is_optional_missing_tensor(state->name))) {
@@ -1104,7 +1106,11 @@ bool ModelManager::stage_tensors_to_compute_backend(const std::vector<TensorStat
             // Compute copies without a params copy read the model file directly.
             std::vector<sd::weights::ReadTarget> file_reads;
             for (auto& [state, staging_tensor] : staged_tensors) {
-                if (state->param_source() == ParamSource::ModelFile && !reusable_lora_weight(*state))
+                if (state->param_source() != ParamSource::ModelFile || reusable_lora_weight(*state))
+                    continue;
+                if (const auto* source = prefetched_file_tensor(prefetch_owner, *state))
+                    ggml_backend_tensor_copy(source, staging_tensor);
+                else
                     file_reads.push_back(read_target(*state, staging_tensor));
             }
             if (!file_reads.empty() && !sd::weights::read_weights(file_reads)) {
@@ -1373,6 +1379,10 @@ size_t ModelManager::host_weight_bytes() const {
     for (const auto& entry : prefetch_blocks_) {
         for (const auto& block : entry.second->staging_blocks)
             add_buffer(block->buffer);
+        if (const auto& file = entry.second->file) {
+            add_buffer(file->host.get());
+            add(file->scratch_bytes);
+        }
     }
     return bytes;
 }
@@ -1408,7 +1418,7 @@ bool ModelManager::ensure_host_capacity(size_t pending, const std::vector<Tensor
     size_t available = 0;
     auto fits        = [&] { return fits_host_capacity(pending, weight_allocation, pending_device_commit, available); };
     host_memory_error_.clear();
-    if (fits())
+    if (fits_host_capacity_after_prefetch_reclaim(pending, weight_allocation, pending_device_commit, available))
         return true;

     if (!weight_allocation || !max_ram_bytes_ || pending <= max_ram_bytes_) {
@@ -1478,7 +1488,7 @@ bool ModelManager::alloc_params_buffers(const std::vector<TensorState*>& states,
             .push_back(state);
     }
     size_t host_left = 0;
-    if (host_bytes > 0 && !fits_host_capacity(host_bytes, true, 0, host_left)) {
+    if (host_bytes > 0 && !fits_host_capacity_after_prefetch_reclaim(host_bytes, true, 0, host_left)) {
         // Reserve RAM for tensors the compute device cannot read directly from a device buffer.
         std::unordered_set<const ggml_tensor*> view_bases;
         for (auto* state : required_states) {
@@ -1658,11 +1668,21 @@ sd::weights::ReadTarget ModelManager::read_target(const TensorState& state, ggml
     return target;
 }

-bool ModelManager::load_tensors(const std::vector<TensorState*>& states) {
+bool ModelManager::load_tensors(const std::vector<TensorState*>& states,
+                               const std::vector<TensorState*>& need_alloc,
+                               uintptr_t prefetch_owner) {
+    // Collected after mmap and shared reuse, need_alloc contains the destinations safe to overwrite.
+    std::unordered_set<TensorState*> writable;
+    if (prefetch_owner)
+        writable.insert(need_alloc.begin(), need_alloc.end());
     std::vector<sd::weights::ReadTarget> targets;
     targets.reserve(states.size());
     for (auto* state : states) {
-        if (state != nullptr)
+        if (!state)
+            continue;
+        if (const auto* source = writable.count(state) ? prefetched_file_tensor(prefetch_owner, *state) : nullptr)
+            ggml_backend_tensor_copy(source, state->tensor);
+        else
             targets.push_back(read_target(*state, state->tensor));
     }
     if (!sd::weights::read_weights(targets))
@@ -1962,6 +1982,8 @@ size_t ModelManager::compute_backend_resident_bytes(ggml_backend_t compute_backe
                     add_buffer(block->buffer);
                 }
             }
+            if (const auto& file = entry.second->file; file && file->device)
+                add_buffer(file->device->buffer);
         }
     }
     return total_size;
@@ -2058,65 +2080,6 @@ void ModelManager::release_compute_backend_params(const std::vector<ggml_tensor*
     finish_compute_backend_usage(required_states);
 }

-WeightResidencyInfo ModelManager::inspect_compute_backend_params(
-    const std::vector<ggml_tensor*>& tensors) const {
-    WeightResidencyInfo info;
-    std::vector<TensorState*> states;
-    if (!resolve_required_tensor_states(tensors, states)) {
-        return info;
-    }
-
-    ggml_backend_t prefetch_compute_backend = nullptr;
-    bool has_missing_params                 = false;
-    bool prefetch_candidate                 = true;
-    bool single_prefetch_buffer             = true;
-    for (TensorState* state : states) {
-        if (state == nullptr || should_ignore(*state) ||
-            (state->sources.empty() && is_optional_missing_tensor(state->name))) {
-            continue;
-        }
-        if (compute_params_resident(*state)) {
-            continue;
-        }
-        has_missing_params = true;
-        // A merged weight uploads from its RAM cache; an INT8 pair without one stages synchronously.
-        const bool cached = reusable_lora_weight(*state) != nullptr;
-        if (state->usage_op == GGML_OP_CUSTOM || (has_lora_int8_pair(*state) && !cached)) {
-            single_prefetch_buffer = false;
-        }
-        if (split_buffer_type_for(*state) != nullptr) {
-            prefetch_candidate = false;
-        }
-        if ((!cached && (state->compute_backend == state->params_backend() || state->param_source() != ParamSource::Backend)) ||
-            state->compute_backend == nullptr || sd_backend_is_cpu(state->compute_backend)) {
-            prefetch_candidate = false;
-            continue;
-        }
-        if (prefetch_compute_backend == nullptr) {
-            prefetch_compute_backend = state->compute_backend;
-        } else if (prefetch_compute_backend != state->compute_backend) {
-            prefetch_candidate = false;
-        }
-    }
-    info.missing_bytes = compute_backend_alloc_size(states, true);
-    if (has_missing_params && prefetch_candidate && prefetch_compute_backend != nullptr) {
-        ggml_backend_dev_t device = ggml_backend_get_device(prefetch_compute_backend);
-        if (device != nullptr) {
-            ggml_backend_dev_props props{};
-            ggml_backend_dev_get_props(device, &props);
-            info.async_prefetch_supported = props.caps.async;
-        }
-        if (info.async_prefetch_supported && single_prefetch_buffer && info.missing_bytes > 0 &&
-            (sd_backend_is(prefetch_compute_backend, "CUDA") || sd_backend_is(prefetch_compute_backend, "ROCm"))) {
-            auto buft = ggml_backend_get_default_buffer_type(prefetch_compute_backend);
-            if (info.missing_bytes <= std::min(MAX_RESIDENCY_BLOCK_BYTES, ggml_backend_buft_get_max_size(buft))) {
-                info.single_prefetch_buffer_type = buft;
-            }
-        }
-    }
-    return info;
-}
-
 void ModelManager::register_runtime_owner(uintptr_t owner_id) {
     runtime_owners_.insert(owner_id);
 }
diff --git a/src/model_manager.h b/src/model_manager.h
index 6f4ca99..f6e1423 100644
--- a/src/model_manager.h
+++ b/src/model_manager.h
@@ -3,9 +3,11 @@

 #include <cstdint>
 #include <functional>
+#include <future>
 #include <list>
 #include <map>
 #include <memory>
+#include <mutex>
 #include <set>
 #include <string>
 #include <tuple>
@@ -114,6 +116,18 @@ private:
     static Resource& resource_of(const TensorState& state) { return *static_cast<Resource*>(state.resource); }
     static Resource* resource_ptr(const TensorState& state) { return static_cast<Resource*>(state.resource); }

+    struct FilePrefetch {
+        std::unique_ptr<ggml_context, decltype(&ggml_free)> context{nullptr, ggml_free};
+        std::unique_ptr<ggml_backend_buffer, decltype(&ggml_backend_buffer_free)> host{nullptr, ggml_backend_buffer_free};
+        std::map<TensorState*, ggml_tensor*> tensors;
+        std::unique_ptr<ComputeStagingBlock> device;
+        sd::weights::PendingTransfer transfer;
+        size_t scratch_bytes = 0;
+        bool ready           = false;
+        std::future<bool> read;
+        ~FilePrefetch();
+    };
+
     struct PrefetchBlock {
         std::vector<TensorState*> states;
         ggml_backend_t compute_backend = nullptr;
@@ -124,6 +138,7 @@ private:
         // The storage epoch of each original when its upload was queued. A merge in place
         // afterwards leaves the uploaded bytes stale.
         std::map<const TensorState*, uint64_t> source_epochs;
+        std::unique_ptr<FilePrefetch> file;
     };

     struct RuntimeResidency {
@@ -144,6 +159,8 @@ private:
     // A batched merge needs its completed copies until the full request is ready again.
     const std::unordered_set<TensorState*>* lora_batch_spills_ = nullptr;
     sd::weights::WeightTransfer transfer_;
+    sd::weights::WeightTransfer file_transfer_;
+    std::mutex file_transfer_mutex_;
     std::map<std::pair<uintptr_t, ggml_backend_t>, RuntimeResidency> runtime_residencies_;
     std::unordered_set<uintptr_t> runtime_owners_;
     uint64_t residency_epoch_ = 0;
@@ -155,6 +172,14 @@ private:

     static const ggml_tensor* prefetch_source(const PrefetchBlock& block, const TensorState& state);
     bool populate_prefetch_block(PrefetchBlock& block, PrefetchBuffer* prefetch_buffer);
+    static std::unique_ptr<ComputeStagingBlock> allocate_prefetch_chunk(
+        ggml_backend_t backend,
+        const std::vector<TensorState*>& states,
+        PrefetchBuffer* prefetch_buffer = nullptr);
+    static void free_prefetch_staging(ComputeStagingBlock& block);
+    std::unique_ptr<FilePrefetch> prepare_file_prefetch(const WeightResidencyInfo& info);
+    static bool wait_file_prefetch(FilePrefetch& file);
+    const ggml_tensor* prefetched_file_tensor(uintptr_t owner, TensorState& state) const;
     void free_prefetch_block(PrefetchBlock& block);
     void protect_prefetched_states(std::unordered_set<TensorState*>& states) const;
     void clear_all_prefetched_params();
@@ -169,7 +194,7 @@ private:
     bool validate_tensor(const TensorState& state) const;

     // capacity_failure reports that device memory ran out; the caller then retries with less.
-    bool load_tensors_to_params_backend(const std::vector<TensorState*>& states, bool* capacity_failure = nullptr);
+    bool load_tensors_to_params_backend(const std::vector<TensorState*>& states, bool* capacity_failure = nullptr, uintptr_t prefetch_owner = 0);
     void reuse_shared_weights(std::vector<TensorState*>& need_load);
     static bool has_lora_int8_pair(const TensorState& state);
     static bool needs_lora_staging(const TensorState& state);
@@ -213,7 +238,7 @@ private:
     bool ready_for_compute(const TensorState& state) const;
     // Loads and stages the weights so the compute device can read them.
     // capacity_failure reports that staging ran out of device memory.
-    bool ensure_copies(const std::vector<TensorState*>& states, bool* capacity_failure = nullptr);
+    bool ensure_copies(const std::vector<TensorState*>& states, bool* capacity_failure = nullptr, uintptr_t prefetch_owner = 0);
     void release_unprepared(const std::vector<TensorState*>& states);
     // Returns the use epoch; 0 starts a new one.
     uint64_t lease_states(const std::vector<TensorState*>& states, uint64_t use_epoch = 0);
@@ -253,13 +278,14 @@ private:
     // reload: weights whose device reload size the plan needs, i.e. the request's weights.
     sd::weights::Snapshot residency_snapshot(const sd::weights::Request& plan, ggml_backend_t backend) const;
     bool fits_host_capacity(size_t pending, bool weight_allocation, size_t pending_device_commit, size_t& available) const;
+    bool fits_host_capacity_after_prefetch_reclaim(size_t pending, bool weight_allocation, size_t pending_device_commit, size_t& available);
     bool ensure_host_capacity(size_t pending, const std::vector<TensorState*>& required_states, bool weight_allocation = true, size_t pending_device_commit = 0, bool optional = false, const sd::weights::PriorityLimit* limit = nullptr);
     bool alloc_params_buffers(const std::vector<TensorState*>& states,
                               const std::vector<TensorState*>& required_states,
                               std::vector<ParamsStorageBlock*>& created_storage_blocks,
                               bool* capacity_failure = nullptr);
-    bool load_tensors(const std::vector<TensorState*>& states);
-    bool stage_tensors_to_compute_backend(const std::vector<TensorState*>& states, bool& capacity_failure);
+    bool load_tensors(const std::vector<TensorState*>& states, const std::vector<TensorState*>& need_alloc, uintptr_t prefetch_owner);
+    bool stage_tensors_to_compute_backend(const std::vector<TensorState*>& states, bool& capacity_failure, uintptr_t prefetch_owner);
     size_t compute_backend_alloc_size(const std::vector<TensorState*>& states,
                                       bool missing_only) const;
     size_t compute_backend_resident_bytes(ggml_backend_t compute_backend) const;
@@ -414,7 +440,7 @@ public:

     bool assign_compute_backend(const std::vector<ggml_tensor*>& tensors,
                                 ggml_backend_t compute_backend) override;
-    bool prepare_params(const std::vector<ggml_tensor*>& tensors) override;
+    bool prepare_params(const std::vector<ggml_tensor*>& tensors, uintptr_t prefetch_owner = 0) override;
     bool ensure_host_memory(size_t pending, const std::vector<ggml_tensor*>& protected_params, size_t pending_device_commit = 0) override;
     void register_runtime_owner(uintptr_t owner_id) override;
     void remove_runtime_owner(uintptr_t owner_id) override;
@@ -449,16 +475,12 @@ public:
                                                    const std::vector<ggml_tensor*>& required_params,
                                                    const std::vector<std::vector<ggml_tensor*>>& preferred_eviction_order,
                                                    const std::vector<ggml_tensor*>& protected_params) const override;
-    WeightPrefetchResult prefetch_params(
-        uintptr_t owner_id,
-        const std::vector<ggml_tensor*>& tensors) override;
     WeightPrefetchResult prepare_prefetch_params(
         uintptr_t owner_id,
-        const std::vector<ggml_tensor*>& tensors,
+        const WeightResidencyInfo& info,
         PrefetchBuffer* prefetch_buffer = nullptr) override;
     void submit_prefetched_params(uintptr_t owner_id) override;
-    bool activate_prefetched_params(uintptr_t owner_id,
-                                    const std::vector<ggml_tensor*>& tensors) override;
+    void activate_prefetched_params(uintptr_t owner_id) override;
     void clear_prefetched_params(uintptr_t owner_id) override;
 };

@@ -550,7 +572,9 @@ public:
         return manager_->assign_compute_backend(tensors, backend);
     }
     ggml_tensor* resolve_param_tensor(ggml_tensor* tensor) const override { return manager_->resolve_param_tensor(tensor); }
-    bool prepare_params(const std::vector<ggml_tensor*>& tensors) override { return manager_->prepare_params(tensors); }
+    bool prepare_params(const std::vector<ggml_tensor*>& tensors, uintptr_t prefetch_owner = 0) override {
+        return manager_->prepare_params(tensors, prefetch_owner);
+    }
     void release_compute_backend_params(const std::vector<ggml_tensor*>& tensors) override {
         manager_->release_compute_backend_params(tensors);
     }
@@ -589,15 +613,17 @@ public:
         return manager_->plan_reclaim(request, required_params, preferred_eviction_order, protected_params);
     }

-    WeightPrefetchResult prefetch_params(uintptr_t owner, const std::vector<ggml_tensor*>& tensors) override {
-        return manager_->prefetch_params(owner, tensors);
+    WeightPrefetchResult prepare_prefetch_params(
+        uintptr_t owner,
+        const WeightResidencyInfo& info,
+        PrefetchBuffer* prefetch_buffer = nullptr) override {
+        return manager_->prepare_prefetch_params(owner, info, prefetch_buffer);
     }
-    WeightPrefetchResult prepare_prefetch_params(uintptr_t owner, const std::vector<ggml_tensor*>& tensors, PrefetchBuffer* prefetch_buffer) override {
-        return manager_->prepare_prefetch_params(owner, tensors, prefetch_buffer);
+    void submit_prefetched_params(uintptr_t owner) override {
+        manager_->submit_prefetched_params(owner);
     }
-    void submit_prefetched_params(uintptr_t owner) override { manager_->submit_prefetched_params(owner); }
-    bool activate_prefetched_params(uintptr_t owner, const std::vector<ggml_tensor*>& tensors) override {
-        return manager_->activate_prefetched_params(owner, tensors);
+    void activate_prefetched_params(uintptr_t owner) override {
+        manager_->activate_prefetched_params(owner);
     }
     void clear_prefetched_params(uintptr_t owner) override { manager_->clear_prefetched_params(owner); }
 };
diff --git a/src/model_manager_prefetch.cpp b/src/model_manager_prefetch.cpp
index 69303ee..2d9ec52 100644
--- a/src/model_manager_prefetch.cpp
+++ b/src/model_manager_prefetch.cpp
@@ -5,27 +5,67 @@
 #include <unordered_set>
 #include <utility>

+#include "core/file_access.h"
 #include "core/ggml_extend_backend.h"
 #include "core/util.h"
 #include "ggml-alloc.h"

+void ModelManager::free_prefetch_staging(ComputeStagingBlock& block) {
+    if (block.buffer)
+        ggml_backend_buffer_free(block.buffer);
+    if (block.staging_ctx)
+        ggml_free(block.staging_ctx);
+}
+
+ModelManager::FilePrefetch::~FilePrefetch() {
+    if (read.valid())
+        read.wait();
+    sd::weights::WeightTransfer::wait(transfer);
+    if (device)
+        free_prefetch_staging(*device);
+}
+
 void ModelManager::free_prefetch_block(PrefetchBlock& block) {
+    block.file.reset();
     sd::weights::WeightTransfer::wait(block.transfer);
-    for (auto& staging_block : block.staging_blocks) {
-        if (staging_block == nullptr) {
-            continue;
-        }
-        staging_block->staged_tensors.clear();
-        if (staging_block->buffer != nullptr) {
-            ggml_backend_buffer_free(staging_block->buffer);
-            staging_block->buffer = nullptr;
-        }
-        if (staging_block->staging_ctx != nullptr) {
-            ggml_free(staging_block->staging_ctx);
-            staging_block->staging_ctx = nullptr;
+    for (const auto& staging : block.staging_blocks)
+        free_prefetch_staging(*staging);
+    block.staging_blocks.clear();
+}
+
+std::unique_ptr<ModelManager::ComputeStagingBlock> ModelManager::allocate_prefetch_chunk(
+    ggml_backend_t backend,
+    const std::vector<TensorState*>& states,
+    PrefetchBuffer* prefetch_buffer) {
+    auto context = std::unique_ptr<ggml_context, decltype(&ggml_free)>(
+        ggml_init({states.size() * ggml_tensor_overhead(), nullptr, true}), ggml_free);
+    if (!context)
+        return nullptr;
+    auto block             = std::make_unique<ComputeStagingBlock>();
+    block->compute_backend = backend;
+    block->staged_tensors.reserve(states.size());
+    for (auto* state : states) {
+        auto* tensor = ggml_dup_tensor(context.get(), state->tensor);
+        ggml_set_name(tensor, state->tensor->name);
+        block->staged_tensors.emplace_back(state, tensor);
+    }
+    if (prefetch_buffer && prefetch_buffer->buffer) {
+        auto allocator = ggml_tallocr_new(prefetch_buffer->buffer.get());
+        for (const auto& [_, tensor] : block->staged_tensors) {
+            if (ggml_tallocr_alloc(&allocator, tensor) != GGML_STATUS_SUCCESS)
+                return nullptr;
         }
+        block->buffer = prefetch_buffer->buffer.release();
+        LOG_DEBUG("model manager reused %.2f MiB of staging storage for prefetch on %s",
+                  prefetch_buffer->bytes / (1024.0 * 1024.0), ggml_backend_name(backend));
+    } else {
+        block->buffer = ggml_backend_alloc_ctx_tensors_from_buft(context.get(), ggml_backend_get_default_buffer_type(backend));
     }
-    block.staging_blocks.clear();
+    if (!block->buffer)
+        return nullptr;
+    block->staging_ctx = context.release();
+    ggml_backend_buffer_set_usage(block->buffer, GGML_BACKEND_BUFFER_USAGE_WEIGHTS);
+    return block;
 }

 const ggml_tensor* ModelManager::prefetch_source(const PrefetchBlock& block, const TensorState& state) {
@@ -47,8 +87,10 @@ bool ModelManager::populate_prefetch_block(PrefetchBlock& block, PrefetchBuffer*
         if (state == nullptr || state->tensor == nullptr || state->staged() || state->pin_count() > 0)
             return false;
         const auto* source = prefetch_source(block, *state);
-        if (source->buffer == nullptr || source->data == nullptr ||
-            (source == state->tensor && state->params_backend() == nullptr)) {
+        if (!source->buffer || !source->data ||
+            (source == state->tensor && !state->params_backend()) ||
+            (ggml_backend_buffer_is_host(source->buffer) &&
+             (!ggml_is_contiguous(source) || ggml_nbytes(source) != ggml_nbytes(state->tensor)))) {
             return false;
         }
     }
@@ -85,59 +127,11 @@ bool ModelManager::populate_prefetch_block(PrefetchBlock& block, PrefetchBuffer*
         }
     }

-    auto allocate_chunk = [&](const std::vector<TensorState*>& chunk) -> bool {
-        if (chunk.empty()) {
-            return true;
-        }
-        ggml_init_params init_params;
-        init_params.mem_size      = chunk.size() * ggml_tensor_overhead();
-        init_params.mem_buffer    = nullptr;
-        init_params.no_alloc      = true;
-        ggml_context* staging_ctx = ggml_init(init_params);
-        if (staging_ctx == nullptr) {
+    auto allocate_chunk = [&](const std::vector<TensorState*>& chunk) {
+        auto staging = allocate_prefetch_chunk(block.compute_backend, chunk, prefetch_buffer);
+        if (!staging)
             return false;
-        }
-
-        auto staging_block             = std::make_unique<ComputeStagingBlock>();
-        staging_block->compute_backend = block.compute_backend;
-        staging_block->staging_ctx     = staging_ctx;
-        staging_block->staged_tensors.reserve(chunk.size());
-        for (TensorState* state : chunk) {
-            ggml_tensor* staging_tensor = ggml_dup_tensor(staging_ctx, state->tensor);
-            ggml_set_name(staging_tensor, state->tensor->name);
-            const auto* source = prefetch_source(block, *state);
-            if (ggml_backend_buffer_is_host(source->buffer) &&
-                (!ggml_is_contiguous(source) || !ggml_is_contiguous(staging_tensor) ||
-                 ggml_nbytes(source) != ggml_nbytes(staging_tensor))) {
-                ggml_free(staging_ctx);
-                staging_block->staging_ctx = nullptr;
-                return false;
-            }
-            staging_block->staged_tensors.push_back({state, staging_tensor});
-        }
-        if (reuse_buffer) {
-            auto allocator = ggml_tallocr_new(prefetch_buffer->buffer.get());
-            for (const auto& pair : staging_block->staged_tensors) {
-                if (ggml_tallocr_alloc(&allocator, pair.second) != GGML_STATUS_SUCCESS) {
-                    ggml_free(staging_ctx);
-                    return false;
-                }
-            }
-            staging_block->buffer = prefetch_buffer->buffer.release();
-            LOG_DEBUG("model manager reused %.2f MiB of staging storage for prefetch on %s",
-                      prefetch_buffer->bytes / (1024.0 * 1024.0), ggml_backend_name(block.compute_backend));
-        } else {
-            staging_block->buffer = ggml_backend_alloc_ctx_tensors_from_buft(staging_ctx, buffer_type);
-        }
-        if (staging_block->buffer == nullptr) {
-            ggml_free(staging_ctx);
-            staging_block->staging_ctx = nullptr;
-            return false;
-        }
-        ggml_backend_buffer_set_usage(staging_block->buffer,
-                                      GGML_BACKEND_BUFFER_USAGE_WEIGHTS);
-
-        block.staging_blocks.push_back(std::move(staging_block));
+        block.staging_blocks.push_back(std::move(staging));
         return true;
     };

@@ -166,7 +160,8 @@ bool ModelManager::populate_prefetch_block(PrefetchBlock& block, PrefetchBuffer*

 void ModelManager::submit_prefetched_params(uintptr_t owner_id) {
     auto existing = prefetch_blocks_.find(owner_id);
-    if (existing == prefetch_blocks_.end() || existing->second->transfer.submitted) {
+    if (existing == prefetch_blocks_.end() || existing->second->staging_blocks.empty() ||
+        existing->second->transfer.submitted) {
         return;
     }
     auto& block = *existing->second;
@@ -189,195 +184,413 @@ void ModelManager::submit_prefetched_params(uintptr_t owner_id) {
     }
     LOG_DEBUG("model manager queued segment prefetch (%6.2f MB, %zu tensors) to %s",
               total_size / (1024.f * 1024.f),
-              block.states.size(),
+              copies.size(),
               ggml_backend_name(block.compute_backend));
 }

-WeightPrefetchResult ModelManager::prefetch_params(
-    uintptr_t owner_id,
-    const std::vector<ggml_tensor*>& tensors) {
-    auto result = prepare_prefetch_params(owner_id, tensors);
-    if (result == WeightPrefetchResult::Scheduled || result == WeightPrefetchResult::ScheduledAfterCompute) {
-        submit_prefetched_params(owner_id);
-    }
-    return result;
-}
+static constexpr size_t MAX_FILE_PREFETCH_BYTES = 256 * 1024 * 1024;

-WeightPrefetchResult ModelManager::prepare_prefetch_params(
-    uintptr_t owner_id,
-    const std::vector<ggml_tensor*>& tensors,
-    PrefetchBuffer* prefetch_buffer) {
-    if (tensors.empty()) {
-        return WeightPrefetchResult::AlreadyResident;
-    }
+static bool file_prefetch_can_bind_compute(const sd::weights::TensorState& state) {
+    return state.param_source() == sd::weights::ParamSource::ModelFile ||
+           state.residency_mode == sd::weights::ResidencyMode::Disk;
+}

-    std::vector<TensorState*> required_states;
-    if (!resolve_required_tensor_states(tensors, required_states)) {
-        return WeightPrefetchResult::Failed;
+// ZIP entries can expand beyond a tensor's raw size, so they use the normal reader.
+static size_t file_prefetch_scratch(const sd::weights::TensorState& state) {
+    size_t largest = 0;
+    for (const auto& source : state.sources) {
+        if (source.index_in_zip >= 0)
+            return SIZE_MAX;
+        if (source.type == state.tensor->type && !source.is_f64 && !source.is_i64)
+            continue;
+        largest = std::max(largest, static_cast<size_t>(std::max(source.nbytes(), source.nbytes_to_read())));
+        if (source.type != state.tensor->type) {
+            // The loader may dequantize through F32 and retain its read buffer across tensors.
+            if (source.nelements() > MAX_FILE_PREFETCH_BYTES / sizeof(float))
+                return SIZE_MAX;
+            largest = std::max(largest, static_cast<size_t>(source.nelements()) * sizeof(float));
+        }
     }
+    return std::min(largest, SIZE_MAX / 4) * 4;
+}

+WeightResidencyInfo ModelManager::inspect_compute_backend_params(
+    const std::vector<ggml_tensor*>& tensors) const {
+    WeightResidencyInfo info;
     std::vector<TensorState*> states;
-    states.reserve(required_states.size());
-    const std::unordered_set<TensorState*> requested(required_states.begin(), required_states.end());
-    std::map<const TensorState*, std::shared_ptr<const CachedLoraWeight>> merged;
+    if (!resolve_required_tensor_states(tensors, states))
+        return info;
+
+    size_t host_available          = 0;
+    const size_t file_budget       = fits_host_capacity(0, true, 0, host_available)
+                                         ? std::min(MAX_FILE_PREFETCH_BYTES, host_available)
+                                         : 0;
+    const auto cpu_type            = ggml_backend_cpu_buffer_type();
+    size_t host_bytes              = 0;
+    size_t scratch_bytes           = 0;
     ggml_backend_t compute_backend = nullptr;
-    bool needs_synchronous_load    = false;
-    for (TensorState* state : required_states) {
-        if (state == nullptr || should_ignore(*state) ||
-            is_optional_missing_tensor(state->name)) {
-            continue;
-        }
-        // An INT8 weight and its scale upload together, so both carry the same merge.
-        const bool cached = reusable_lora_weight(*state) &&
-                            (!has_lora_int8_pair(*state) || requested.count(state->lora_int8_partner) != 0);
-        if (cached) {
-            if (!state->staged() && state->pin_count() == 0)
-                merged.emplace(state, state->cached_lora());
-        } else if (has_lora_int8_pair(*state) || state->param_source() == ParamSource::ModelFile) {
-            // These weights are restored by synchronous staging, including the LoRA state.
-            needs_synchronous_load = needs_synchronous_load || !state->staged();
-            continue;
-        } else if (state->usage_op == GGML_OP_CUSTOM || state->compute_backend == state->params_backend()) {
-            needs_synchronous_load = needs_synchronous_load ||
-                                     !state->loaded();
+    bool async                     = false;
+    const std::unordered_set<TensorState*> requested(states.begin(), states.end());
+    for (auto* state : states) {
+        if (!state || !state->tensor || state->tensor->view_src || state->sources.empty() ||
+            should_ignore(*state) || compute_params_resident(*state) || state->pin_count() ||
+            state->usage_op == GGML_OP_CUSTOM || split_buffer_type_for(*state) ||
+            !state->compute_backend || sd_backend_is_cpu(state->compute_backend))
             continue;
+        if (!compute_backend) {
+            compute_backend   = state->compute_backend;
+            const auto device = ggml_backend_get_device(compute_backend);
+            if (device) {
+                ggml_backend_dev_props props{};
+                ggml_backend_dev_get_props(device, &props);
+                async                  = props.caps.async;
+                info.async_file_upload = async && props.caps.events && sd_backend_dev_host_buffer_type(device) &&
+                                         !ggml_backend_buft_is_host(ggml_backend_get_default_buffer_type(compute_backend)) &&
+                                         (sd_backend_is(compute_backend, "CUDA") || sd_backend_is(compute_backend, "ROCm") ||
+                                          sd_backend_is(compute_backend, "Vulkan"));
+            }
         }
-        if (state->staged() || state->pin_count() > 0) {
+        if (state->compute_backend != compute_backend)
             continue;
+
+        // Both members of a merged INT8 pair must upload with the same epoch.
+        const bool pair     = has_lora_int8_pair(*state);
+        const auto* partner = state->lora_int8_partner;
+        const bool cached   = reusable_lora_weight(*state) &&
+                              (!pair || (requested.count(state->lora_int8_partner) && !partner->staged() && !partner->pin_count()));
+        if (async && (cached || (!pair && state->loaded() && state->compute_backend != state->params_backend()))) {
+            info.upload_params.push_back(state->tensor);
+        } else if (!cached && !pair && !state->loaded()) {
+            const size_t bytes   = GGML_PAD(ggml_backend_buft_get_alloc_size(cpu_type, state->tensor),
+                                            ggml_backend_buft_get_alignment(cpu_type));
+            const size_t scratch = std::max(scratch_bytes, file_prefetch_scratch(*state));
+            if (scratch <= file_budget - host_bytes && bytes <= file_budget - host_bytes - scratch) {
+                info.file_params.push_back(state->tensor);
+                if (info.async_file_upload && file_prefetch_can_bind_compute(*state))
+                    info.file_upload_params.push_back(state->tensor);
+                host_bytes += bytes;
+                scratch_bytes = scratch;
+            }
         }
-        // Split buffers cannot use the primary device's asynchronous upload path.
-        if (split_buffer_type_for(*state) != nullptr) {
-            return WeightPrefetchResult::Unsupported;
+    }
+    info.async_file_upload = !info.file_upload_params.empty();
+    if (!info.upload_params.empty()) {
+        const auto type      = ggml_backend_get_default_buffer_type(compute_backend);
+        const auto alignment = ggml_backend_buft_get_alignment(type);
+        for (const auto* tensor : info.upload_params) {
+            const auto bytes = GGML_PAD(ggml_backend_buft_get_alloc_size(type, tensor), alignment);
+            info.upload_bytes += std::min(bytes, SIZE_MAX - info.upload_bytes);
         }
-        if (compute_backend == nullptr) {
-            compute_backend = state->compute_backend;
-        } else if (compute_backend != state->compute_backend) {
-            return WeightPrefetchResult::Failed;
+        if (info.upload_bytes <= std::min(MAX_RESIDENCY_BLOCK_BYTES, ggml_backend_buft_get_max_size(type)) &&
+            (sd_backend_is(compute_backend, "CUDA") || sd_backend_is(compute_backend, "ROCm")))
+            info.single_prefetch_buffer_type = type;
+    }
+    return info;
+}
+
+std::unique_ptr<ModelManager::FilePrefetch> ModelManager::prepare_file_prefetch(const WeightResidencyInfo& info) {
+    if (info.file_params.empty())
+        return nullptr;
+
+    auto file = std::make_unique<FilePrefetch>();
+    file->context.reset(ggml_init({info.file_params.size() * ggml_tensor_overhead(), nullptr, true}));
+    if (!file->context)
+        return nullptr;
+    std::vector<TensorState*> states;
+    std::vector<std::vector<TensorStorage>> sources;
+    std::vector<sd::weights::ReadTarget> targets;
+    std::map<std::tuple<ModelLoader*, ModelLoader::FileId, SDVersion>, ModelLoader> readers;
+    std::set<std::string> authorized_paths;
+    size_t scratch = 0;
+    states.reserve(info.file_params.size());
+    sources.reserve(info.file_params.size());
+    targets.reserve(info.file_params.size());
+    for (auto* tensor : info.file_params) {
+        auto* state = store_.tensor_index().at(tensor);
+        if (!state->metadata_validated && !validate_tensor(*state))
+            continue;
+        auto* destination = ggml_dup_tensor(file->context.get(), tensor);
+        ggml_set_name(destination, tensor->name);
+        auto target    = read_target(*state, destination);
+        const auto key = std::make_tuple(target.loader, target.file, target.version);
+        auto reader    = readers.find(key);
+        if (reader == readers.end()) {
+            auto snapshot = target.file ? target.loader->file_reader(target.file, target.version) : *target.loader;
+            snapshot.set_n_threads(1);
+            if (sd::active_file_access.callback) {
+                for (const auto& dependency : snapshot.dependencies(false)) {
+                    if (authorized_paths.insert(dependency.path).second)
+                        sd::require_file_access(dependency.path, SD_DGL_FILE_READ_MODEL);
+                }
+            }
+            reader = readers.emplace(key, std::move(snapshot)).first;
         }
+        target.loader = &reader->second;
+        target.file   = 0;
+        // A whole-file mmap hint can read beyond the selected batch.
+        target.use_mmap = false;
+        sources.push_back(state->sources);
+        target.sources = &sources.back();
+        // The background reader owns its file handles and conversion scratch.
+        targets.push_back(std::move(target));
         states.push_back(state);
+        file->tensors.emplace(state, destination);
+        scratch = std::max(scratch, file_prefetch_scratch(*state));
     }
-    if (states.empty()) {
-        return needs_synchronous_load ? WeightPrefetchResult::Unsupported
-                                      : WeightPrefetchResult::AlreadyResident;
-    }
-    if (compute_backend == nullptr || sd_backend_is_cpu(compute_backend)) {
-        return WeightPrefetchResult::Unsupported;
-    }
-    ggml_backend_dev_t compute_device = ggml_backend_get_device(compute_backend);
-    ggml_backend_dev_props compute_props{};
-    if (compute_device == nullptr) {
-        return WeightPrefetchResult::Unsupported;
-    }
-    ggml_backend_dev_get_props(compute_device, &compute_props);
-    if (!compute_props.caps.async) {
-        return WeightPrefetchResult::Unsupported;
+    if (targets.empty())
+        return nullptr;
+
+    const auto backend    = states.front()->compute_backend;
+    const auto device     = ggml_backend_get_device(backend);
+    const auto pinned     = device ? sd_backend_dev_host_buffer_type(device) : nullptr;
+    const auto cpu_type   = ggml_backend_cpu_buffer_type();
+    const auto host_bytes = [&](ggml_backend_buffer_type_t type) {
+        size_t bytes = 0;
+        for (const auto& target : targets) {
+            const size_t size = GGML_PAD(ggml_backend_buft_get_alloc_size(type, target.destination),
+                                         ggml_backend_buft_get_alignment(type));
+            bytes += std::min(size, SIZE_MAX - bytes);
+        }
+        return bytes;
+    };
+    size_t available         = 0;
+    const auto allocate_host = [&](ggml_backend_buffer_type_t type) {
+        const size_t bytes = host_bytes(type);
+        if (scratch > MAX_FILE_PREFETCH_BYTES || bytes > MAX_FILE_PREFETCH_BYTES - scratch ||
+            !fits_host_capacity(bytes + scratch, true, 0, available))
+            return false;
+        file->host.reset(ggml_backend_alloc_ctx_tensors_from_buft(file->context.get(), type));
+        if (file->host)
+            return true;
+        // A failed multi-buffer allocation can leave bindings to freed partial allocations.
+        for (const auto& target : targets) {
+            target.destination->buffer = nullptr;
+            target.destination->data   = nullptr;
+            target.destination->extra  = nullptr;
+        }
+        return false;
+    };
+    if ((!info.async_file_upload || !pinned || !allocate_host(pinned)) && !allocate_host(cpu_type))
+        return nullptr;
+    file->scratch_bytes = scratch;
+
+    std::vector<sd::weights::WeightTransfer::Copy> copies;
+    if (info.async_file_upload && ggml_backend_buffer_get_type(file->host.get()) == pinned) {
+        std::vector<TensorState*> upload;
+        for (auto* state : states) {
+            if (file_prefetch_can_bind_compute(*state))
+                upload.push_back(state);
+        }
+        if (!upload.empty()) {
+            size_t commit = 0;
+#ifdef _WIN32
+            if (sd_backend_is(backend, "CUDA"))
+                commit = compute_backend_alloc_size(upload, true);
+#endif
+            if (fits_host_capacity(scratch, true, commit, available)) {
+                file->transfer.queue = file_transfer_.queue_for(backend);
+                if (file->transfer.queue)
+                    file->device = allocate_prefetch_chunk(backend, upload);
+            }
+        }
+        if (file->device) {
+            copies.reserve(file->device->staged_tensors.size());
+            for (const auto& [state, destination] : file->device->staged_tensors)
+                copies.push_back({file->tensors.at(state), nullptr, destination});
+        }
     }
+
+    const bool restrict_access = sd::active_file_access.callback != nullptr;
+    auto read                  = [this, job = file.get(), readers = std::move(readers), sources = std::move(sources),
+                                  targets = std::move(targets), paths = std::move(authorized_paths), restrict_access,
+                                  copies = std::move(copies)]() mutable {
+        // Only the execution thread calls the application policy. The worker checks those paths.
+        const sd::FileAccessPolicy authorized{
+            [](const char* path, sd_dgl_file_access_t access, void* data) {
+                return access == SD_DGL_FILE_READ_MODEL && static_cast<const std::set<std::string>*>(data)->count(path) != 0;
+            },
+            &paths,
+        };
+        const sd::FileAccessScope access(restrict_access ? authorized : sd::FileAccessPolicy{});
+        const auto start = ggml_time_us();
+        if (!sd::weights::read_weights(targets, false))
+            return false;
+        LOG_DEBUG("model manager prefetched %.2f MiB from model files in %.2f ms (%zu tensors, %zu early uploads)",
+                  ggml_backend_buffer_get_size(job->host.get()) / (1024.0 * 1024.0),
+                  (ggml_time_us() - start) / 1000.0, targets.size(), copies.size());
+        if (!copies.empty()) {
+            std::lock_guard<std::mutex> lock(file_transfer_mutex_);
+            sd::weights::WeightTransfer::submit_direct(job->transfer, copies);
+        }
+        return true;
+    };
+    file->read = std::async(std::launch::async, std::move(read));
+    return file;
+}
+
+WeightPrefetchResult ModelManager::prepare_prefetch_params(
+    uintptr_t owner_id,
+    const WeightResidencyInfo& info,
+    PrefetchBuffer* prefetch_buffer) {
     clear_prefetched_params(owner_id);
-    std::vector<TensorState*> originals;
-    for (auto* state : states) {
-        if (merged.count(state) == 0)
-            originals.push_back(state);
+    auto block = std::make_unique<PrefetchBlock>();
+    for (auto* tensor : info.upload_params) {
+        auto* state            = store_.tensor_index().at(tensor);
+        block->compute_backend = state->compute_backend;
+        block->states.push_back(state);
+        if (reusable_lora_weight(*state))
+            block->merged.emplace(state, state->cached_lora());
     }
-    if (!load_tensors_to_params_backend(originals)) {
-        return WeightPrefetchResult::Failed;
+    bool submit_after_compute = false;
+    if (!block->states.empty()) {
+        if (!populate_prefetch_block(*block, prefetch_buffer)) {
+            free_prefetch_block(*block);
+            block->states.clear();
+            block->merged.clear();
+        } else if (sd_backend_is(block->compute_backend, "Vulkan")) {
+            const auto type      = sd_backend_dev_host_buffer_type(ggml_backend_get_device(block->compute_backend));
+            submit_after_compute = std::any_of(block->states.begin(), block->states.end(), [&](const auto* state) {
+                return sd::weights::WeightTransfer::needs_vulkan_staging(*prefetch_source(*block, *state), type);
+            });
+        }
     }
-
-    auto block             = std::make_unique<PrefetchBlock>();
-    block->states          = std::move(states);
-    block->compute_backend = compute_backend;
-    block->merged          = std::move(merged);
-    if (!populate_prefetch_block(*block, prefetch_buffer)) {
-        free_prefetch_block(*block);
-        return WeightPrefetchResult::Failed;
+    try {
+        block->file = prepare_file_prefetch(info);
+    } catch (const std::exception& error) {
+        LOG_DEBUG("model manager skipped file prefetch: %s", error.what());
     }
-    bool submit_after_compute = false;
-    if (sd_backend_is(compute_backend, "Vulkan")) {
-        const auto host_type = sd_backend_dev_host_buffer_type(compute_device);
-        submit_after_compute = std::any_of(block->states.begin(), block->states.end(), [&](const auto* state) {
-            return sd::weights::WeightTransfer::needs_vulkan_staging(*prefetch_source(*block, *state), host_type);
-        });
+    if (block->file) {
+        for (const auto& [state, _] : block->file->tensors)
+            block->states.push_back(state);
     }
+    if (block->states.empty())
+        return WeightPrefetchResult::Unsupported;
     prefetch_blocks_[owner_id] = std::move(block);
     return submit_after_compute ? WeightPrefetchResult::ScheduledAfterCompute : WeightPrefetchResult::Scheduled;
 }

-bool ModelManager::activate_prefetched_params(
-    uintptr_t owner_id,
-    const std::vector<ggml_tensor*>& tensors) {
-    std::vector<TensorState*> required_states;
-    if (!resolve_required_tensor_states(tensors, required_states)) {
-        return false;
-    }
-
-    const bool already_staged = std::all_of(
-        required_states.begin(),
-        required_states.end(),
-        [&](TensorState* state) {
-            if (state == nullptr || should_ignore(*state) || is_optional_missing_tensor(state->name) || state->staged())
-                return true;
-            if (reusable_lora_weight(*state))
-                return false;
-            return has_lora_int8_pair(*state) ||
-                   state->param_source() == ParamSource::ModelFile ||
-                   state->usage_op == GGML_OP_CUSTOM ||
-                   state->compute_backend == state->params_backend();
-        });
-    if (already_staged) {
-        clear_prefetched_params(owner_id);
-        return true;
+bool ModelManager::wait_file_prefetch(FilePrefetch& file) {
+    const auto start = ggml_time_us();
+    try {
+        file.ready = file.read.get();
+    } catch (const std::exception& error) {
+        LOG_DEBUG("model manager file prefetch failed: %s", error.what());
     }
+    sd::weights::WeightTransfer::wait(file.transfer);
+    file.scratch_bytes = 0;
+    LOG_DEBUG("model manager waited %.2f ms for file prefetch", (ggml_time_us() - start) / 1000.0);
+    return file.ready;
+}

+void ModelManager::activate_prefetched_params(uintptr_t owner_id) {
     auto existing = prefetch_blocks_.find(owner_id);
-    if (existing == prefetch_blocks_.end()) {
-        return false;
-    }
+    if (existing == prefetch_blocks_.end())
+        return;
     submit_prefetched_params(owner_id);
-    std::unique_ptr<PrefetchBlock> block = std::move(existing->second);
-    prefetch_blocks_.erase(existing);
-    sd::weights::WeightTransfer::wait(block->transfer);
+    auto& block = *existing->second;
+    sd::weights::WeightTransfer::wait(block.transfer);

-    for (const auto& staging_block : block->staging_blocks) {
-        if (staging_block == nullptr) {
-            continue;
-        }
-        for (const auto& pair : staging_block->staged_tensors) {
-            TensorState* state          = pair.first;
-            ggml_tensor* staging_tensor = pair.second;
-            const auto source           = block->source_epochs.find(state);
-            const bool stale            = source != block->source_epochs.end() &&
-                                          source->second != (state->loaded() ? state->storage_epoch() : UINT64_MAX);
-            if (state == nullptr || state->tensor == nullptr || staging_tensor == nullptr ||
-                state->staged() || state->pin_count() > 0 || stale) {
-                free_prefetch_block(*block);
+    const uint64_t use_epoch = ++residency_epoch_;
+    const auto can_bind      = [&](const ComputeStagingBlock& staging, bool from_file) {
+        return std::all_of(staging.staged_tensors.begin(), staging.staged_tensors.end(), [&](const auto& pair) {
+            const auto* state = pair.first;
+            if (state->staged() || state->pin_count() || !state->tensor)
                 return false;
+            if (from_file)
+                return !state->loaded() && file_prefetch_can_bind_compute(*state);
+            if (const auto merged = block.merged.find(state); merged != block.merged.end())
+                return reusable_lora_weight(*state) == merged->second.get();
+            const auto source = block.source_epochs.find(state);
+            return source != block.source_epochs.end() && state->loaded() && source->second == state->storage_epoch();
+        });
+    };
+    const auto bind = [&](std::unique_ptr<ComputeStagingBlock>& staging, bool from_file) {
+        std::vector<uint64_t> epochs;
+        epochs.reserve(staging->staged_tensors.size());
+        for (auto& [state, tensor] : staging->staged_tensors) {
+            auto epoch = UINT64_MAX;
+            if (!from_file) {
+                const auto merged = block.merged.find(state);
+                epoch             = merged != block.merged.end() ? merged->second->lora_epoch : state->storage_epoch();
             }
+            epochs.push_back(epoch);
+            std::swap(state->tensor->buffer, tensor->buffer);
+            std::swap(state->tensor->data, tensor->data);
+            std::swap(state->tensor->extra, tensor->extra);
+            state->last_use_epoch = use_epoch;
         }
+        store_.add_compute(std::move(staging), epochs);
+    };
+    // Validate the RAM batch together so an INT8 weight and its scale activate together.
+    const bool all_ram_current = std::all_of(block.staging_blocks.begin(), block.staging_blocks.end(), [&](const auto& staging) {
+        return can_bind(*staging, false);
+    });
+    for (auto& staging : block.staging_blocks) {
+        if (all_ram_current)
+            bind(staging, false);
+        else
+            free_prefetch_staging(*staging);
     }
-    const uint64_t use_epoch = ++residency_epoch_;
-    for (auto& staging_block : block->staging_blocks) {
-        if (staging_block == nullptr) {
-            continue;
+    block.staging_blocks.clear();
+    block.merged.clear();
+    block.source_epochs.clear();
+    block.states.clear();
+
+    if (block.file) {
+        if (!wait_file_prefetch(*block.file)) {
+            block.file.reset();
+        } else {
+            if (block.file->device) {
+                if (can_bind(*block.file->device, true)) {
+                    for (const auto& [state, _] : block.file->device->staged_tensors)
+                        block.file->tensors.erase(state);
+                    bind(block.file->device, true);
+                } else {
+                    free_prefetch_staging(*block.file->device);
+                    block.file->device.reset();
+                }
+            }
+            if (block.file->tensors.empty())
+                block.file.reset();
+            else
+                for (const auto& [state, _] : block.file->tensors)
+                    block.states.push_back(state);
         }
-        // An uploaded copy carries the merge of its source.
-        std::vector<uint64_t> epochs;
-        for (auto& pair : staging_block->staged_tensors) {
-            TensorState* state          = pair.first;
-            ggml_tensor* staging_tensor = pair.second;
-            std::swap(state->tensor->buffer, staging_tensor->buffer);
-            std::swap(state->tensor->data, staging_tensor->data);
-            std::swap(state->tensor->extra, staging_tensor->extra);
-            const auto merged = block->merged.find(state);
-            const auto source = block->source_epochs.find(state);
-            epochs.push_back(merged != block->merged.end()          ? merged->second->lora_epoch
-                             : source != block->source_epochs.end() ? source->second
-                             : state->loaded()                      ? state->storage_epoch()
-                                                                    : UINT64_MAX);
-            state->last_use_epoch = use_epoch;
+    }
+    if (!block.file)
+        prefetch_blocks_.erase(existing);
+}
+
+const ggml_tensor* ModelManager::prefetched_file_tensor(uintptr_t owner, TensorState& state) const {
+    if (!owner)
+        return nullptr;
+    const auto block = prefetch_blocks_.find(owner);
+    if (block == prefetch_blocks_.end() || !block->second->file || !block->second->file->ready)
+        return nullptr;
+    const auto& tensors = block->second->file->tensors;
+    const auto source   = tensors.find(&state);
+    return source == tensors.end() ? nullptr : source->second;
+}
+
+bool ModelManager::fits_host_capacity_after_prefetch_reclaim(size_t pending, bool weight_allocation,
+                                                            size_t pending_device_commit, size_t& available) {
+    if (fits_host_capacity(pending, weight_allocation, pending_device_commit, available))
+        return true;
+
+    // Activation has joined these readers and transferred any ready device copies to the store.
+    // Remaining host data is speculative and may yield to normal weight preparation.
+    for (auto it = prefetch_blocks_.begin(); it != prefetch_blocks_.end();) {
+        const auto& file = it->second->file;
+        if (!file || !file->ready) {
+            ++it;
+            continue;
         }
-        store_.add_compute(std::move(staging_block), epochs);
+        free_prefetch_block(*it->second);
+        it = prefetch_blocks_.erase(it);
+        if (fits_host_capacity(pending, weight_allocation, pending_device_commit, available))
+            return true;
     }
-    block->staging_blocks.clear();
-    return true;
+    return false;
 }

 void ModelManager::clear_prefetched_params(uintptr_t owner_id) {
@@ -400,4 +613,5 @@ void ModelManager::clear_all_prefetched_params() {
 void ModelManager::release_prefetch() {
     clear_all_prefetched_params();
     transfer_.release();
+    file_transfer_.release();
 }
diff --git a/src/model_manager_prepare.cpp b/src/model_manager_prepare.cpp
index 249a295..bd35b00 100644
--- a/src/model_manager_prepare.cpp
+++ b/src/model_manager_prepare.cpp
@@ -15,7 +15,7 @@
 // copies and commits them. Allocation, reading, leases, merges and rollback share one lifecycle,
 // so the flow and its intermediate state stay inside ModelManager.

-bool ModelManager::prepare_params(const std::vector<ggml_tensor*>& tensors) {
+bool ModelManager::prepare_params(const std::vector<ggml_tensor*>& tensors, uintptr_t prefetch_owner) {
     if (tensors.empty())
         return true;
     std::vector<TensorState*> states;
@@ -77,7 +77,10 @@ bool ModelManager::prepare_params(const std::vector<ggml_tensor*>& tensors) {

     // Readable copies of every weight. Merged copies are as large as their originals, so when
     // these do not fit, merging in batches would not fit at the end either.
-    if (!ensure_copies(states)) {
+    const bool copies_ready = ensure_copies(states, nullptr, prefetch_owner);
+    if (prefetch_owner)
+        clear_prefetched_params(prefetch_owner);
+    if (!copies_ready) {
         release_unprepared(states);
         return false;
     }
@@ -308,13 +311,13 @@ bool ModelManager::ready_for_compute(const TensorState& state) const {
             (state.param_source() == ParamSource::Backend && state.compute_backend == state.params_backend()));
 }

-bool ModelManager::ensure_copies(const std::vector<TensorState*>& states, bool* capacity_failure) {
+bool ModelManager::ensure_copies(const std::vector<TensorState*>& states, bool* capacity_failure, uintptr_t prefetch_owner) {
     // Reclaims made for these weights may release some of them (reload bytes in the plan), so
     // loading repeats until a pass leaves every weight in place.
     for (int pass = 0; pass < 3; ++pass) {
         bool load_capacity = false, staging_capacity = false;
-        if (!load_tensors_to_params_backend(states, capacity_failure ? &load_capacity : nullptr) ||
-            !stage_tensors_to_compute_backend(states, staging_capacity) || !ensure_host_capacity(0, states)) {
+        if (!load_tensors_to_params_backend(states, capacity_failure ? &load_capacity : nullptr, prefetch_owner) ||
+            !stage_tensors_to_compute_backend(states, staging_capacity, prefetch_owner) || !ensure_host_capacity(0, states)) {
             if (capacity_failure)
                 *capacity_failure = load_capacity || staging_capacity;
             return false;
diff --git a/src/weights/weight_reader.cpp b/src/weights/weight_reader.cpp
index 7fd581f..bc0dcc5 100644
--- a/src/weights/weight_reader.cpp
+++ b/src/weights/weight_reader.cpp
@@ -35,7 +35,8 @@ namespace sd::weights {
             for (auto& entry : batch) {
                 auto* first = entry.second.front();
                 for (auto* tensor : entry.second) {
-                    if (tensor != first)
+                    // File mappings already contain the weight and may be read-only.
+                    if (tensor != first && !loader->is_mmap_buffer(tensor->buffer))
                         ggml_backend_tensor_copy(first, tensor);
                 }
             }
@@ -72,7 +73,7 @@ namespace sd::weights {
         }
     }

-    bool read_weights(const std::vector<ReadTarget>& targets) {
+    bool read_weights(const std::vector<ReadTarget>& targets, bool log_progress) {
         std::map<ReadGroup, std::vector<ReadBatch>> groups;
         size_t part_count = 0;
         for (const auto& target : targets) {
@@ -127,7 +128,7 @@ namespace sd::weights {
         }
         for (auto& [group, batches] : groups) {
             for (auto& batch : batches) {
-                if (!read_batch(group, batch, true))
+                if (!read_batch(group, batch, log_progress))
                     return false;
             }
         }
diff --git a/src/weights/weight_reader.h b/src/weights/weight_reader.h
index 6551849..5f89724 100644
--- a/src/weights/weight_reader.h
+++ b/src/weights/weight_reader.h
@@ -25,7 +25,7 @@ namespace sd::weights {

     // Reads all targets, batching reads per file. Destinations with the same source receive the
     // same data from one read.
-    bool read_weights(const std::vector<ReadTarget>& targets);
+    bool read_weights(const std::vector<ReadTarget>& targets, bool log_progress = true);

     // Maps file-backed tensors in place; returns the mappings that keep them valid.
     std::vector<MmapTensorStore> map_weights(ModelLoader& loader,
diff --git a/src/weights/weight_transfer.cpp b/src/weights/weight_transfer.cpp
index 6a55213..7d54ae7 100644
--- a/src/weights/weight_transfer.cpp
+++ b/src/weights/weight_transfer.cpp
@@ -126,12 +126,23 @@ namespace sd::weights {
     void WeightTransfer::submit(PendingTransfer& pending, const std::vector<Copy>& copies) {
         if (pending.submitted || pending.queue == nullptr)
             return;
-        pending.submitted = true;
-        if (sd_backend_is(pending.queue, "Vulkan") && submit_vulkan_staged(pending, copies))
+        if (sd_backend_is(pending.queue, "Vulkan") && submit_vulkan_staged(pending, copies)) {
+            pending.submitted = true;
             return;
+        }
+        submit_direct(pending, copies);
+    }
+
+    void WeightTransfer::submit_direct(PendingTransfer& pending, const std::vector<Copy>& copies) {
+        pending.submitted = true;
+        // CUDA selects the queue's device when it creates the event, including on a reader thread.
+        const auto event = ggml_backend_event_new(ggml_backend_get_device(pending.queue));
+        if (event != nullptr)
+            pending.event = TransferEvent(event, ggml_backend_event_free);
         for (const auto& copy : copies)
             submit_copy(pending.queue, copy);
-        pending.event = record_event(pending.queue);
+        if (pending.event)
+            ggml_backend_event_record(pending.event.get(), pending.queue);
     }

     void WeightTransfer::wait(PendingTransfer& pending) {
diff --git a/src/weights/weight_transfer.h b/src/weights/weight_transfer.h
index 245df96..40b1266 100644
--- a/src/weights/weight_transfer.h
+++ b/src/weights/weight_transfer.h
@@ -40,6 +40,7 @@ namespace sd::weights {
         static bool needs_vulkan_staging(const ggml_tensor& source, ggml_backend_buffer_type_t host_type);
         // Queues the copies on pending.queue and records their completion.
         void submit(PendingTransfer& pending, const std::vector<Copy>& copies);
+        static void submit_direct(PendingTransfer& pending, const std::vector<Copy>& copies);
         // Waits for submitted copies; pending can be reused afterwards.
         static void wait(PendingTransfer& pending);
         void release();