From 081f368133075064cae1181f43744bd92d096ac4 Mon Sep 17 00:00:00 2001 From: anmeza Date: Thu, 14 Nov 2024 11:30:40 -0800 Subject: [PATCH 1/2] Update fmodel.py --- fkeras/fmodel.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fkeras/fmodel.py b/fkeras/fmodel.py index 4c5c56f..b786001 100644 --- a/fkeras/fmodel.py +++ b/fkeras/fmodel.py @@ -15,6 +15,7 @@ "Flatten", "BatchNormalization", "Activation", + "Add", ] From 02042936ef6e7c0f1ce9463a6f5805b041cb8f24 Mon Sep 17 00:00:00 2001 From: anmeza Date: Thu, 14 Nov 2024 12:16:00 -0800 Subject: [PATCH 2/2] Update console messages to only print in verbose mode --- fkeras/fmodel.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/fkeras/fmodel.py b/fkeras/fmodel.py index b786001..dddfb1d 100644 --- a/fkeras/fmodel.py +++ b/fkeras/fmodel.py @@ -20,9 +20,10 @@ class FModel: - def __init__(self, model, model_param_ber=0): + def __init__(self, model, model_param_ber=0, verbose=0): self.model = model self.model_param_ber = model_param_ber + self.verbose = verbose self._set_layer_bit_ranges() self._set_model_param_ber() # self.layer_bit_ranges = {} @@ -72,7 +73,8 @@ def _set_layer_bit_ranges(self): raise NotImplementedError( f"Injecting faults in {layer.__class__.__name__} layer not yet supported." ) - print(f"[fkeras.fmodel._set_layer_bit_ranges] {self.num_model_param_bits}") + if self.verbose > 0: + print(f"[fkeras.fmodel._set_layer_bit_ranges] {self.num_model_param_bits}") def explicit_select_model_param_bitflip(self, bits_to_flip): """ @@ -87,9 +89,11 @@ def explicit_select_model_param_bitflip(self, bits_to_flip): """ bits_to_flip_per_layer = defaultdict(int) # num_faults = int(self.num_model_param_bits * self.model_param_ber) - print( - f"[fkeras.fmodel.explicit_select_model_param_bitflip] num_faults = {len(bits_to_flip)}" - ) + + if self.verbose > 0: + print( + f"[fkeras.fmodel.explicit_select_model_param_bitflip] num_faults = {len(bits_to_flip)}" + ) # bits_to_flip = random.sample(list(range(self.num_model_param_bits)), num_faults) bits_to_flip.sort() # print(f"[fkeras.fmodel.explicit_select_model_param_bitflip] {bits_to_flip}") @@ -127,7 +131,8 @@ def random_select_model_param_bitflip(self): """ bits_to_flip_per_layer = defaultdict(int) num_faults = int(self.num_model_param_bits * self.model_param_ber) - print(f"num_faults = {num_faults}") + if self.verbose > 0: + print(f"num_faults = {num_faults}") bits_to_flip = random.sample(list(range(self.num_model_param_bits)), num_faults) bits_to_flip.sort() for bit in bits_to_flip: