-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Incorrect ABC type signature of BaseModel.forward #1027
Comments
Your recommendation seems legitimate. stable-baselines3/stable_baselines3/common/policies.py Lines 90 to 92 in c4f54fc
|
Deleting the definition of I like PRs that just delete code :) |
LOL okay will add a PR for this when I get a minute.
…On Fri, Sep 9 2022 at 23:28, Adam Gleave < ***@***.*** > wrote:
Deleting the definition of forward in BaseModel does seem like it should
work, so long as it's already defined sufficiently generically in nn.Module
, which it seems it is from https://github.com/pytorch/pytorch/blob/ce7a9f92e30b93ab6efff4135be005c9afd0533a/torch/nn/modules/module.py#L230-L244
I like PRs that just delete code :)
—
Reply to this email directly, view it on GitHub (
#1027 (comment)
) , or unsubscribe (
https://github.com/notifications/unsubscribe-auth/ABVWH33I666KUORDTV7O6DDV5OTZVANCNFSM57NFB2DQ
).
You are receiving this because you authored the thread. Message ID: <DLR-RM/stable-baselines3/issues/1027/1242495280
@ github. com>
|
Important Note: We do not do technical support, nor consulting and don't answer personal questions per email.
Please post your question on the RL Discord, Reddit or Stack Overflow in that case.
If your issue is related to a custom gym environment, please use the custom gym env template.
🐛 Bug
The defined type signature of the abstract
.forward()
method insb3.common.policies.BaseModel
is too general and no actual implementation that is type-safe is possible.The method is defined as:
This means that all objects subclassing
BaseModel
(including BasePolicy) have to necessarily accept any positional and named arguments in their type signature to be compliant with the type.One has to either
To Reproduce
BaseModel
instance with a type signature more restrictive than*args, **kwargs
signature of "func" incompatible with supertype "BaseClass"
Minimal working example. The following code is wrong:
Expected behavior
I would like to be allowed to implement this abstract method without having to hack the type checker.
### System Info
You can use
sb3.get_system_info()
to print relevant packages info:Potential solution
This has been discussed in mypy (python/mypy#5876) and the recommended approach is to avoid violating LSP if possible, especially in ABCs. However, there can a good reason for requiring subclasses to implement some forward method, whose specific type signature may depend on the class. A potential hack is (again with the minimal working example):
So in the case of SB3,
Checklist
The text was updated successfully, but these errors were encountered: