(
transform_state_dict,
device="cpu",
)
| 724 | |
| 725 | |
| 726 | def make_ddpg_actor( |
| 727 | transform_state_dict, |
| 728 | device="cpu", |
| 729 | ): |
| 730 | proof_environment = make_transformed_env(make_env()) |
| 731 | proof_environment.transform[2].init_stats(3) |
| 732 | proof_environment.transform[2].load_state_dict(transform_state_dict) |
| 733 | |
| 734 | out_features = proof_environment.action_spec.shape[-1] |
| 735 | |
| 736 | actor_net = DdpgMlpActor( |
| 737 | action_dim=out_features, |
| 738 | ) |
| 739 | |
| 740 | in_keys = ["observation_vector"] |
| 741 | out_keys = ["param"] |
| 742 | |
| 743 | actor = TensorDictModule( |
| 744 | actor_net, |
| 745 | in_keys=in_keys, |
| 746 | out_keys=out_keys, |
| 747 | ) |
| 748 | |
| 749 | actor = ProbabilisticActor( |
| 750 | actor, |
| 751 | distribution_class=TanhDelta, |
| 752 | in_keys=["param"], |
| 753 | spec=CompositeSpec(action=proof_environment.action_spec), |
| 754 | ).to(device) |
| 755 | |
| 756 | q_net = DdpgMlpQNet() |
| 757 | |
| 758 | in_keys = in_keys + ["action"] |
| 759 | qnet = ValueOperator( |
| 760 | in_keys=in_keys, |
| 761 | module=q_net, |
| 762 | ).to(device) |
| 763 | |
| 764 | # initialize lazy modules |
| 765 | qnet(actor(proof_environment.reset().to(device))) |
| 766 | return actor, qnet |
| 767 | |
| 768 | |
| 769 | actor, qnet = make_ddpg_actor( |
no test coverage detected