ModuleList.extend should be called with an iterable, but got PositionalEncoding
时间: 2024-03-25 11:38:54 浏览: 18
It seems like you are encountering an error in PyTorch related to using `extend` method on `nn.ModuleList`. The error message suggests that you need to pass an iterable object to `extend`, but you might be passing a single item instead (in your case, `PositionalEncoding`).
To fix this error, you could wrap `PositionalEncoding` in a list or tuple before passing it to `extend`. Here's an example:
```
import torch.nn as nn
class MyModel(nn.Module):
def __init__(self):
super().__init__()
self.layers = nn.ModuleList()
self.layers.extend([PositionalEncoding(), nn.Linear(10, 5)])
```
In this example, we've wrapped `PositionalEncoding` in a list before passing it to `extend`. This should resolve the error you encountered.