Skip to content

error_mode

MRFI error mode methods, i.e. fault injectors

A error_mode callback function recieve a fixed argument x_in, and other arguments specified by config, then return a tensor with values after fault inject. DO NOT modify data in tensor x_in.

x_in is a 1-d tensor contains values selected by selector. The return fault injected tensor should have same shape and type as x_in.

Tip

The fault injection are implemented by pytorch functions, so they are both suitable on CPUs and GPUs.

Use fi_model = MRFI(NNModel().cuda(), configs) and use cuda tensor can automatically perform error injection on GPU.

Note
  • Integer fault injectors usually REQUIRES quantization.
  • Float bit flip injectors usually NOT use quantization.

IntSignBitFlip(x_in, bit_width)

Flip integer tensor on sign bit

Parameters:

Name Type Description Default
bit_width int

bit width of quantized value.

required

IntRandomBitFlip(x_in, bit_width)

Flip integer tensor on random bit

Parameters:

Name Type Description Default
bit_width int

bit width of quantized value.

required

IntFixedBitFlip(x_in, bit_width, bit)

Flip integer tensor on specified bit

if bit is a list, it should have same length as x_in. Can cooperate with a fixed number selector.

Parameters:

Name Type Description Default
bit_width int

bit width of quantized value.

required
bit Union[int, Sized]

If bit is an integer 0<=bit<bit_width, flip on fixed bit.

If bit is a list of integer, the list should have the same length as selected tensor values. Then this function flip each corresponding bit.

required

SetZero(x)

Fault inject selected value to zero

SetValue(x, value)

Fault inject value to specified value(s)

if value is a list, it should have same length as input. Can cooperate with a fixed number selector.

Parameters:

Name Type Description Default
value Union[int, float, Sized]

If value is an scalar value(i.e. int, float), set selected tensor to value.

If value is a list, the list should have the same length as selected tensor values. Then this function set selected value according to the list.

required

FloatRandomBitFlip(x_in, floattype=None)

Flip bit randomly on float values

Flip random bit when regards the values as IEEE-754 float type.

Parameters:

Name Type Description Default
floattype Optional[Union[np.float16, np.float32, np.float64]]

Should be one of "float16", "float32", "float64". if None, use the input tensor type, usually is "float32".

None

FloatFixedBitFlip(x_in, bit, floattype=None)

Flip specific bit on float values

Flip specified bit when regards the values as IEEE-754 float type.

Parameters:

Name Type Description Default
bit Union[int, Sized]

If bit is an integer 0 <= bit < float bits, flip on fixed bit.

If bit is a list of integer, the list should have the same length as selected tensor values. Then this function flip each corresponding bit.

required
floattype Optional[Union[np.float16, np.float32, np.float64]]

Should be one of "float16", "float32", "float64". if None, use the input tensor type, usually is "float32".

None

IntRandom(x_in, low=0, high=128)

Uniformly set to random integer in range.

Set fault injection value to integer in range [low, high) with uniform probability.

Parameters:

Name Type Description Default
low int

Minimum range, included.

0
high int

Maximum range, excluded.

128

IntRandomBit(x_in, bit_width=8, signed=False)

Set fault value to a random bit_width-bit integer.

If unsigned, randomly set to [0, 2**bit_width). If signed, randomly set to [-2**(bit_width-1), 2**(bit_width-1)).

Parameters:

Name Type Description Default
bit_width int

Width of target value.

8
signed bool

Signed range.

False

UniformRandom(x_in, low=-1, high=1)

Uniform set to float number in range.

Set fault injection value to float number in [low, high] with uniform probability.

Parameters:

Name Type Description Default
low float

Minimum range.

-1
high float

Maximum range.

1

NormalRandom(x_in, mean=0, std=1)

Set fault injection value to a normal distribution.

Set fault injection value to a normal distribution with specified mean, std. i.e. $ X ~ Normal(mean, std^2) $.

Parameters:

Name Type Description Default
mean float

Distribution mean.

0
std float

Distribution standard deviation.

1

UniformDisturb(x_in, low=-1, high=1)

Add uniform distribution noise to current value.

Add uniform distribution noise in range [low, high] to current value.

Parameters:

Name Type Description Default
low float

Minimum noise range.

-1
high float

Maximum noise range.

1

NormalDisturb(x_in, std=1, bias=0)

Add normal distribution noise to current value.

Add a normal distribution with specified std, bias. i.e. $ x_{out}=x_{in} + X + bias, X ~ Normal(0, std^2) $.

Parameters:

Name Type Description Default
std float

Distribution mean.

1
bias float

Extra noise bias.

0