Skip to content

selector

MRFI selector methods

A selector is a call back function with fixed argument shape, and other optional args specified in config file.

The selector determines which positions of tensor are send to fault injector i.e. error_mode.

Selector returns a 1-d index tensor with type torch.long, indicates the index of target tensor after flatten.

Note

If no selector specified in config file, all target tensor will be sent to fault injector.

EmptySelector(shape)

No position selected by this, for debug or special use.

FixPosition(shape, position)

Select fixed one position by coordinate.

Parameters:

Name Type Description Default
position Union[int, List[int]]

if int, stands for index of target position on flattened tensor.

if List[int], stands for n-d coordinate of target position.

required

FixPositions(shape, positions)

Select a list of fixed positions by coordinate.

Parameters:

Name Type Description Default
positions Union[List[int], List[List[int]]]

if List[int], stands for index of target tensor after flatten.

if List[List[int]], stands for n-d coordinate of target position.

required

RandomPositionByNumber(shape, n=1, per_instance=False)

Select n random positions.

Parameters:

Name Type Description Default
n int

Number of target positions.

1
per_instance bool

if True, perform n inject on per instance (i.e. ignore dim 0).

False

RandomPositionByRate(shape, rate=0.0001, poisson=True)

Select random positions by rate.

This function generate positions by n ~ Possion(N_all * rate).

Parameters:

Name Type Description Default
rate float

Rate of each position to be chosen.

0.0001
poisson bool

Enable poisson samping, which is more accurate when rate is quite small.

True
Info

rate stands for tensor value selected rate here. To calculate the bit error rate on bit flip experiment, it needs to be additionally divided by the bit width.

RandomPositionByRate_classic(shape, rate=0.0001)

Select random positions by rate.

This function generate positions by sampling on all value.

Parameters:

Name Type Description Default
rate float

Rate of each position to be chosen.

0.0001
Deprecated

This function is deprecated and only for test because of low performance.

MaskedDimRandomPositionByNumber(shape, n=1, **kwargs)

Select n positions after specifed dimensions are masked.

Use a list to indicate which values on a certain dimension are not selected.

For a 2-D tensor, it is equivalent to selecting on a submatrix where some rows and cols are masked.

Tip

MaskedDim- and SelectedDim- selectors can be used for fine-grained evaluate and selective protect experiments, including instance-wise, channel-wise and spatial-wise.

Info

Mask argeuments follow common pytorch memory layout:

  • CNN feature map: (instance, channel, height, width)

  • CNN weight: (out_channel, in_channel, height, width)

  • Full connect layer: (instance, neuron)

  • Full connect weight: (out, in)

Parameters:

Name Type Description Default
n int

number of position to select.

1
**kwargs dict

instance(dim = 0), type list[int]

channel(dim = 1), type list[int]

height(dim = 2), type list[int]

width(dim = 3), type list[int]

out_channel(dim = 0), type list[int]

in_channel(dim = 1), type list[int]

out(dim = 0), type list[int]

in(dim = 1), type list[int]

neuron(dim = 1), type list[int]

{}

SelectedDimRandomPositionByNumber(shape, n=1, **kwargs)

Select n positions on selected coordinate.

For argument list, please refer MaskedDimRandomPositionByNumber.

Note if one dimension selection list is not specified, it stands for all of this dimension are possible selected.

MaskedDimRandomPositionByRate(shape, rate, poisson=True, **kwargs)

Select by rate where some coordinate are masked.

For argument list, please refer MaskedDimRandomPositionByNumber.

SelectedDimRandomPositionByRate(shape, rate, poisson=True, **kwargs)

Select on some coordinate by rate.

For argument list, please refer MaskedDimRandomPositionByNumber.

Note if one dimension selection list is not specified, it stands for all of this dimension are possible selected.

FixedPixelByNumber(shape, n, pixel, per_instance=False)

Select n random channel on one fixed pixel.

Pixel is on H * W dimension.

Parameters:

Name Type Description Default
n int

number of positions

required
pixel Union[int, tuple]

An 2-d coordinate tuple specified target pixel

required
per_instance bool

if True, perform n inject on per instance (i.e. ignore dim 0)

False