6 #ifndef DISMEC_MODEL_IO_H
7 #define DISMEC_MODEL_IO_H
17 #include <boost/iterator/iterator_adaptor.hpp>
94 using std::filesystem::path;
128 void save_model(
const path& target_file,
const std::shared_ptr<const Model>& model,
SaveOption options);
131 std::shared_ptr<Model>
load_model(path source);
270 std::future<WeightFileEntry>
add_model(
const std::shared_ptr<const Model>& model,
271 const std::optional<std::string>& file_path={});
355 [[nodiscard]] std::shared_ptr<Model>
load_model(
int index)
const;
This class is used as an implementation detail to capture the common code of PartialModelSaver and Pa...
weight_file_iter_t label_lower_bound(label_id_t pos) const
Gets an iterator into the weight-file list that points to the first element whose starting label is l...
~PartialModelIO()=default
void read_metadata_file(const path &meta_file)
void insert_sub_file(const WeightFileEntry &data)
Inserts a new sub-file entry into the metadata object.
std::vector< WeightFileEntry >::const_iterator weight_file_iter_t
std::vector< WeightFileEntry > m_SubFiles
long num_labels() const noexcept
Gets the total number of labels.
long num_features() const noexcept
Gets the total number of features.
This class allows loading only a subset of the weights of a large model.
std::shared_ptr< Model > load_model(label_id_t label_begin, label_id_t label_end) const
Loads part of the model.
long num_weight_files() const
Returns the number of availabel weight files.
bool validate() const
Validates that all weight files exist.
const path & meta_file_path() const
The path to the metadata file.
SubModelRangeSpec get_loading_range(label_id_t label_begin, label_id_t label_end) const
PartialModelLoader(path meta_file, ESparseMode mode=DEFAULT)
Create a new PartialModelLoader for the given metadata file.
Manage saving a model consisting of multiple partial models.
void finalize()
Checks that all weights have been written and updates the metadata file.
PartialModelSaver(path target_file, SaveOption options, bool load_partial=false)
Create a new PartialModelSaver.
bool any_weight_vector_for_interval(label_id_t begin, label_id_t end) const
Checks if there are any weight vectors for the given interval.
std::pair< label_id_t, label_id_t > get_missing_weights() const
Get an interval labels for which weights are missing.
std::future< WeightFileEntry > add_model(const std::shared_ptr< const Model > &model, const std::optional< std::string > &file_path={})
Adds the weights of a partial model asynchronously.
void update_meta_file()
Updates the metadata file.
Strong typedef for an int to signify a label id.
A model combines a set of weight with some meta-information about these weights.
std::shared_ptr< Model > load_model(path source)
WeightFormat parse_weights_format(std::string_view name)
Gets the eighs.
void save_model(const path &target_file, const std::shared_ptr< const Model > &model, SaveOption options)
Saves a complete model to a file.
WeightFormat
Describes the format in which the weight data has been saved.
@ DENSE_TXT
Dense Text Format
@ SPARSE_TXT
Sparse Text Format
@ DENSE_NPY
Dense Numpy Format
const char * to_string(WeightFormat format)
weight_file_iter_t FilesEnd
weight_file_iter_t FilesBegin
WeightFormat Format
Format in which the weights will be saved.
double Culling
If saving in sparse mode, threshold below which weights will be omitted.
int Precision
Precision with which the labels will be saved.
int SplitFiles
Maximum number of weight vectors per file.
Collect the data about a weight file.