Skip to content
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] Surprising MLP default behavior #2328

Closed
3 tasks done
chnyutao opened this issue Jul 29, 2024 · 2 comments · Fixed by #2395
Closed
3 tasks done

[BUG] Surprising MLP default behavior #2328

chnyutao opened this issue Jul 29, 2024 · 2 comments · Fixed by #2395
Assignees
Labels
bug Something isn't working

Comments

@chnyutao
Copy link

Describe the bug

When depth and num_cells are both not specified, MLP will by default create a fully-connected neural network with three hidden layers, each with 32 neurons.

This is somewhat surprising, as I would imaging leaving depth and num_cells unspecified would lead to a neural network with no hidden layer at all. Not sure why use depth=3 and num_cells=32 as default here :)

This is not really a bug report, just IMHO a weird design choice which is also not documented. Would appreciate if we can discuss and reconsider this.

To Reproduce

>>> from torchrl.modules import MLP
>>> MLP(in_features=1024, out_features=512)
MLP(
  (0): Linear(in_features=1024, out_features=32, bias=True)
  (1): Tanh()
  (2): Linear(in_features=32, out_features=32, bias=True)
  (3): Tanh()
  (4): Linear(in_features=32, out_features=32, bias=True)
  (5): Tanh()
  (6): Linear(in_features=32, out_features=512, bias=True)
)

Expected behavior

>>> MLP(in_features=1024, out_features=512)
MLP(
  (0): Linear(in_features=1024, out_features=512, bias=True)
)

System info

  • Python 3.10.0
  • TorchRL 0.3.1

Reason and Possible fixes

default_num_cells = 32
if num_cells is None:
if depth is None:
num_cells = [default_num_cells] * 3
depth = 3
else:
num_cells = [default_num_cells] * depth

Checklist

  • I have checked that there is no similar issue in the repo (required)
  • I have read the documentation (required)
  • I have provided a minimal working example to reproduce the bug (required)
@chnyutao chnyutao added the bug Something isn't working label Jul 29, 2024
@vmoens
Copy link
Contributor

vmoens commented Jul 29, 2024

I agree, it's more a historical debt than anything meaningful.
I will make a PR to progressively deprecate this.
In the future, I can see two default behaviours for your example:

  • no depth, just a linear layer
  • error: one must say what depth / number of cells is to be used
    Let me know what you think would make more sense here!

@chnyutao
Copy link
Author

Thanks, I personally would prefer the former behavior (no depth implies depth=0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants