As the code shown below, nn.ModuleList is not subclass of MutableSequence.
In [4]: from collections.abc import MutableSequence, Mapping
In [5]: import torch.nn as nn
In [6]: issubclass(nn.ModuleList, MutableSequence)
Out[6]: False
In [7]: issubclass(nn.ModuleDict, Mapping)
Out[7]: False
Thanks. I also find that ModuleDict implement all the interface except for get in 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 Sequence or Reversible[_T].