evolutionary-policy-optimization 0.3.1__tar.gz → 0.3.5__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.3.1 → evolutionary_policy_optimization-0.3.5}/PKG-INFO +3 -2
- {evolutionary_policy_optimization-0.3.1 → evolutionary_policy_optimization-0.3.5}/evolutionary_policy_optimization/__init__.py +1 -1
- {evolutionary_policy_optimization-0.3.1 → evolutionary_policy_optimization-0.3.5}/evolutionary_policy_optimization/env_wrappers.py +3 -4
- {evolutionary_policy_optimization-0.3.1 → evolutionary_policy_optimization-0.3.5}/evolutionary_policy_optimization/epo.py +11 -60
- {evolutionary_policy_optimization-0.3.1 → evolutionary_policy_optimization-0.3.5}/pyproject.toml +3 -2
- {evolutionary_policy_optimization-0.3.1 → evolutionary_policy_optimization-0.3.5}/.gitignore +0 -0
- {evolutionary_policy_optimization-0.3.1 → evolutionary_policy_optimization-0.3.5}/LICENSE +0 -0
- {evolutionary_policy_optimization-0.3.1 → evolutionary_policy_optimization-0.3.5}/README.md +0 -0
- {evolutionary_policy_optimization-0.3.1 → evolutionary_policy_optimization-0.3.5}/evolutionary_policy_optimization/distributed.py +0 -0
- {evolutionary_policy_optimization-0.3.1 → evolutionary_policy_optimization-0.3.5}/evolutionary_policy_optimization/experimental.py +0 -0
- {evolutionary_policy_optimization-0.3.1 → evolutionary_policy_optimization-0.3.5}/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.3.
|
|
3
|
+
Version: 0.3.5
|
|
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
|
|
@@ -33,13 +33,14 @@ Classifier: Intended Audience :: Developers
|
|
|
33
33
|
Classifier: License :: OSI Approved :: MIT License
|
|
34
34
|
Classifier: Programming Language :: Python :: 3.8
|
|
35
35
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
36
|
-
Requires-Python: >=3.
|
|
36
|
+
Requires-Python: >=3.10
|
|
37
37
|
Requires-Dist: accelerate>=1.6.0
|
|
38
38
|
Requires-Dist: assoc-scan>=0.0.2
|
|
39
39
|
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.0.7
|
|
43
44
|
Requires-Dist: torch>=2.2
|
|
44
45
|
Requires-Dist: tqdm
|
|
45
46
|
Requires-Dist: x-mlps-pytorch>=0.3.0
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
from evolutionary_policy_optimization.env_wrappers import GymnasiumEnvWrapper, rescale_from_to
|
|
2
|
-
from evolutionary_policy_optimization.epo import EPO, MLP, Actor, Agent,
|
|
2
|
+
from evolutionary_policy_optimization.epo import EPO, MLP, Actor, Agent, Beta, CategoricalActionDistr, Critic, LatentGenePool, create_agent
|
|
3
3
|
from evolutionary_policy_optimization.mock_env import Env, VectorEnv
|
|
@@ -5,9 +5,8 @@ from torch.nn import Module
|
|
|
5
5
|
|
|
6
6
|
from evolutionary_policy_optimization.epo import Agent, create_agent, exists
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
# e.g. beta actions on (0, 1) -> the env's action bounds
|
|
8
|
+
def rescale_from_to(x, from_range = (-1., 1.), to_range = (-1., 1.)):
|
|
9
|
+
# e.g. beta actions on (-1, 1) -> the env's action bounds
|
|
11
10
|
|
|
12
11
|
from_low, from_high = from_range
|
|
13
12
|
to_low, to_high = to_range
|
|
@@ -36,7 +35,7 @@ class GymnasiumEnvWrapper(Module):
|
|
|
36
35
|
return self.env.reset(*args, **kwargs)
|
|
37
36
|
|
|
38
37
|
def step(self, actions, *args, **kwargs):
|
|
39
|
-
#
|
|
38
|
+
# continuous actions are on (-1, 1) - rescale to env bounds at interface
|
|
40
39
|
|
|
41
40
|
if exists(self.rescale_to):
|
|
42
41
|
actions = rescale_from_to(actions, to_range = self.rescale_to)
|
|
@@ -15,15 +15,15 @@ import torch
|
|
|
15
15
|
import torch.distributed as dist
|
|
16
16
|
import torch.nn.functional as F
|
|
17
17
|
from accelerate import Accelerator
|
|
18
|
-
from
|
|
18
|
+
from torch.optim import AdamW
|
|
19
19
|
from assoc_scan import AssocScan
|
|
20
20
|
from einops import einsum, rearrange, reduce, repeat
|
|
21
21
|
from einops.layers.torch import Rearrange
|
|
22
22
|
from ema_pytorch import EMA
|
|
23
23
|
from hl_gauss_pytorch import HLGaussLayer
|
|
24
|
+
from mean_conc_beta import Beta
|
|
24
25
|
from torch import Tensor, cat, from_numpy, is_tensor, nn, stack, tensor
|
|
25
|
-
from torch.distributions import
|
|
26
|
-
|
|
26
|
+
from torch.distributions import Categorical, Distribution
|
|
27
27
|
from torch.nn import Linear, Module, ModuleList
|
|
28
28
|
from torch.utils._pytree import tree_map
|
|
29
29
|
from torch.utils.data import DataLoader, TensorDataset
|
|
@@ -545,7 +545,7 @@ class DiversityDiscr(Module):
|
|
|
545
545
|
|
|
546
546
|
# action distributions - the actor always returns a `Distribution`, either
|
|
547
547
|
# categorical (discrete) or beta mean-conc (continuous). beta is defined over
|
|
548
|
-
# (
|
|
548
|
+
# (-1, 1) - multiplied by some constant usually (e.g. 0.4) for the env action range
|
|
549
549
|
|
|
550
550
|
class CategoricalActionDistr(Module):
|
|
551
551
|
def forward(self, logits, temperature = 1.):
|
|
@@ -554,58 +554,6 @@ class CategoricalActionDistr(Module):
|
|
|
554
554
|
|
|
555
555
|
return Categorical(logits = logits)
|
|
556
556
|
|
|
557
|
-
class BetaActionDistr(Module):
|
|
558
|
-
def __init__(
|
|
559
|
-
self,
|
|
560
|
-
init_conc = 2.,
|
|
561
|
-
min_conc = 0.,
|
|
562
|
-
eps = 1e-5
|
|
563
|
-
):
|
|
564
|
-
super().__init__()
|
|
565
|
-
assert init_conc > min_conc
|
|
566
|
-
|
|
567
|
-
self.init_conc = init_conc
|
|
568
|
-
self.min_conc = min_conc
|
|
569
|
-
self.eps = eps
|
|
570
|
-
|
|
571
|
-
# softplus offset so the concentration at raw_conc = 0 is exactly init_conc
|
|
572
|
-
|
|
573
|
-
self.raw_init_conc = math.log(math.expm1(init_conc - min_conc))
|
|
574
|
-
|
|
575
|
-
def mean(self, params):
|
|
576
|
-
# the beta mean is exactly (tanh(raw_mean) + 1) / 2 by construction
|
|
577
|
-
|
|
578
|
-
raw_mean, _ = params.unbind(dim = -1)
|
|
579
|
-
return ((torch.tanh(raw_mean) + 1.) * 0.5).clamp(min = self.eps, max = 1. - self.eps)
|
|
580
|
-
|
|
581
|
-
def entropy(self, params, temperature = 1.):
|
|
582
|
-
# entropy is over the rescaled (2x - 1) in [-1, 1], with log 2 jacobian
|
|
583
|
-
# adjustment for the differential entropy of an affine transform
|
|
584
|
-
|
|
585
|
-
distr = self.forward(params, temperature = temperature)
|
|
586
|
-
return distr.entropy() + math.log(2.)
|
|
587
|
-
|
|
588
|
-
def forward(self, params, temperature = 1.):
|
|
589
|
-
_, raw_conc = params.unbind(dim = -1)
|
|
590
|
-
|
|
591
|
-
mean = self.mean(params)
|
|
592
|
-
|
|
593
|
-
conc = F.softplus(raw_conc + self.raw_init_conc) + self.min_conc
|
|
594
|
-
|
|
595
|
-
# concentration floor - unimodal (alpha > 1 and beta > 1), mean kept exact
|
|
596
|
-
|
|
597
|
-
conc = conc + 1. / torch.minimum(mean, 1. - mean).clamp(min = self.eps)
|
|
598
|
-
|
|
599
|
-
# temperature scales the concentration - lower temperature, sharper policy
|
|
600
|
-
|
|
601
|
-
if temperature > 0. and temperature != 1.:
|
|
602
|
-
conc = conc / temperature
|
|
603
|
-
|
|
604
|
-
alpha = mean * conc
|
|
605
|
-
beta = (1. - mean) * conc
|
|
606
|
-
|
|
607
|
-
return Beta(alpha, beta)
|
|
608
|
-
|
|
609
557
|
# self-predictive representations (SPR) over the actor's hidden embedding
|
|
610
558
|
|
|
611
559
|
class HiddenSpr(Module):
|
|
@@ -689,6 +637,7 @@ class Actor(Module):
|
|
|
689
637
|
state_norm: StateNorm | None = None,
|
|
690
638
|
dim_latent = 0,
|
|
691
639
|
action_is_continuous = False, # continuous control - beta policy
|
|
640
|
+
beta_kwargs: dict = dict(),
|
|
692
641
|
):
|
|
693
642
|
super().__init__()
|
|
694
643
|
|
|
@@ -720,7 +669,7 @@ class Actor(Module):
|
|
|
720
669
|
nn.Linear(dim, num_actions, bias = False),
|
|
721
670
|
)
|
|
722
671
|
|
|
723
|
-
self.action_distr =
|
|
672
|
+
self.action_distr = Beta(**beta_kwargs) if self.beta_actions else CategoricalActionDistr()
|
|
724
673
|
|
|
725
674
|
def latent(
|
|
726
675
|
self,
|
|
@@ -1079,6 +1028,8 @@ class LatentGenePool(Module):
|
|
|
1079
1028
|
should_update_per_island = self.should_run_genetic_algorithm(fitness)
|
|
1080
1029
|
|
|
1081
1030
|
if not should_update_per_island.any():
|
|
1031
|
+
self.advance_step_()
|
|
1032
|
+
|
|
1082
1033
|
if inplace:
|
|
1083
1034
|
return False, None
|
|
1084
1035
|
|
|
@@ -1229,13 +1180,13 @@ class Agent(Module):
|
|
|
1229
1180
|
actor: Actor,
|
|
1230
1181
|
critic: Critic,
|
|
1231
1182
|
latent_gene_pool: LatentGenePool | None,
|
|
1232
|
-
optim_klass =
|
|
1183
|
+
optim_klass = AdamW,
|
|
1233
1184
|
state_norm: StateNorm | None = None,
|
|
1234
1185
|
actor_lr = 8e-4,
|
|
1235
1186
|
critic_lr = 8e-4,
|
|
1236
1187
|
latent_lr = 1e-5,
|
|
1237
|
-
actor_weight_decay =
|
|
1238
|
-
critic_weight_decay =
|
|
1188
|
+
actor_weight_decay = 0.,
|
|
1189
|
+
critic_weight_decay = 0.,
|
|
1239
1190
|
diversity_aux_loss_weight = 0.,
|
|
1240
1191
|
use_critic_ema = True,
|
|
1241
1192
|
critic_ema_beta = 0.95,
|
{evolutionary_policy_optimization-0.3.1 → evolutionary_policy_optimization-0.3.5}/pyproject.toml
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "evolutionary-policy-optimization"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.5"
|
|
4
4
|
description = "EPO - Pytorch"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Phil Wang", email = "lucidrains@gmail.com" }
|
|
7
7
|
]
|
|
8
8
|
readme = "README.md"
|
|
9
|
-
requires-python = ">= 3.
|
|
9
|
+
requires-python = ">= 3.10"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
11
|
keywords = [
|
|
12
12
|
'artificial intelligence',
|
|
@@ -30,6 +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.0.7',
|
|
33
34
|
'torch>=2.2',
|
|
34
35
|
'tqdm',
|
|
35
36
|
"x-mlps-pytorch>=0.3.0",
|
{evolutionary_policy_optimization-0.3.1 → evolutionary_policy_optimization-0.3.5}/.gitignore
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|