DiSMEC++
dismec::io::model::PartialModelLoader Class Reference

This class allows loading only a subset of the weights of a large model. More...

#include <model-io.h>

Inheritance diagram for dismec::io::model::PartialModelLoader:
dismec::io::model::PartialModelIO

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< Modelload_model (label_id_t label_begin, label_id_t label_end) const
 Loads part of the model. More...
 
std::shared_ptr< Modelload_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< WeightFileEntrym_SubFiles
 

Detailed Description

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.

Member Enumeration Documentation

◆ ESparseMode

Enumerator
DEFAULT 
FORCE_SPARSE 
FORCE_DENSE 

Definition at line 319 of file model-io.h.

Constructor & Destructor Documentation

◆ PartialModelLoader()

PartialModelLoader::PartialModelLoader ( path  meta_file,
ESparseMode  mode = DEFAULT 
)
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.

Parameters
meta_filePath to the metadata file.
modeShould 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().

Member Function Documentation

◆ get_loading_range()

auto PartialModelLoader::get_loading_range ( label_id_t  label_begin,
label_id_t  label_end 
) const

◆ load_model() [1/2]

◆ load_model() [2/2]

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.

Parameters
label_beginFirst label whose weight is guaranteed to be part of the returned model.
label_endElement id after the last weight vector that is included in the returned model.
Returns
A model that contains weight at least for the interval [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().

◆ meta_file_path()

const path& dismec::io::model::PartialModelLoader::meta_file_path ( ) const
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().

◆ num_weight_files()

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().

◆ validate()

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().

Member Data Documentation

◆ m_MetaFileName

path dismec::io::model::PartialModelLoader::m_MetaFileName
private

Definition at line 374 of file model-io.h.

Referenced by load_model(), meta_file_path(), and PartialModelLoader().

◆ m_SparseMode

ESparseMode dismec::io::model::PartialModelLoader::m_SparseMode
private

Definition at line 375 of file model-io.h.

Referenced by load_model().


The documentation for this class was generated from the following files: