quant : Optimise memory usage by evicting weights after processing each layer (#22877)
* Evict weights from memory after processing each layer * Revert changes * Move unmap to libllama * Unmap weights offloaded to backend * Change member's constness * Remove unmap weights offloaded to backend
This commit is contained in:
@@ -1395,6 +1395,11 @@ void llama_model_loader::get_mapping_range(size_t * first, size_t * last, void *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void llama_model_loader::unmap_weight(const llama_tensor_weight & w) const {
|
||||||
|
if (!use_mmap) { return; }
|
||||||
|
mappings.at(w.idx)->unmap_fragment(w.offs, w.offs + ggml_nbytes(w.tensor));
|
||||||
|
}
|
||||||
|
|
||||||
void llama_model_loader::load_data_for(struct ggml_tensor * cur) const {
|
void llama_model_loader::load_data_for(struct ggml_tensor * cur) const {
|
||||||
const auto & w = require_weight(ggml_get_name(cur));
|
const auto & w = require_weight(ggml_get_name(cur));
|
||||||
|
|
||||||
|
|||||||
@@ -194,6 +194,9 @@ struct llama_model_loader {
|
|||||||
|
|
||||||
void get_mapping_range(size_t * first, size_t * last, void ** addr, int idx, ggml_context * ctx) const;
|
void get_mapping_range(size_t * first, size_t * last, void ** addr, int idx, ggml_context * ctx) const;
|
||||||
|
|
||||||
|
// release a weight's mmap pages
|
||||||
|
void unmap_weight(const llama_tensor_weight & w) const;
|
||||||
|
|
||||||
// for backwards compatibility, does not support ggml-backend
|
// for backwards compatibility, does not support ggml-backend
|
||||||
void load_data_for(struct ggml_tensor * cur) const;
|
void load_data_for(struct ggml_tensor * cur) const;
|
||||||
|
|
||||||
|
|||||||
@@ -1278,6 +1278,10 @@ static void llama_model_quantize_impl(const std::string & fname_inp, const std::
|
|||||||
// write tensor data + padding
|
// write tensor data + padding
|
||||||
fout.write((const char *) new_data, new_size);
|
fout.write((const char *) new_data, new_size);
|
||||||
zeros(fout, GGML_PAD(new_size, align) - new_size);
|
zeros(fout, GGML_PAD(new_size, align) - new_size);
|
||||||
|
|
||||||
|
// unmap the tensor to free memory
|
||||||
|
if (ml.use_mmap) { ml.unmap_weight(weight); }
|
||||||
|
|
||||||
} // no --dry-run
|
} // no --dry-run
|
||||||
} // main loop
|
} // main loop
|
||||||
|
|
||||||
|
|||||||
@@ -2023,7 +2023,6 @@ int llama_perplexity(int argc, char ** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const int32_t n_ctx = params.n_ctx;
|
const int32_t n_ctx = params.n_ctx;
|
||||||
|
|
||||||
if (n_ctx <= 0) {
|
if (n_ctx <= 0) {
|
||||||
LOG_ERR("%s: perplexity tool requires '--ctx-size' > 0\n", __func__);
|
LOG_ERR("%s: perplexity tool requires '--ctx-size' > 0\n", __func__);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user