Open nehSgnaiL opened 1 month ago
I suspect the issue is due to the loading of wrong Sequential
module likely due to the random uid
being used to generate the /tmp/torchgeometric.nn.sequential{uid}.py file.
In your construct_model
function, you seem to create Sequential
module with 3 layers and 2 layers. If the current Sequential
module is,
Sequential(
(0) - ChebConv(32, 16, K=3, normalization=sym): x, edge_index, edge_weight -> x
(1) - ChebConv(16, 1, K=3, normalization=sym): x, edge_index, edge_weight -> x
)
and the /tmp/torch_geometric.nn.sequential_{uid}.py
file loaded from the module_from_template contains Sequential
module,
Sequential(
(0) - ChebConv(32, 16, K=3, normalization=sym): x, edge_index, edge_weight -> x
(1) - ChebConv(16, 1, K=3, normalization=sym): x, edge_index, edge_weight -> x
(2) - ChebConv(32, 1, K=3, normalization=sym): x, edge_index, edge_weight -> x
)
then you might get an index error when executing the print statement since the loaded Sequential
module has len(self)
of 3 but the _module_names contains only 2 values.
Potential cause
I suspect the issue is due to the loading of wrong
Sequential
module likely due to the randomuid
being used to generate the /tmp/torchgeometric.nn.sequential{uid}.py file.Explanation
In your
construct_model
function, you seem to createSequential
module with 3 layers and 2 layers. If the currentSequential
module is,Sequential( (0) - ChebConv(32, 16, K=3, normalization=sym): x, edge_index, edge_weight -> x (1) - ChebConv(16, 1, K=3, normalization=sym): x, edge_index, edge_weight -> x )
and the
/tmp/torch_geometric.nn.sequential_{uid}.py
file loaded from the module_from_template containsSequential
module,Sequential( (0) - ChebConv(32, 16, K=3, normalization=sym): x, edge_index, edge_weight -> x (1) - ChebConv(16, 1, K=3, normalization=sym): x, edge_index, edge_weight -> x (2) - ChebConv(32, 1, K=3, normalization=sym): x, edge_index, edge_weight -> x )
then you might get an index error when executing the print statement since the loaded
Sequential
module haslen(self)
of 3 but the _module_names contains only 2 values.
Thanks for your hint.
In my practice, the torch_geometric.nn.Sequential
will be confused and might raise an error if many objects are created, no matter whether in a multiprocess environment, because I set the same random seed at the beginning of my function.
Right now, my temporal solution is using torch.nn.ModuleDict
instead of torch_geometric.nn.Sequential
and making some adjustments to my code.
Your original code should work fine if you install PyG from source (pip install git+https://github.com/pyg-team/pytorch_geometric.git
). Recent version of PyG 2.6.0 contains Sequential
module that has been refactored,
Sequential
class on the fly has been moved from sequential.jinja
file to sequential.py
file. sequential.jinja
file. Take a look at #9369.
🐛 Describe the bug
Problem description:
Hello,
I recently encountered an
IndexError
when attempting to initializetorch_geometric.nn.Sequential
within a multiprocessing environment. My suspicion is that due to the shared nature of multiprocessing, the ID of theSequential
module might be the same across multiple processes, leading to conflicts and incorrect indexing.I would greatly appreciate any suggestions on how to address this issue. :)
Code to reproduce:
Error message:
Versions