mindinsight.lineagemgr
Lineagemgr Module Introduction.
This module provides Python APIs to collect and query the lineage of models.Users can add the TrainLineage/EvalLineage callback to the MindSpore train/eval callback list tocollect the key parameters and results, such as, the name of the network and optimizer, theevaluation metric and results.The APIs can be used to get the lineage information of the models. For example,what hyperparameter is used in the model training, which model has the highestaccuracy among all the versions, etc.
- class
mindinsight.lineagemgr.
TrainLineage
(summary_record, raise_exception=False)[source] Collect lineage of a training job.
- Parameters
summary_record (SummaryRecord) – SummaryRecord is used to recordthe summary value, and summary_record is an instance of SummaryRecord,see mindspore.train.summary.SummaryRecord.
raise_exception (bool) – Whether to raise exception when error occurs inTrainLineage. If True, raise exception. If False, catch exceptionand continue. Default: False.
Raises
MindInsightException – If validating parameter fails.
LineageLogError – If recording lineage information fails.
Examples
- Copy>>> from mindinsight.lineagemgr import TrainLineage
- >>> from mindspore.train.callback import ModelCheckpoint, SummaryStep
- >>> from mindspore.train.summary import SummaryRecord
- >>> model = Model(train_network)
- >>> model_ckpt = ModelCheckpoint(directory='/dir/to/save/model/')
- >>> summary_writer = SummaryRecord(log_dir='./')
- >>> summary_callback = SummaryStep(summary_writer, flush_step=2)
- >>> lineagemgr = TrainLineage(summary_record=summary_writer)
- >>> model.train(epoch_num, dataset, callbacks=[model_ckpt, summary_callback, lineagemgr])
begin
(run_context)[source]Initialize the training progress when the training job begins.
- Parameters
run_context (RunContext) – It contains all lineage information,see mindspore.train.callback.RunContext.
Raises
- MindInsightException – If validating parameter fails.
end
(run_context)[source]Collect lineage information when the training job ends.
- Parameters
run_context (RunContext) – It contains all lineage information,see mindspore.train.callback.RunContext.
Raises
- LineageLogError – If recording lineage information fails.
- class
mindinsight.lineagemgr.
EvalLineage
(summary_record, raise_exception=False)[source] Collect lineage of an evaluation job.
- Parameters
summary_record (SummaryRecord) – SummaryRecord is used to recordthe summary value, and summary_record is an instance of SummaryRecord,see mindspore.train.summary.SummaryRecord.
raise_exception (bool) – Whether to raise exception when error occurs inEvalLineage. If True, raise exception. If False, catch exceptionand continue. Default: False.
Raises
MindInsightException – If validating parameter fails.
LineageLogError – If recording lineage information fails.
Examples
- Copy>>> from mindinsight.lineagemgr import EvalLineage
- >>> from mindspore.train.callback import ModelCheckpoint, SummaryStep
- >>> from mindspore.train.summary import SummaryRecord
- >>> model = Model(train_network)
- >>> model_ckpt = ModelCheckpoint(directory='/dir/to/save/model/')
- >>> summary_writer = SummaryRecord(log_dir='./')
- >>> summary_callback = SummaryStep(summary_writer, flush_step=2)
- >>> lineagemgr = EvalLineage(summary_record=summary_writer)
- >>> model.eval(epoch_num, dataset, callbacks=[model_ckpt, summary_callback, lineagemgr])
end
(run_context)[source]Collect lineage information when the training job ends.
- Parameters
run_context (RunContext) – It contains all lineage information,see mindspore.train.callback.RunContext.
Raises
MindInsightException – If validating parameter fails.
LineageLogError – If recording lineage information fails.
mindinsight.lineagemgr.
getsummary_lineage
(_summary_dir, keys=None)[source]- Get the lineage information according to summary directory and keys.
The function queries lineage information of single train processcorresponding to the given summary directory. Users can query theinformation according to keys.
- Parameters
summary_dir (str) – The summary directory. It contains summary logs forone training.
keys (list[str]) – The filter keys of lineage information. The acceptablekeys are metric, hyper_parameters, algorithm, train_dataset,model, valid_dataset and dataset_graph. If it is None, allinformation will be returned. Default: None.
Returns
dict, the lineage information for one training.
Raises
LineageParamSummaryPathError – If summary path is invalid.
LineageQuerySummaryDataError – If querying summary data fails.
LineageFileNotFoundError – If the summary log file is not found.
Examples
- Copy>>> summary_dir = "/path/to/summary"
- >>> summary_lineage_info = get_summary_lineage(summary_dir)
- >>> hyper_parameters = get_summary_lineage(summary_dir, keys=["hyper_parameters"])
mindinsight.lineagemgr.
filtersummary_lineage
(_summary_base_dir, search_condition=None)[source]- Filter the lineage information under summary base directory according to search condition.
Users can filter and sort all lineage information according to the searchcondition. The supported filter fields include summary_dir, network,etc. The filter conditions include eq, lt, gt, le, ge and in.At the same time, the combined use of these fields and conditions issupported. If you want to sort based on filter fields, the field ofsorted_name and sorted_type should be specified.
Users can use lineage_type to decide what kind of lineage information toquery. If the lineage_type is dataset, the query result is only thelineage information related to data augmentation. If the lineage_type ismodel or None, the query result is all lineage information.
Users can paginate query result based on offset and limit. The offset_refers to page number. The _limit refers to the number in one page.
- Parameters
The search condition. When filtering andsorting, in addition to the following supported fields, fieldsprefixed with metric are also supported. The fields prefixed with_metric are related to the _metrics parameter in the trainingscript. For example, if the key of metrics parameter isaccuracy, the field should be metric_accuracy. Default: None.
-
summary_dir (dict): The filter condition of summary directory.
-
loss_function (dict): The filter condition of loss function.
-
train_dataset_path (dict): The filter condition of train dataset path.
-
train_dataset_count (dict): The filter condition of train dataset count.
-
test_dataset_path (dict): The filter condition of test dataset path.
-
test_dataset_count (dict): The filter condition of test dataset count.
-
network (dict): The filter condition of network.
-
optimizer (dict): The filter condition of optimizer.
-
learning_rate (dict): The filter condition of learning rate.
-
epoch (dict): The filter condition of epoch.
-
batch_size (dict): The filter condition of batch size.
-
loss (dict): The filter condition of loss.
-
model_size (dict): The filter condition of model size.
-
dataset_mark (dict): The filter condition of dataset mark.
-
offset (int): Page number, the value range is [0, 100000].
-
limit (int): The number in one page, the value range is [1, 100].
-
sorted_name (str): Specify which field to sort by.
-
sortedtype (str): Specify sort order. It can be _ascending ordescending.
-
lineagetype (str): It decides what kind of lineage information toquery. It can be _dataset or model. If it is dataset,the query result is only the lineage information related to dataaugmentation. If it is model or None, the query result is alllineage information.
- Returns
dict, all lineage information under summary base directory according tosearch condition.
Raises
LineageSearchConditionParamError – If search_condition param is invalid.
LineageParamSummaryPathError – If summary path is invalid.
LineageFileNotFoundError – If the summary log file is not found.
LineageQuerySummaryDataError – If querying summary log file data fails.
Examples
- Copy>>> summary_base_dir = "/path/to/summary_base"
- >>> search_condition = {
- >>> 'summary_dir': {
- >>> 'in': [
- >>> os.path.join(summary_base_dir, 'summary_1'),
- >>> os.path.join(summary_base_dir, 'summary_2'),
- >>> os.path.join(summary_base_dir, 'summary_3')
- >>> ]
- >>> },
- >>> 'loss': {
- >>> 'gt': 2.0
- >>> },
- >>> 'batch_size': {
- >>> 'ge': 128,
- >>> 'le': 256
- >>> },
- >>> 'metric_accuracy': {
- >>> 'lt': 0.1
- >>> },
- >>> 'sorted_name': 'summary_dir',
- >>> 'sorted_type': 'descending',
- >>> 'limit': 3,
- >>> 'offset': 0,
- >>> 'lineage_type': 'model'
- >>> }
- >>> summary_lineage = filter_summary_lineage(summary_base_dir)
- >>> summary_lineage_filter = filter_summary_lineage(summary_base_dir, search_condition)