-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Refactor of Policy: get rid of config parameter and set argumen…
…ts directly; isolate random, uniform and fixed policies; docstring, etc.
- Loading branch information
1 parent
910a948
commit d85ad5f
Showing
10 changed files
with
176 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
_target_: gflownet.policy.base.Policy | ||
|
||
base: null | ||
shared_weights: False | ||
checkpoint: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
_target_: gflownet.policy.cnn.CNNPolicy | ||
|
||
shared: null | ||
defaults: | ||
- base | ||
|
||
forward: | ||
n_layers: 2 | ||
channels: [16, 32] | ||
kernel_sizes: [[3, 3], [2, 2]] # Each tuple represents (height, width) | ||
strides: [[1, 1], [1, 1]] # Each tuple represents (vertical_stride, horizontal_stride) | ||
checkpoint: null | ||
reload_ckpt: False | ||
_target_: gflownet.policy.cnn.CNNPolicy | ||
|
||
backward: | ||
shared_weights: True | ||
checkpoint: null | ||
reload_ckpt: False | ||
n_layers: 2 | ||
channels: [16, 32] | ||
# Kernels: Each tuple represents (height, width) | ||
kernels: [[3, 3], [2, 2]] | ||
# Strides: Each tuple represents (vertical_stride, horizontal_stride) | ||
strides: [[1, 1], [1, 1]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
_target_: gflownet.policy.mlp.MLPPolicy | ||
|
||
shared: null | ||
defaults: | ||
- base | ||
|
||
forward: | ||
n_hid: 128 | ||
n_layers: 2 | ||
checkpoint: null | ||
reload_ckpt: False | ||
_target_: gflownet.policy.mlp.MLPPolicy | ||
|
||
backward: null | ||
n_hid: 128 | ||
n_layers: 2 | ||
tail: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from gflownet.policy.base import Policy | ||
|
||
|
||
class FixedPolicy(Policy): | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
def make_model(self): | ||
""" | ||
Instantiates the policy model as a fixed tensor with the values of | ||
`self.fixed_output` defined by the environment. | ||
Returns | ||
------- | ||
model : torch.tensor | ||
The tensor `self.fixed_output` defined by the environment. | ||
is_model : bool | ||
False, because the policy is not a model. | ||
""" | ||
return ( | ||
torch.tile(self.fixed_output, (len(states), 1)).to( | ||
dtype=self.float, device=self.device | ||
), | ||
False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from gflownet.policy.base import Policy | ||
|
||
|
||
class RandomPolicy(Policy): | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
def make_model(self): | ||
""" | ||
Instantiates the policy model as a fixed tensor with the values of | ||
`self.random_output` defined by the environment. | ||
Returns | ||
------- | ||
model : torch.tensor | ||
The tensor `self.random_output` defined by the environment. | ||
is_model : bool | ||
False, because the policy is not a model. | ||
""" | ||
return ( | ||
torch.tile(self.random_output, (len(states), 1)).to( | ||
dtype=self.float, device=self.device | ||
), | ||
False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from gflownet.policy.base import Policy | ||
|
||
|
||
class UniformPolicy(Policy): | ||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
||
def make_model(self): | ||
""" | ||
Instantiates the policy model as a fixed tensor of ones, to define a uniform | ||
distribution over the action space. | ||
Returns | ||
------- | ||
model : torch.tensor | ||
A tensor of `self.output_dim` ones. | ||
is_model : bool | ||
False, because the policy is not a model. | ||
""" | ||
return ( | ||
torch.ones( | ||
(len(states), self.output_dim), dtype=self.float, device=self.device | ||
), | ||
False, | ||
) |