DiSMEC++
|
This class allows loading only a subset of the weights of a large model. More...
#include <model-io.h>
Classes | |
struct | SubModelRangeSpec |
Public Types | |
enum | ESparseMode { DEFAULT , FORCE_SPARSE , FORCE_DENSE } |
Public Member Functions | |
PartialModelLoader (path meta_file, ESparseMode mode=DEFAULT) | |
Create a new PartialModelLoader for the given metadata file. More... | |
const path & | meta_file_path () const |
The path to the metadata file. More... | |
std::shared_ptr< Model > | load_model (label_id_t label_begin, label_id_t label_end) const |
Loads part of the model. More... | |
std::shared_ptr< Model > | load_model (int index) const |
Loads the model from the weights file at the given index. More... | |
bool | validate () const |
Validates that all weight files exist. More... | |
long | num_weight_files () const |
Returns the number of availabel weight files. More... | |
SubModelRangeSpec | get_loading_range (label_id_t label_begin, label_id_t label_end) const |
Public Member Functions inherited from dismec::io::model::PartialModelIO | |
long | num_labels () const noexcept |
Gets the total number of labels. More... | |
long | num_features () const noexcept |
Gets the total number of features. More... | |
Private Attributes | |
path | m_MetaFileName |
ESparseMode | m_SparseMode |
Additional Inherited Members | |
Protected Types inherited from dismec::io::model::PartialModelIO | |
using | weight_file_iter_t = std::vector< WeightFileEntry >::const_iterator |
Protected Member Functions inherited from dismec::io::model::PartialModelIO | |
PartialModelIO ()=default | |
~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. More... | |
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 larger than or equal to pos . More... | |
Protected Attributes inherited from dismec::io::model::PartialModelIO | |
long | m_TotalLabels = -1 |
long | m_NumFeatures = -1 |
std::vector< WeightFileEntry > | m_SubFiles |
This class allows loading only a subset of the weights of a large model.
In a setting with an extreme number of labels, it might not be possible to load the entire set of weights into the memory at once.
Definition at line 317 of file model-io.h.
Enumerator | |
---|---|
DEFAULT | |
FORCE_SPARSE | |
FORCE_DENSE |
Definition at line 319 of file model-io.h.
|
explicit |
Create a new PartialModelLoader for the given metadata file.
This operation will only open and parse the metadata file, but no weights will be read in.
meta_file | Path to the metadata file. |
mode | Should the returned models store their weights in a sparse matrix, a dense matrix, or use the representation as given by the weights file (DEFAULT). |
Definition at line 341 of file model-io.cpp.
References m_MetaFileName, and dismec::io::model::PartialModelIO::read_metadata_file().
auto PartialModelLoader::get_loading_range | ( | label_id_t | label_begin, |
label_id_t | label_end | ||
) | const |
Definition at line 346 of file model-io.cpp.
References dismec::io::model::WeightFileEntry::Count, dismec::io::model::WeightFileEntry::First, and dismec::io::model::NULL_FORMAT.
Referenced by load_model().
std::shared_ptr< Model > PartialModelLoader::load_model | ( | int | index | ) | const |
Loads the model from the weights file at the given index.
index | The index of the sub-model to be loaded. |
Definition at line 423 of file model-io.cpp.
References dismec::io::model::WeightFileEntry::Count, dismec::io::model::WeightFileEntry::FileName, dismec::io::model::WeightFileEntry::First, dismec::io::model::WeightFileEntry::Format, m_SparseMode, dismec::io::model::PartialModelIO::m_SubFiles, anonymous_namespace{model-io.cpp}::make_model(), meta_file_path(), dismec::io::model::PartialModelIO::num_features(), dismec::io::model::PartialModelIO::num_labels(), anonymous_namespace{model-io.cpp}::read_weights_dispatch(), THROW_ERROR, and anonymous_namespace{model-io.cpp}::use_sparse_weights().
std::shared_ptr< Model > PartialModelLoader::load_model | ( | label_id_t | label_begin, |
label_id_t | label_end | ||
) | const |
Loads part of the model.
If the desired interval [label_begin, label_end)
does not match directly with the weight files, a model that encompasses more weights will be used. Each weights file which has some overlap with the interval will be loaded entirely.
label_begin | First label whose weight is guaranteed to be part of the returned model. |
label_end | Element id after the last weight vector that is included in the returned model. |
[label_begin, label_end)
. Definition at line 373 of file model-io.cpp.
References get_loading_range(), m_MetaFileName, dismec::io::model::PartialModelIO::m_NumFeatures, dismec::io::model::PartialModelIO::m_TotalLabels, anonymous_namespace{model-io.cpp}::read_weights_dispatch(), and THROW_ERROR.
Referenced by dismec::io::model::load_model(), and main().
|
inline |
The path to the metadata file.
Definition at line 338 of file model-io.h.
References m_MetaFileName.
Referenced by load_model(), and validate().
long PartialModelLoader::num_weight_files | ( | ) | const |
Returns the number of availabel weight files.
Definition at line 395 of file model-io.cpp.
References dismec::io::model::PartialModelIO::m_SubFiles.
Referenced by main().
bool PartialModelLoader::validate | ( | ) | const |
Validates that all weight files exist.
Definition at line 441 of file model-io.cpp.
References dismec::io::model::PartialModelIO::m_SubFiles, and meta_file_path().
Referenced by main().
|
private |
Definition at line 374 of file model-io.h.
Referenced by load_model(), meta_file_path(), and PartialModelLoader().
|
private |
Definition at line 375 of file model-io.h.
Referenced by load_model().