8000 Override `__call__` instead of `forward` · Issue #38876 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content
Override __call__ instead of forward #38876
@vpj

Description

@vpj

🚀 Feature

Let users override __call__ of modules so that it works with type checking.

Motivation

This is a Module class I've been using over torch.nn.Module so that I can override __call__ instead of forward.

Pitch

When writing modules we override forward, and invoke them through __call__. In this setup
we can neither use static analysis tools to find errors nor use editor features such as viewing method signatures.

Additional context

Are there any side effects of using __init_subclass__ to rename __call__ implementations of subclasses to forward?.

cc @ezyang

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: typingRelated to mypy type annotationstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0