Skip to content

Commit

Permalink
Add memory_summary back to DynapcnnNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
bauerfe committed Oct 31, 2024
1 parent 3d4793f commit bb0e132
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion sinabs/backend/dynapcnn/dynapcnn_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,26 @@ def parameters(self) -> list:

return parameters

def memory_summary(self) -> Dict[str, Dict[int, int]]:
"""Get a summary of the network's memory requirements.
Returns
-------
dict:
A dictionary with keys kernel, neuron, bias. The values are a dicts.
Each nested dict has as keys the indices of all dynapcnn_layers and
as values the corresonding memory values for each layer.
"""
# For each entry (kernel, neuron, bias) provide one nested dict with
# one entry for each layer
summary = {key: dict() for key in ("kernel", "neuron", "bias")}

for layer_index, layer in self.dynapcnn_layers.items():
for key, val in layer.memory_summary().items():
summary[key][layer_index] = val

return summary

def init_weights(self, init_fn: nn.init = nn.init.xavier_normal_) -> None:
"""Call the weight initialization method `init_fn` on each `DynapcnnLayer.conv_layer.weight.data` in the `DynapcnnNetwork` instance.
Expand Down Expand Up @@ -240,7 +260,7 @@ def to(
config_modifier: Optional[Callable] = None,
slow_clk_frequency: Optional[int] = None,
layer2core_map: Union[Dict[int, int], str] = "auto",
chip_layers_ordering="auto",
chip_layers_ordering: Optional[Union[Sequence[int], str]] = None,
):
"""Deploy model to cpu, gpu or a SynSense device.
Expand Down

0 comments on commit bb0e132

Please sign in to comment.