SEA-pytorch 0.0.1__py3-none-any.whl
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.
SEA_pytorch/SEA.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import torch
|
|
4
|
+
from torch import nn, is_tensor, Tensor
|
|
5
|
+
from torch.nn import Module, ModuleList
|
|
6
|
+
import torch.nn.functional as F
|
|
7
|
+
|
|
8
|
+
# ein equations
|
|
9
|
+
|
|
10
|
+
import einx
|
|
11
|
+
from einops import rearrange, repeat, pack, unpack
|
|
12
|
+
from torch_einops_utils import cast_tensor
|
|
13
|
+
from torch_einops_utils.shape import size, shape
|
|
14
|
+
|
|
15
|
+
# functions
|
|
16
|
+
|
|
17
|
+
def exists(v):
|
|
18
|
+
return v is not None
|
|
19
|
+
|
|
20
|
+
def default(v, d):
|
|
21
|
+
return v if exists(v) else d
|
|
22
|
+
|
|
23
|
+
def cast_tuple(t, length = 1):
|
|
24
|
+
return t if isinstance(t, tuple) else ((t,) * length)
|
|
25
|
+
|
|
26
|
+
# truncated geometric sampling
|
|
27
|
+
|
|
28
|
+
def sample_truncated_geometric(
|
|
29
|
+
max_steps: Tensor | int,
|
|
30
|
+
discount: float | Tensor,
|
|
31
|
+
*,
|
|
32
|
+
allow_zero: bool = False,
|
|
33
|
+
sample_shape: tuple[int, ...] | int = (),
|
|
34
|
+
rand_uniform: Tensor | None = None,
|
|
35
|
+
device: torch.device | None = None,
|
|
36
|
+
generator: torch.Generator | None = None
|
|
37
|
+
) -> Tensor:
|
|
38
|
+
# device
|
|
39
|
+
|
|
40
|
+
device = default(device, next((t.device for t in (max_steps, discount, rand_uniform) if is_tensor(t)), None))
|
|
41
|
+
|
|
42
|
+
max_steps = cast_tensor(max_steps, device = device, dtype = torch.long)
|
|
43
|
+
discount = cast_tensor(discount, device = device, dtype = torch.float32)
|
|
44
|
+
|
|
45
|
+
assert ((discount >= 0.) & (discount <= 1.)).all(), 'discount must be in [0, 1]'
|
|
46
|
+
|
|
47
|
+
# uniform draws
|
|
48
|
+
|
|
49
|
+
out_shape = (*cast_tuple(sample_shape), *torch.broadcast_shapes(max_steps.shape, discount.shape))
|
|
50
|
+
|
|
51
|
+
if exists(rand_uniform):
|
|
52
|
+
out_shape = torch.broadcast_shapes(out_shape, rand_uniform.shape)
|
|
53
|
+
rand_uniform = rand_uniform.to(device = device, dtype = torch.float32).expand(out_shape)
|
|
54
|
+
else:
|
|
55
|
+
rand_uniform = torch.rand(out_shape, device = device, dtype = torch.float32, generator = generator)
|
|
56
|
+
|
|
57
|
+
# inverse cdf
|
|
58
|
+
|
|
59
|
+
num_steps = (max_steps + int(allow_zero)).clamp(min = 1)
|
|
60
|
+
max_zero_based = num_steps - 1
|
|
61
|
+
|
|
62
|
+
is_zero = discount == 0.
|
|
63
|
+
is_undiscounted = discount == 1.
|
|
64
|
+
|
|
65
|
+
safe_discount = torch.where(is_zero | is_undiscounted, 0.5, discount)
|
|
66
|
+
|
|
67
|
+
log_discount = torch.where(safe_discount < 0.5, safe_discount.log(), torch.log1p(safe_discount - 1.))
|
|
68
|
+
prob_reach = -torch.expm1(num_steps * log_discount)
|
|
69
|
+
|
|
70
|
+
delta = torch.where(
|
|
71
|
+
is_undiscounted,
|
|
72
|
+
rand_uniform * num_steps,
|
|
73
|
+
torch.log1p(-rand_uniform * prob_reach) / log_discount
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
delta = torch.where(is_zero, 0., delta)
|
|
77
|
+
|
|
78
|
+
# clamp before long cast
|
|
79
|
+
|
|
80
|
+
delta = delta.floor().clamp(min = 0.).minimum(max_zero_based).long().minimum(max_zero_based)
|
|
81
|
+
|
|
82
|
+
return delta if allow_zero else (delta + 1)
|
|
83
|
+
|
|
84
|
+
# classes
|
|
85
|
+
|
|
86
|
+
class SEA(Module):
|
|
87
|
+
def __init__(
|
|
88
|
+
self
|
|
89
|
+
):
|
|
90
|
+
super().__init__()
|
|
91
|
+
|
|
92
|
+
def forward(
|
|
93
|
+
self,
|
|
94
|
+
x
|
|
95
|
+
):
|
|
96
|
+
return x
|
SEA_pytorch/__init__.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: SEA-pytorch
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Explorations into Scaling Empowered Agents
|
|
5
|
+
Project-URL: Homepage, https://pypi.org/project/SEA-pytorch/
|
|
6
|
+
Project-URL: Repository, https://github.com/lucidrains/SEA-pytorch
|
|
7
|
+
Author-email: Phil Wang <lucidrains@gmail.com>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2026 Phil Wang
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Keywords: artificial intelligence,deep learning,empowerment,unsupervised skill discovery
|
|
31
|
+
Classifier: Development Status :: 4 - Beta
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
35
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
36
|
+
Requires-Python: >=3.10
|
|
37
|
+
Requires-Dist: einops>=0.8.1
|
|
38
|
+
Requires-Dist: einx>=0.4.0
|
|
39
|
+
Requires-Dist: torch-einops-utils>=0.2.8
|
|
40
|
+
Requires-Dist: torch>=2.5
|
|
41
|
+
Provides-Extra: examples
|
|
42
|
+
Provides-Extra: test
|
|
43
|
+
Requires-Dist: pytest; extra == 'test'
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## SEA-pytorch (wip)
|
|
48
|
+
|
|
49
|
+
Explorations into [Scaling Empowered Agents](https://arxiv.org/abs/2610.13002), from [Catherine Ji](https://cj7280.github.io/cathyji/) et al. of Benjamin Eysenbach's group
|
|
50
|
+
|
|
51
|
+
## Citations
|
|
52
|
+
|
|
53
|
+
```bibtex
|
|
54
|
+
@misc{ji2026scalingempoweredagents,
|
|
55
|
+
title = {Scaling Empowered Agents},
|
|
56
|
+
author = {Catherine Ji and Vivek Myers and Joshua Lin and Alexandra Wingate and Sergey Levine and Benjamin Eysenbach},
|
|
57
|
+
year = {2026},
|
|
58
|
+
eprint = {2610.13002},
|
|
59
|
+
archivePrefix = {arXiv},
|
|
60
|
+
primaryClass = {cs.AI},
|
|
61
|
+
url = {https://arxiv.org/abs/2610.13002},
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```bibtex
|
|
66
|
+
@misc{zheng2025mislflyanalysisingredients,
|
|
67
|
+
title = {Can a MISL Fly? Analysis and Ingredients for Mutual Information Skill Learning},
|
|
68
|
+
author = {Chongyi Zheng and Jens Tuyls and Joanne Peng and Benjamin Eysenbach},
|
|
69
|
+
year = {2025},
|
|
70
|
+
eprint = {2412.08021},
|
|
71
|
+
archivePrefix = {arXiv},
|
|
72
|
+
primaryClass = {cs.LG},
|
|
73
|
+
url = {https://arxiv.org/abs/2412.08021},
|
|
74
|
+
}
|
|
75
|
+
```
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
SEA_pytorch/SEA.py,sha256=FyTLT4ikttWX579cgcDWECwmvLlgsSqUFfmPHxtskMY,2646
|
|
2
|
+
SEA_pytorch/__init__.py,sha256=ZHECgn3pDX4yMbea5fKu_R89FIRkPXB61ADX_d2BzeI,72
|
|
3
|
+
sea_pytorch-0.0.1.dist-info/METADATA,sha256=pqIVv4qrWIUMmCn5ysej8o6FKoj4CO2jhTfaPIi_EJA,3144
|
|
4
|
+
sea_pytorch-0.0.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
5
|
+
sea_pytorch-0.0.1.dist-info/licenses/LICENSE,sha256=e6AOF7Z8EFdK3IdcL0x0fLw4cY7Q0d0kNR0o0TmBewM,1066
|
|
6
|
+
sea_pytorch-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Phil Wang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|