Skip to content

Commit

Permalink
DONE - DVS node not given
Browse files Browse the repository at this point in the history
constructor of DynapcnnNetwork executing wihtout errors
  • Loading branch information
Willian-Girao committed Oct 29, 2024
1 parent 3a5e419 commit 430af98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 11 additions & 10 deletions sinabs/backend/dynapcnn/dynapcnn_layer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,17 @@ def construct_destination_map(dcnnl_map: Dict[int, Dict]) -> Dict[int, List[int]
"""
destination_map = dict()
for layer_index, layer_info in dcnnl_map.items():
destination_indices = []
none_counter = 0
for dest in layer_info["destinations"]:
if (dest_idx := dest["destination_layer"]) is None:
# For `None` destinations use unique negative index
none_counter += 1
destination_indices.append(-none_counter)
else:
destination_indices.append(dest_idx)
destination_map[layer_index] = destination_indices
if 'dvs_layer' not in layer_info: # only called for `DynapcnnLayer` instances (skip DVS layer).
destination_indices = []
none_counter = 0
for dest in layer_info["destinations"]:
if (dest_idx := dest["destination_layer"]) is None:
# For `None` destinations use unique negative index
none_counter += 1
destination_indices.append(-none_counter)
else:
destination_indices.append(dest_idx)
destination_map[layer_index] = destination_indices

# update mapper if a DVS layer exists.
update_destination_map_with_dvs(dcnnl_map, destination_map)
Expand Down
4 changes: 4 additions & 0 deletions sinabs/backend/dynapcnn/sinabs_edges_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def collect_dynapcnn_layer_info(
dynapcnn_layer_info,
indx_2_module_map,
node_2_layer_map,
nodes_io_shapes,
)

# TODO - handle dvs->pooling connections.
Expand Down Expand Up @@ -405,6 +406,7 @@ def add_or_update_dvs_to_entry(
dynapcnn_layer_info: Dict[int, Dict[int, Dict]],
indx_2_module_map: Dict[int, nn.Module],
node_2_layer_map: Dict[int, int],
nodes_io_shapes: Dict[int, Dict[str, Tuple[Size, Size]]],
) -> None:
""" Initiate or update dict to hold information for a DVS Layer configuration based on a "dvs-weight" edges.
Change `dynapcnn_layer_info` in-place. If a entry for the DVS node exists the function will add a new entry
Expand All @@ -420,6 +422,7 @@ def add_or_update_dvs_to_entry(
indx_2_module_map (dict): Maps node IDs of the graph as `key` to their associated module as `value`
node_2_layer_map (dict): Maps each node ID to the ID of the layer it is assigned to.
Will be updated in-place.
nodes_io_shapes (dict): Map from node ID to dict containing node's in- and output shapes
"""

assert isinstance(indx_2_module_map[edge[0]], DVSLayer), f'Source node in edge {edge} is of type {type(DVSLayer)} (it should be a DVSLayer instance).'
Expand All @@ -432,6 +435,7 @@ def add_or_update_dvs_to_entry(

# Init. entry for a DVS layer using its configuration dict.
dynapcnn_layer_info[layer_id] = {
"is_entry_node": True,
"dvs_layer": True,
"node_id": edge[0],
# TODO - GraphTracer not populating I/O shape for DVS yet.
Expand Down

0 comments on commit 430af98

Please sign in to comment.