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

Deprecation of shared layers in MlpExtractor #1252

Merged
merged 7 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Minor edits
  • Loading branch information
araffin committed Jan 4, 2023
commit b88cb2a3cae106263e6df0c3ba75260fdf468cd2
6 changes: 1 addition & 5 deletions docs/guide/custom_policy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ If your task requires even more granular control over the policy/value architect
last_layer_dim_pi: int = 64,
last_layer_dim_vf: int = 64,
):
super(CustomNetwork, self).__init__()
super().__init__()

# IMPORTANT:
# Save output dimensions, used to create the distributions
Expand Down Expand Up @@ -361,8 +361,6 @@ If your task requires even more granular control over the policy/value architect
observation_space: spaces.Space,
action_space: spaces.Space,
lr_schedule: Callable[[float], float],
net_arch: Optional[List[Union[int, Dict[str, List[int]]]]] = None,
activation_fn: Type[nn.Module] = nn.Tanh,
*args,
**kwargs,
):
Expand All @@ -371,8 +369,6 @@ If your task requires even more granular control over the policy/value architect
observation_space,
action_space,
lr_schedule,
net_arch,
activation_fn,
# Pass remaining arguments to base class
*args,
**kwargs,
Expand Down
4 changes: 2 additions & 2 deletions stable_baselines3/common/torch_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class MlpExtractor(nn.Module):
It is formatted like ``dict(vf=[<value layer sizes>], pi=[<policy layer sizes>])``.
If it is missing any of the keys (pi or vf), no non-shared layers (empty list) is assumed.

Depredcation note: shared layers in ``net_arch`` are deprecated, please use separate
pi and vf networks (e.g. net_arch=[dict(pi=[...], vf=[...])])
Deprecation note: shared layers in ``net_arch`` are deprecated, please use separate
pi and vf networks (e.g. net_arch=dict(pi=[...], vf=[...]))

For example to construct a network with one shared layer of size 55 followed by two non-shared layers for the value
network of size 255 and a single non-shared layer of size 128 for the policy network, the following layers_spec
Expand Down
2 changes: 1 addition & 1 deletion tests/test_custom_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@pytest.mark.parametrize("model_class", [A2C, PPO])
def test_flexible_mlp(model_class, net_arch):
if isinstance(net_arch, list) and len(net_arch) > 0 and isinstance(net_arch[0], int):
with pytest.warns():
with pytest.warns(DeprecationWarning):
_ = model_class("MlpPolicy", "CartPole-v1", policy_kwargs=dict(net_arch=net_arch), n_steps=64).learn(300)
else:
_ = model_class("MlpPolicy", "CartPole-v1", policy_kwargs=dict(net_arch=net_arch), n_steps=64).learn(300)
Expand Down