Skip to content
Discussion options

You must be logged in to vote

The expression self.layers is evaluated as type ModuleList, but the expression self.layers[:-1] has the type ModuleList | Module. This comes directly from the ModuleList.__getitem__ method type declaration:

class ModuleList(Module):
    ...
    def __getitem__(self, idx: Union[int, slice]) -> Union[Module, 'ModuleList']: ...

The problem appears to be that __getitem__ is missing an @overload declaration. If you add the following overloads to the pytorch sources, it will work as expected.

    @overload
    def __getitem__(self, idx: int) -> Module: ...
    @overload
    def __getitem__(self, idx: slice) -> ModuleList: ...

You may want to file a bug report or submit a PR in the pytorch project.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by InfiniteSwerve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants