Open sssleder opened 1 month ago
Ah it seems I misunderstood the purpose of the input_map
argument. By setting input_map={'skip_weights': 'node'}
I was able to properly set the Parameters as a node-level argument. The purpose and use of input_map
was not immediately clear from the documentation.
However, using torch_geometric.nn.to_hetero()
as follows results in a NotImplementedError
:
model = to_hetero(model, data.metadata(), debug=True, input_map={'skip_weights': 'node', 'linear': 'node'})
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
Cell In[17], line 64
60 #model = to_hetero_with_bases(model, data.metadata(), num_bases=2, in_channels={'x': 2}, debug=True, input_map={'skip_weights': 'node'})#, 'linear': 'node', 'x': 'node'})
62 print(data.metadata())
---> 64 model = to_hetero(model, data.metadata(), debug=True, input_map={'skip_weights': 'node'})
File ~/.conda/envs/graph_mining/lib/python3.11/site-packages/torch_geometric/nn/to_hetero_transformer.py:120, in to_hetero(module, metadata, aggr, input_map, debug)
30 r"""Converts a homogeneous GNN model into its heterogeneous equivalent in
31 which node representations are learned for each node type in
32 :obj:`metadata[0]`, and messages are exchanged between each edge type in
(...)
117 transformation in debug mode. (default: :obj:`False`)
118 """
119 transformer = ToHeteroTransformer(module, metadata, aggr, input_map, debug)
--> 120 return transformer.transform()
File ~/.conda/envs/graph_mining/lib/python3.11/site-packages/torch_geometric/nn/fx.py:165, in Transformer.transform(self)
163 elif is_global_pooling_op(self.module, op, node.target):
164 op = 'call_global_pooling_module'
--> 165 getattr(self, op)(node, node.target, node.name)
167 # Remove all unused nodes in the computation graph, i.e., all nodes
168 # which have been replaced by node type-wise or edge type-wise variants
169 # but which are still present in the computation graph.
170 # We do this by iterating over the computation graph in reversed order,
171 # and try to remove every node. This does only succeed in case there
172 # are no users of that node left in the computation graph.
173 for node in reversed(list(self.graph.nodes)):
File ~/.conda/envs/graph_mining/lib/python3.11/site-packages/torch_geometric/nn/to_hetero_transformer.py:191, in ToHeteroTransformer.get_attr(self, node, target, name)
190 def get_attr(self, node: Node, target: Any, name: str):
--> 191 raise NotImplementedError
NotImplementedError:
🚀 The feature, motivation and pitch
When creating a heterogeneous model by using
torch_geometric.nn.to_hetero_with_bases()
, usingtorch.nn.parameter.Parameter
directly as a layer is unsupported while layers such astorch.nn.Linear
, which depend on it, are supported. I would like for this functionality to be implemented as it would be quite helpful.An example of this is as follows:
With the current implementation this results in the following error:
Alternatives
Simply using
torch.nn.Linear(bias=False)
is not a viable alternative totorch.nn.parameter.Parameter
in all use cases.Additional context
No response