lava icon indicating copy to clipboard operation
lava copied to clipboard

Monitoring Vars of SubProcesses

Open nskat opened this issue 3 years ago • 3 comments

Objective of issue: Enable the possibility to probe Vars of SubProcesses

Lava version:

  • [x] 0.3.0 (feature release)
  • [ ] 0.2.1 (bug fixes)
  • [x] 0.2.0 (current version)
  • [ ] 0.1.2

I'm submitting a ...

  • [ ] bug report
  • [x ] feature request
  • [ ] documentation request

Current behavior: As I was trying to run the MNIST tutorial, I encountered the following error: C:\Users\K1804053\Miniconda3\envs\snn\lib\site-packages\lava\proc\lif\models.py:36: RuntimeWarning: overflow encountered in multiply self.u[:] = self.u * (1 - self.du) C:\Users\K1804053\Miniconda3\envs\snn\lib\site-packages\lava\proc\lif\models.py:39: RuntimeWarning: invalid value encountered in add self.v[:] = self.v * (1 - self.dv) + self.u + bias C:\Users\K1804053\Miniconda3\envs\snn\lib\site-packages\lava\proc\lif\models.py:36: RuntimeWarning: overflow encountered in multiply self.u[:] = self.u * (1 - self.du) C:\Users\K1804053\Miniconda3\envs\snn\lib\site-packages\lava\proc\lif\models.py:39: RuntimeWarning: invalid value encountered in add self.v[:] = self.v * (1 - self.dv) + self.u + bias C:\Users\K1804053\Miniconda3\envs\snn\lib\site-packages\lava\proc\lif\models.py:36: RuntimeWarning: overflow encountered in multiply self.u[:] = self.u * (1 - self.du) C:\Users\K1804053\Miniconda3\envs\snn\lib\site-packages\lava\proc\lif\models.py:39: RuntimeWarning: invalid value encountered in add self.v[:] = self.v * (1 - self.dv) + self.u + bias I tried to set up probes on the Vars of the LIF layers to see where the overflow occurred, but it doesn't seem possible at the moment: the SubProcesses are attributes of the ModelProcess only and cannot be accessed through e.g. mnist_clf.lif1.u. The ProcessModel being chosen at compilation only, I imagine it could be possible to access it through the _model attribute after it is compiled, but it is a protected attribute so I don't expect it is a desired behavior.

Expected behavior: Set up probes on the SubProcesses of a Process directly as monitor.probe(mnist_clf.lif1.u, num_steps_per_image) Steps to reproduce: Following the first steps from the MNIST tutorial, replacing the execution with

num_images = 5
num_steps_per_image = 128

# Create instances
spike_input = SpikeInput(num_images=num_images,
                         num_steps_per_image=num_steps_per_image,
                         vth=1)
mnist_clf = MnistClassifier(
    trained_weights_path=os.path.join('.', 'mnist_pretrained.npy'))
output_proc = OutputProcess(num_images=num_images)

# Connect instances
spike_input.out_ports.spikes_out.connect(mnist_clf.in_ports.spikes_in)
mnist_clf.out_ports.spikes_out.connect(output_proc.in_ports.spikes_in)
spike_input.out_ports.label_out.connect(output_proc.in_ports.label_in)

# Set up Monitor
from lava.proc.monitor.process import Monitor
monitor = Monitor()
monitor.probe(mnist_clf.lif1.u, num_steps_per_image)

from lava.magma.core.run_conditions import RunSteps
from lava.magma.core.run_configs import Loihi1SimCfg

mnist_clf.run(
    condition=RunSteps(num_steps=(num_images+1) * num_steps_per_image),
    run_cfg=Loihi1SimCfg(select_sub_proc_model=True))
mnist_clf.stop()

raises AttributeError: 'MnistClassifier' object has no attribute 'lif1' although the MnistClassifier has a SubProcess lif1.

Thanks a lot!

nskat avatar Jan 27 '22 14:01 nskat

Hi @nskat, thanks for your feedback.

As of now, probing requires a variable to be exposed at the process level.

By default, Vars of a sub process are therefore not exposed at the level of the parent process containing the sub process because a sub process model is just one possible implementation of the behavior of a process.

However, a parent process can also define a Var that the SubProcModel "aliases" to map to a Var of a sub process. Thereby the sub process var is not just an implementation detail but exposed at the parent process level. As a result the sub process variable become probe'able.

However, I understand your desire to probe sub process variables for pure debugging purposes if such a SubProcModel is used. We will think if we can incorporate that in the design.

Thanks

awintel avatar Feb 07 '22 22:02 awintel

Thanks a lot for the clarification @awintel, it makes sense to me. It would be worth highlighting this in the upcoming tutorial on Monitors, if it's not planned already! Best, Nicolas

nskat avatar Feb 08 '22 09:02 nskat

Yes good point. Thanks! Andreas

awintel avatar Feb 08 '22 15:02 awintel