Skip to content

Commit d111529

Browse files
authored
Evaluate bias scale wrt weight size (#126)
* Fixes #123
1 parent b06861f commit d111529

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

izer/checkpoint.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,15 @@ def load(
8484
while seq < len(operator) and (operator[seq] == opn.NONE or bypass[seq]):
8585
seq += 1
8686

87-
operation, parameter = k.rsplit(sep='.', maxsplit=1)
87+
param_levels = k.rsplit(sep='.', maxsplit=2)
88+
if len(param_levels) == 3:
89+
layer, op, parameter = param_levels[0], param_levels[1], param_levels[2]
90+
elif len(param_levels) == 2:
91+
layer, op, parameter = param_levels[0], None, param_levels[1]
92+
else:
93+
continue
94+
8895
if parameter in ['weight']:
89-
_, op = k.split(sep='.', maxsplit=1)
90-
op = op.rsplit(sep='.', maxsplit=1)[0]
9196
if layers >= num_conv_layers or seq >= num_conv_layers:
9297
continue
9398

@@ -171,11 +176,12 @@ def load(
171176
weight_keys.append(k)
172177

173178
# Is there a bias for this layer?
174-
bias_name = operation + '.bias'
179+
bias_name = '.'.join([layer, op, 'bias'])
180+
wb_name = '.'.join([layer, 'weight_bits'])
175181

176182
if bias_name in checkpoint_state and seq not in no_bias:
177183
w = checkpoint_state[bias_name].numpy(). \
178-
astype(np.int64) // tc.dev.BIAS_DIV
184+
astype(np.int64) // 2**(checkpoint_state[wb_name].numpy().astype(np.int64) - 1)
179185

180186
if np.all(w == 0):
181187
wprint(f'All bias values for `{bias_name}` are zero.')
@@ -207,7 +213,7 @@ def load(
207213

208214
# Not overriding output_shift?
209215
if output_shift[seq] is None:
210-
output_shift_name = operation.rsplit(sep='.', maxsplit=1)[0] + '.output_shift'
216+
output_shift_name = '.'.join([layer, 'output_shift'])
211217
# Is there an output_shift for this layer?
212218
if output_shift_name in checkpoint_state:
213219
w = checkpoint_state[output_shift_name].numpy().astype(np.int64)

0 commit comments

Comments
 (0)