Skip to content

experiment

logspace_density(low=-8, high=-4, density=3)

Similar as np.logspace but the datapoint always contains 10^{-n}

Parameters:

Name Type Description Default
low int

begin point at 10**low

-8
high int

end point at 10**high

-4
density int

how many data point per 10x range.

3

Returns:

Type Description
np.array

Array of uniformed logspace data point.

Acc_experiment(model, dataloader)

Return classification accuracy on dataset.

Parameters:

Name Type Description Default
model Union[MRFI, torch.nn.Module]

Target model.

required
dataloader DataLoader

Yields a series of tuple of (batched) input images and classification label.

required

Returns:

Type Description
float

Accuracy result among all data, between 0 and 1.

observeFI_experiment(fi_model, input_data, use_golden=True, observers_dict=None)

Run fault inject experiment and return internal oberver results.

Parameters:

Name Type Description Default
fi_model MRFI

Target model.

required
input_data Union[torch.Tensor, DataLoader]

A input tensor or a dataloader.

required
use_golden bool

If True, run both golden run and fault injection per batch, most of fault injection observer requires golden run before fault inject.

True
observers_dict Optional[dict]

A dict of observer config handlers to get result. if None, return all observer result.

None

Returns:

Type Description
dict

Dictionary of observer result, keys are observer name and values are result of observer.result().

BER_Acc_experiment(fi_model, fi_selectors, dataloader, BER_range=logspace_density(), bit_width=16)

Conduct a series of experimet under different bit error rate and get accuracy.

Parameters:

Name Type Description Default
fi_model MRFI

Target model.

required
fi_selectors ConfigItemList

A target selector list from fi_model.get_configs().

required
dataloader DataLoader

Yields a series of tuple of (batched) input images and classification label.

required
BER_range Union[list, np.array]

A list or a array for target bit error rate.

logspace_density()
bit_width int

To calculate bit error rate by tensor value selected rate.

16

Returns:

Type Description
tuple

Current bit error rate list and accuracy result among all data of each bit error list.

BER_observe_experiment(fi_model, fi_selectors, dataloader, BER_range=logspace_density(), bit_width=16, use_golden=True)

Conduct a series of experimet under different bit error rate and get all observers result.

Parameters:

Name Type Description Default
fi_model MRFI

Target model.

required
fi_selectors ConfigItemList

A target selector list from fi_model.get_configs().

required
dataloader DataLoader

Yields a series of tuple of (batched) input images and classification label.

required
BER_range Union[list, np.array]

A list or a array for target bit error rate.

logspace_density()
bit_width int

To calculate bit error rate by tensor value selected rate.

16
use_golden bool

If True, run both golden run and fault injection per batch.

True

Returns:

Type Description
tuple

Current bit error rate list and observation result dictionary list.

Acc_golden(fi_model, dataloader, disable_quantization=False)

Evaluate model accuracy without error injection.

Parameters:

Name Type Description Default
fi_model MRFI

Target model.

required
dataloader torch.utils.data.DataLoader

Yields a series of tuple of (batched) input images and classification label.

required
disable_quantization bool

If True, also disable quantization if it exists. Note that quantization also affects model accuracy.

False

Returns:

Type Description
float

Golden run accuracy result among all data, between 0 and 1.

observeFI_experiment_plus(fi_model, input_data, method='RMSE', pre_hook=False, **kwargs)

Run fault injection experiment and observe its internal effect.

Compare with observeFI_experiment(), this function add temporary target observers of to model.

Parameters:

Name Type Description Default
fi_model MRFI

Target model.

required
input_data Union[torch.Tensor, DataLoader]

A input tensor or a dataloader.

required
method str

Name of the fault injection observer in mrfi.observer.

'RMSE'
pre_hook bool

Observer value in module input, not output.

False
**kwargs dict

Target module to do observe, module_type, module_name or module_fullname

{}

Returns:

Type Description
dict

Dictionary of observer result, keys are observer name and values are result of observer.result().

get_activation_info(fi_model, input_data, method='MinMax', pre_hook=False, **kwargs)

Observe model activations without fault injection.

Parameters:

Name Type Description Default
fi_model MRFI

Target model.

required
input_data Union[torch.Tensor, DataLoader]

A input tensor or a dataloader.

required
method str

Name of the basic observer in mrfi.observer.

'MinMax'
pre_hook bool

Observer value in module input, not output.

False
**kwargs dict

Target module to observe, module_type, module_name or module_fullname

{}

Returns:

Type Description
dict

Dictionary of observer result, keys are activation observation name and values are result of observer.result().

get_weight_info(model, method='MinMax', weight_name='weight', **kwargs)

Observe model weights.

Parameters:

Name Type Description Default
model Union[MRFI, torch.nn.Module]

Target model.

required
method str

Name of the basic observer in mrfi.observer.

'MinMax'
weight_name Union[str, List[str]]

Target weight name.

'weight'
**kwargs dict

Target module to observe, module_type, module_name or module_fullname

{}

Returns:

Type Description
dict

Dictionary of observer result, keys are weight observation and values are result of observer.result().