Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialization of Dense with all-zero weights #501

Closed
1 of 2 tasks
PhilippPlank opened this issue Nov 24, 2022 · 3 comments · Fixed by #585
Closed
1 of 2 tasks

Initialization of Dense with all-zero weights #501

PhilippPlank opened this issue Nov 24, 2022 · 3 comments · Fixed by #585
Assignees
Labels
1-bug Something isn't working 2-important/urgent Important and urgent issues
Milestone

Comments

@PhilippPlank
Copy link
Contributor

PhilippPlank commented Nov 24, 2022

Describe the bug

The automatic determination of the weight exponent given the weights does fail, if all weights are 0. As this is used in the general Dense process for Loihi2HwCfg (running on Loihi 2), initializing weights with just 0 is currently not possible.

To reproduce current behavior
Steps to reproduce the behavior:

  • Configure as LIF->Dense network with the Dense process from the process library and set the initial weights to 0. Run the network with Loihi2HwCfg (running on Loihi 2).
weights = np.zeros((3,4))

inport_plug = LIF(shape=(4,), vth=10, du=0, dv=0, bias_mant=80)

dense_weights = Dense(weights=weights, 
                      use_graded_spike=False)

lif_layer = LIF(shape=(3,), vth=10, du=4095, dv=0, bias_mant=0)
inport_plug.s_out.connect(dense_weights.s_in)
dense_weights.a_out.connect(lif_layer.a_in)

lif_layer.run(condition=RunSteps(num_steps=run_steps), 
                 run_cfg=Loihi2HwCfg())

v_final = lif_layer.v.get()
lif_layer.stop()
  1. I get this error ...
File ~/frameworks.ai.lava.lava-loihi/.venv/lib/python3.8/site-packages/lava/utils/weightutils.py:75, in optimize_weight_bits(weights, sign_mode, loihi2)
     56 """Optimizes the weight matrix to best fit in Loihi's synapse.
     57 
     58 Parameters
   (...)
     71     An object that wraps the optimized weight matrix and weight parameters.
     72 """
     73 _validate_weights(weights, sign_mode)
---> 75 weight_exp = _determine_weight_exp(weights, sign_mode)
     76 num_weight_bits = _determine_num_weight_bits(weights, weight_exp, sign_mode)
     78 weights = np.left_shift(weights.astype(np.int32), int(-weight_exp))

File ~/frameworks.ai.lava.lava-loihi/.venv/lib/python3.8/site-packages/lava/utils/weightutils.py:148, in _determine_weight_exp(weights, sign_mode)
    145 elif sign_mode == SignMode.EXCITATORY:
    146     scale = 255 / max_weight
--> 148 scale_bits = int(np.floor(np.log2(scale)))
    149 if sign_mode == SignMode.MIXED:
    150     scale_bits += 1

OverflowError: cannot convert float infinity to integer

Expected behavior
As a user, I want the automatic determination of weight exponent and sign in Dense to work also when all weights are zero.

Environment (please complete the following information):

  • Device: Intel cloud
  • OS: Linux
  • Lava 0.5.1

Tasks

  • Implement the conversion which accepts all-zero weight matrices without throwing an error for Loihi 2 and CPU backend + writing unit tests (1/2 day)
  • Review the change and merge it (1/2 day)
@PhilippPlank PhilippPlank added the 1-bug Something isn't working label Nov 24, 2022
@PhilippPlank PhilippPlank added this to the Release v0.6 milestone Nov 24, 2022
@mathisrichter mathisrichter added the 0-needs-review For all new issues label Jan 3, 2023
@mathisrichter
Copy link
Contributor

@PhilippPlank Is this the same problem as reported in #59?

@mathisrichter mathisrichter added the help needed Extra attention is needed label Jan 9, 2023
@PhilippPlank
Copy link
Contributor Author

Yes. I guess we can close this then. Sorry for overlooking the issue.

@mathisrichter
Copy link
Contributor

Reopening the issue here as the original issue was incorrectly filed internally.

@mathisrichter mathisrichter added 2-important/urgent Important and urgent issues and removed help needed Extra attention is needed 0-needs-review For all new issues labels Jan 9, 2023
@mathisrichter mathisrichter changed the title Automatic determination of weight exp for 0 weights Initialization of Dense with all-zero weights Jan 9, 2023
@mathisrichter mathisrichter added the 0-needs-estimate Issue needs to be estimated with story points label Jan 9, 2023
@mathisrichter mathisrichter added 0-needs-work Issue needs more work or information and removed 0-needs-estimate Issue needs to be estimated with story points 0-needs-work Issue needs more work or information labels Jan 23, 2023
@PhilippPlank PhilippPlank linked a pull request Jan 26, 2023 that will close this issue
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1-bug Something isn't working 2-important/urgent Important and urgent issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants