metacontroller-pytorch 0.0.1__tar.gz → 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: metacontroller-pytorch
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: Transformer Metacontroller
5
5
  Project-URL: Homepage, https://pypi.org/project/metacontroller/
6
6
  Project-URL: Repository, https://github.com/lucidrains/metacontroller
@@ -49,6 +49,7 @@ class MetaController(Module):
49
49
  self,
50
50
  dim_latent,
51
51
  *,
52
+ switch_per_latent_dim = True,
52
53
  decoder_expansion_factor = 2.,
53
54
  decoder_depth = 1,
54
55
  hypernetwork_low_rank = 16,
@@ -70,8 +71,10 @@ class MetaController(Module):
70
71
 
71
72
  # switching unit
72
73
 
74
+ self.switch_per_latent_dim = switch_per_latent_dim
75
+
73
76
  self.switching_unit = GRU(dim_latent, dim_latent)
74
- self.to_switching_unit_beta = nn.Linear(dim_latent, 1, bias = False)
77
+ self.to_switching_unit_beta = nn.Linear(dim_latent, dim_latent if switch_per_latent_dim else 1, bias = False)
75
78
 
76
79
  self.switch_gating = AssocScan(**assoc_scan_kwargs)
77
80
 
@@ -154,7 +157,7 @@ class MetaController(Module):
154
157
  switch_beta = self.to_switching_unit_beta(switching_unit_gru_out).sigmoid()
155
158
 
156
159
  action_intent_for_gating = rearrange(sampled_action_intents, 'b n d -> (b d) n')
157
- switch_beta = repeat(switch_beta, 'b n 1 -> (b d) n', d = dim)
160
+ switch_beta = repeat(switch_beta, 'b n d -> (b r d) n', r = dim if not self.switch_per_latent_dim else 1)
158
161
 
159
162
  forget = 1. - switch_beta
160
163
  gated_action_intent = self.switch_gating(action_intent_for_gating * forget, switch_beta)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "metacontroller-pytorch"
3
- version = "0.0.1"
3
+ version = "0.0.2"
4
4
  description = "Transformer Metacontroller"
5
5
  authors = [
6
6
  { name = "Phil Wang", email = "lucidrains@gmail.com" }
@@ -5,8 +5,10 @@ import torch
5
5
  from metacontroller.metacontroller import Transformer, MetaController
6
6
 
7
7
  @param('discovery_phase', (False, True))
8
+ @param('switch_per_latent_dim', (False, True))
8
9
  def test_metacontroller(
9
- discovery_phase
10
+ discovery_phase,
11
+ switch_per_latent_dim
10
12
  ):
11
13
 
12
14
  ids = torch.randint(0, 256, (1, 1024))
@@ -19,7 +21,10 @@ def test_metacontroller(
19
21
  readout = dict(num_discrete = 256)
20
22
  )
21
23
 
22
- meta_controller = MetaController(512)
24
+ meta_controller = MetaController(
25
+ 512,
26
+ switch_per_latent_dim = switch_per_latent_dim
27
+ )
23
28
 
24
29
  logits = model(ids, meta_controller = meta_controller, discovery_phase = discovery_phase)
25
30