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

Use GATv2 + add option to use different number of heads. #43

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 7 additions & 4 deletions clrs/_src/baselines.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(
inf_bias_edge: bool,
use_lstm: bool,
dropout_prob: float,
nb_heads: int,
nb_dims=None,
name: str = 'net',
):
Expand All @@ -93,6 +94,7 @@ def __init__(
self.kind = kind
self.nb_dims = nb_dims
self.use_lstm = use_lstm
self.nb_heads = nb_heads

def _msg_passing_step(self,
mp_state: _MessagePassingScanState,
Expand Down Expand Up @@ -289,13 +291,13 @@ def _construct_processor(self):
elif self.kind in ['gat', 'gat_full']:
self.mpnn = processors.GAT(
out_size=self.hidden_dim,
nb_heads=1,
nb_heads=self.nb_heads,
activation=jax.nn.relu,
residual=True)
elif self.kind in ['gatv2', 'gatv2_full']:
self.mpnn = processors.GAT(
self.mpnn = processors.GATv2(
out_size=self.hidden_dim,
nb_heads=1,
nb_heads=self.nb_heads,
activation=jax.nn.relu,
residual=True)
elif self.kind == 'memnet_full' or self.kind == 'memnet_masked':
Expand Down Expand Up @@ -440,6 +442,7 @@ class BaselineModel(model.Model):
def __init__(
self,
spec,
nb_heads=1,
hidden_dim=32,
kind='mpnn',
encode_hints=False,
Expand Down Expand Up @@ -485,7 +488,7 @@ def __init__(
def _use_net(*args, **kwargs):
return Net(spec, hidden_dim, encode_hints, decode_hints, decode_diffs,
kind, inf_bias, inf_bias_edge, use_lstm, dropout_prob,
self.nb_dims)(*args, **kwargs)
nb_heads, self.nb_dims)(*args, **kwargs)

self.net_fn = hk.transform(_use_net)
self.net_fn_apply = jax.jit(self.net_fn.apply, static_argnums=3)
Expand Down
2 changes: 2 additions & 0 deletions clrs/examples/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'Number of hidden size units of the model.')
flags.DEFINE_float('learning_rate', 0.003, 'Learning rate to use.')
flags.DEFINE_float('dropout_prob', 0.0, 'Dropout rate to use.')
flags.DEFINE_integer('nb_heads', 1, 'Number of heads for GAT processors')

flags.DEFINE_boolean('encode_hints', True,
'Whether to provide hints as model inputs.')
Expand Down Expand Up @@ -121,6 +122,7 @@ def main(unused_argv):
checkpoint_path=FLAGS.checkpoint_path,
freeze_processor=FLAGS.freeze_processor,
dropout_prob=FLAGS.dropout_prob,
nb_heads=FLAGS.nb_heads,
dummy_trajectory=next(train_sampler),
)

Expand Down