Skip to content

Commit f75540f

Browse files
committed
Merge branch 'scalar_loss' of github.com:UT-Austin-RPL/amago into scalar_loss
2 parents 382134b + 685eda3 commit f75540f

9 files changed

Lines changed: 103 additions & 67 deletions

amago/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
__version__ = "3.1.2"
1+
from importlib.metadata import version, PackageNotFoundError
2+
3+
try:
4+
__version__ = version("amago")
5+
except PackageNotFoundError:
6+
__version__ = "unknown"
27

38
from .experiment import Experiment
49
from .agent import Agent, register_agent, get_agent_cls, list_registered_agents

amago/agent.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,9 +1234,7 @@ def __init__(
12341234
actor_type: Type[actor_critic.BaseActorHead] = actor_critic.Actor,
12351235
critic_type: Type[actor_critic.BaseCriticHead] = actor_critic.NCriticsTwoHot,
12361236
pass_obs_keys_to_actor: Optional[Iterable[str]] = None,
1237-
dpg_temperature: float = 1.0,
12381237
):
1239-
self.dpg_temperature = dpg_temperature
12401238
super().__init__(
12411239
obs_space=obs_space,
12421240
rl2_space=rl2_space,
@@ -1502,9 +1500,7 @@ def forward(self, batch: Batch, log_step: bool):
15021500
a_agent_dpg = torch.stack([a_dist.rsample() for _ in range(K_a)], dim=0)
15031501
q_s_a_agent = self.maximized_critics(s_rep.detach(), a_agent_dpg)
15041502
q_s_a_agent = self.popart.normalize_values(
1505-
self.maximized_critics.bin_dist_to_raw_vals(
1506-
q_s_a_agent, temperature=self.dpg_temperature
1507-
).mean(0).min(2).values
1503+
self.maximized_critics.bin_dist_to_raw_vals(q_s_a_agent).mean(0).min(2).values
15081504
)
15091505
actor_loss += self.online_coeff * -(q_s_a_agent[:, :-1, ...])
15101506

amago/nets/actor_critic.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -600,25 +600,18 @@ def critic_network_forward(
600600
)
601601
return pyd.Categorical(logits=outputs)
602602

603-
def bin_dist_to_raw_vals(
604-
self, bin_dist: pyd.Categorical, temperature: float = 1.0
605-
) -> torch.Tensor:
603+
def bin_dist_to_raw_vals(self, bin_dist: pyd.Categorical) -> torch.Tensor:
606604
"""Convert a categorical distribution over bins to a scalar.
607605
608606
Args:
609607
bin_dist: The categorical distribution over bins (output of `forward`).
610-
temperature: Temperature for softening the distribution.
611608
612609
Returns:
613610
The scalar value.
614611
"""
615612
assert isinstance(bin_dist, pyd.Categorical)
616-
if temperature == 1.0:
617-
probs = bin_dist.probs
618-
else:
619-
probs = torch.softmax(bin_dist.logits / temperature, dim=-1)
620-
bin_vals = self.bin_vals.to(probs.device, dtype=probs.dtype)
621-
exp_val = (probs * bin_vals).sum(-1, keepdims=True)
613+
bin_vals = self.bin_vals.to(bin_dist.probs.device, dtype=bin_dist.probs.dtype)
614+
exp_val = (bin_dist.probs * bin_vals).sum(-1, keepdims=True)
622615
return self.invert_bins(exp_val)
623616

624617
def raw_vals_to_labels(self, raw_td_target: torch.Tensor) -> torch.Tensor:

docs/api/amago.agent.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ amago.agent
1010

1111
binary_filter
1212
exp_filter
13+
register_agent
14+
get_agent_cls
15+
list_registered_agents
16+
nstep_return
1317

1418
.. rubric:: Classes
1519

1620
.. autosummary::
1721

22+
BaseAgent
1823
Agent
1924
MultiTaskAgent
2025
Multigammas

docs/api/amago.envs.exploration.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ amago.envs.exploration
44
.. automodule:: amago.envs.exploration
55

66

7+
.. rubric:: Functions
8+
9+
.. autosummary::
10+
11+
register_exploration
12+
get_exploration_cls
13+
list_registered_explorations
14+
715
.. rubric:: Classes
816

917
.. autosummary::
1018

11-
BilevelEpsilonGreedy
12-
EpsilonGreedy
1319
ExplorationWrapper
20+
EpsilonGreedy
21+
BilevelEpsilonGreedy
1422

docs/api/amago.nets.traj_encoders.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ amago.nets.traj\_encoders
44
.. automodule:: amago.nets.traj_encoders
55

66

7+
.. rubric:: Functions
8+
9+
.. autosummary::
10+
11+
register_traj_encoder
12+
get_traj_encoder_cls
13+
list_registered_traj_encoders
14+
715
.. rubric:: Classes
816

917
.. autosummary::
1018

19+
TrajEncoder
1120
FFTrajEncoder
1221
GRUTrajEncoder
13-
MambaTrajEncoder
1422
TformerTrajEncoder
15-
TrajEncoder
23+
MambaTrajEncoder
1624

docs/api/amago.nets.tstep_encoders.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ amago.nets.tstep\_encoders
44
.. automodule:: amago.nets.tstep_encoders
55

66

7+
.. rubric:: Functions
8+
9+
.. autosummary::
10+
11+
register_tstep_encoder
12+
get_tstep_encoder_cls
13+
list_registered_tstep_encoders
14+
715
.. rubric:: Classes
816

917
.. autosummary::
1018

11-
CNNTstepEncoder
12-
FFTstepEncoder
1319
TstepEncoder
20+
FFTstepEncoder
21+
CNNTstepEncoder
1422

pyproject.toml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "amago"
7+
version = "3.2.0"
8+
description = "off-policy RL on long sequences"
9+
readme = { file = "README.md", content-type = "text/markdown" }
10+
authors = [
11+
{ name = "Jake Grigsby", email = "grigsby@cs.utexas.edu" }
12+
]
13+
license = "MIT"
14+
license-files = ["LICENSE"]
15+
requires-python = ">=3.10"
16+
classifiers = [
17+
"Development Status :: 4 - Beta",
18+
"Intended Audience :: Science/Research",
19+
"Programming Language :: Python",
20+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
21+
]
22+
keywords = ["reinforcement-learning", "memory", "transformers", "machine-learning"]
23+
dependencies = [
24+
"gymnasium>=0.26,<=0.29.1",
25+
"torch>=2.5,<3",
26+
"numpy>=1.21,<3",
27+
"gin-config",
28+
"wandb",
29+
"einops",
30+
"tqdm",
31+
"gym",
32+
"accelerate>=1.0",
33+
"termcolor",
34+
]
35+
36+
[project.optional-dependencies]
37+
envs = [
38+
"metaworld @ git+https://github.com/Farama-Foundation/Metaworld.git@04be337a12305e393c0caf0cbf5ec7755c7c8feb",
39+
"cython<3",
40+
"popgym",
41+
"minigrid",
42+
"stable-retro",
43+
"dm_env",
44+
"dm_alchemy @ git+https://github.com/deepmind/dm_alchemy.git",
45+
"gymnax",
46+
"matplotlib",
47+
"opencv-python",
48+
"procgen",
49+
"ale_py>=0.10",
50+
]
51+
flash = ["ninja", "packaging", "flash-attn"]
52+
mamba = ["causal-conv1d>=1.1.0", "mamba-ssm"]
53+
54+
[project.urls]
55+
Repository = "https://github.com/UT-Austin-RPL/amago"
56+
57+
[tool.setuptools.packages.find]
58+
include = ["amago*"]

setup.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)