evolutionary-policy-optimization 0.4.0__tar.gz → 0.4.1__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.
- {evolutionary_policy_optimization-0.4.0 → evolutionary_policy_optimization-0.4.1}/.gitignore +12 -0
- {evolutionary_policy_optimization-0.4.0 → evolutionary_policy_optimization-0.4.1}/PKG-INFO +2 -2
- {evolutionary_policy_optimization-0.4.0 → evolutionary_policy_optimization-0.4.1}/evolutionary_policy_optimization/epo.py +28 -9
- {evolutionary_policy_optimization-0.4.0 → evolutionary_policy_optimization-0.4.1}/pyproject.toml +2 -2
- {evolutionary_policy_optimization-0.4.0 → evolutionary_policy_optimization-0.4.1}/LICENSE +0 -0
- {evolutionary_policy_optimization-0.4.0 → evolutionary_policy_optimization-0.4.1}/README.md +0 -0
- {evolutionary_policy_optimization-0.4.0 → evolutionary_policy_optimization-0.4.1}/evolutionary_policy_optimization/__init__.py +0 -0
- {evolutionary_policy_optimization-0.4.0 → evolutionary_policy_optimization-0.4.1}/evolutionary_policy_optimization/distributed.py +0 -0
- {evolutionary_policy_optimization-0.4.0 → evolutionary_policy_optimization-0.4.1}/evolutionary_policy_optimization/env_wrappers.py +0 -0
- {evolutionary_policy_optimization-0.4.0 → evolutionary_policy_optimization-0.4.1}/evolutionary_policy_optimization/experimental.py +0 -0
- {evolutionary_policy_optimization-0.4.0 → evolutionary_policy_optimization-0.4.1}/evolutionary_policy_optimization/mock_env.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: evolutionary-policy-optimization
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: EPO - Pytorch
|
|
5
5
|
Project-URL: Homepage, https://pypi.org/project/evolutionary-policy-optimization/
|
|
6
6
|
Project-URL: Repository, https://github.com/lucidrains/evolutionary-policy-optimization
|
|
@@ -40,7 +40,7 @@ Requires-Dist: einops>=0.8.1
|
|
|
40
40
|
Requires-Dist: einx>=0.3.0
|
|
41
41
|
Requires-Dist: ema-pytorch>=0.7.7
|
|
42
42
|
Requires-Dist: hl-gauss-pytorch>=0.2.8
|
|
43
|
-
Requires-Dist: mean-conc-beta>=0.
|
|
43
|
+
Requires-Dist: mean-conc-beta>=0.2.7
|
|
44
44
|
Requires-Dist: torch>=2.2
|
|
45
45
|
Requires-Dist: tqdm
|
|
46
46
|
Requires-Dist: x-mlps-pytorch>=0.3.0
|
|
@@ -52,6 +52,20 @@ def divisible_by(num, den):
|
|
|
52
52
|
def to_device(inp, device):
|
|
53
53
|
return tree_map(lambda t: t.to(device) if is_tensor(t) else t, inp)
|
|
54
54
|
|
|
55
|
+
class ShuffledBatches:
|
|
56
|
+
# fresh permutation on every pass
|
|
57
|
+
|
|
58
|
+
def __init__(self, fields, batch_size):
|
|
59
|
+
self.fields = fields
|
|
60
|
+
self.batch_size = batch_size
|
|
61
|
+
|
|
62
|
+
def __iter__(self):
|
|
63
|
+
perm = torch.randperm(self.fields[0].shape[0])
|
|
64
|
+
|
|
65
|
+
for i in range(0, len(perm), self.batch_size):
|
|
66
|
+
b = perm[i:i + self.batch_size]
|
|
67
|
+
yield [field[b] for field in self.fields]
|
|
68
|
+
|
|
55
69
|
def maybe(fn):
|
|
56
70
|
|
|
57
71
|
@wraps(fn)
|
|
@@ -1234,6 +1248,7 @@ class Agent(Module):
|
|
|
1234
1248
|
hidden_spr_ema_update = 0.99,
|
|
1235
1249
|
get_fitness_scores: Callable[..., Tensor] = get_fitness_scores,
|
|
1236
1250
|
wrap_with_accelerate: bool = True,
|
|
1251
|
+
use_dataloader = False,
|
|
1237
1252
|
accelerate_kwargs: dict = dict(),
|
|
1238
1253
|
accelerator = None,
|
|
1239
1254
|
quiet: bool = False,
|
|
@@ -1245,6 +1260,7 @@ class Agent(Module):
|
|
|
1245
1260
|
# hf accelerate
|
|
1246
1261
|
|
|
1247
1262
|
self.wrap_with_accelerate = wrap_with_accelerate
|
|
1263
|
+
self.use_dataloader = use_dataloader
|
|
1248
1264
|
|
|
1249
1265
|
if wrap_with_accelerate:
|
|
1250
1266
|
self.accelerate = accelerator if exists(accelerator) else Accelerator(**accelerate_kwargs)
|
|
@@ -1592,13 +1608,12 @@ class Agent(Module):
|
|
|
1592
1608
|
epochs = 2
|
|
1593
1609
|
|
|
1594
1610
|
):
|
|
1595
|
-
memories_and_cumulative_rewards = to_device(memories_and_cumulative_rewards, self.device)
|
|
1596
|
-
|
|
1597
1611
|
memories_list, rewards_per_latent_episode = memories_and_cumulative_rewards
|
|
1598
1612
|
|
|
1599
|
-
# stack
|
|
1613
|
+
# stack, then move once per field
|
|
1600
1614
|
|
|
1601
|
-
memories = map(stack, zip(*memories_list))
|
|
1615
|
+
memories = [t.to(self.device) for t in map(stack, zip(*memories_list))]
|
|
1616
|
+
rewards_per_latent_episode = rewards_per_latent_episode.to(self.device)
|
|
1602
1617
|
|
|
1603
1618
|
memories_list.clear()
|
|
1604
1619
|
|
|
@@ -1640,12 +1655,15 @@ class Agent(Module):
|
|
|
1640
1655
|
|
|
1641
1656
|
valid_episode = episode_ids >= 0
|
|
1642
1657
|
|
|
1643
|
-
|
|
1658
|
+
fields = tuple(t[valid_episode] for t in (advantages, states, next_states, latent_gene_ids, actions, log_probs, values, dones))
|
|
1644
1659
|
|
|
1645
|
-
|
|
1660
|
+
if self.wrap_with_accelerate or self.use_dataloader:
|
|
1661
|
+
dataloader = DataLoader(TensorDataset(*fields), batch_size = self.batch_size, shuffle = True)
|
|
1646
1662
|
|
|
1647
|
-
|
|
1648
|
-
|
|
1663
|
+
if self.wrap_with_accelerate:
|
|
1664
|
+
dataloader = self.accelerate.prepare(dataloader)
|
|
1665
|
+
else:
|
|
1666
|
+
dataloader = ShuffledBatches(fields, self.batch_size)
|
|
1649
1667
|
|
|
1650
1668
|
# updating actor and critic
|
|
1651
1669
|
|
|
@@ -2160,6 +2178,7 @@ class EPO(Module):
|
|
|
2160
2178
|
|
|
2161
2179
|
next_obs, rewards, terminated, truncated = env.step_batch(actions.cpu().numpy(), worker_ids = active)[:4]
|
|
2162
2180
|
|
|
2181
|
+
next_states = from_numpy(np.ascontiguousarray(next_obs)).float().to(self.device)
|
|
2163
2182
|
rewards = from_numpy(np.asarray(rewards)).float().to(self.device)
|
|
2164
2183
|
terminated = from_numpy(np.asarray(terminated)).to(self.device)
|
|
2165
2184
|
truncated = from_numpy(np.asarray(truncated)).to(self.device)
|
|
@@ -2169,7 +2188,7 @@ class EPO(Module):
|
|
|
2169
2188
|
|
|
2170
2189
|
latent_id, episode_id, latent, state = slot.latent_id, slot.episode_id, slot.latent, slot.state
|
|
2171
2190
|
|
|
2172
|
-
next_state =
|
|
2191
|
+
next_state = next_states[k]
|
|
2173
2192
|
|
|
2174
2193
|
reward, terminated_at, truncated_at = rewards[k], terminated[k], truncated[k]
|
|
2175
2194
|
|
{evolutionary_policy_optimization-0.4.0 → evolutionary_policy_optimization-0.4.1}/pyproject.toml
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "evolutionary-policy-optimization"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.1"
|
|
4
4
|
description = "EPO - Pytorch"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Phil Wang", email = "lucidrains@gmail.com" }
|
|
@@ -30,7 +30,7 @@ dependencies = [
|
|
|
30
30
|
'einops>=0.8.1',
|
|
31
31
|
'ema-pytorch>=0.7.7',
|
|
32
32
|
'hl-gauss-pytorch>=0.2.8',
|
|
33
|
-
'mean-conc-beta>=0.
|
|
33
|
+
'mean-conc-beta>=0.2.7',
|
|
34
34
|
'torch>=2.2',
|
|
35
35
|
'tqdm',
|
|
36
36
|
"x-mlps-pytorch>=0.3.0",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|