As the code shown below, nn.ModuleList is not subclass of MutableSequence.
In : from collections.abc import MutableSequence, Mapping
In : import torch.nn as nn
In : issubclass(nn.ModuleList, MutableSequence)
In : issubclass(nn.ModuleDict, Mapping)
The source code of
Should we change the code to
class ModuleList(Module, MutableSequence):
Why or why not?
The mutable sequence type comes with quite a few functions that need to be implemented, I’m not sure all of them are there today. Is it worth to implement them? I don’t know.
Thanks. I also find that
ModuleDict implement all the interface except for
Mapping. I hope that someday they will implement this interface so I can reopen this question.
You could always send a patch it and see if they like it. If you test on ModuleDict, you’ll see what the general sentient is without risking to waste too much effort…
I came across this idea because when I want to reverse a ModuleList instance, my IDE (PyCharm) said that
reversed function only accept