Skip to content

Bernhard add mean action - #541

Open
Kait0 wants to merge 42 commits into
3.0from
bernhard_add_mean_action
Open

Bernhard add mean action#541
Kait0 wants to merge 42 commits into
3.0from
bernhard_add_mean_action

Conversation

@Kait0

@Kait0 Kait0 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

The same PR as 536 before, but without my personal files:

Added the option to make the policy use either the mean, the mode, or a sample of the distribution instead of the mode during inference.
This required a fundamental design change.
Previously, the action representation was hardcoded in the simulator.

Now there are two options: one for the agent, either continuous or discrete, and one for the environment, either continuous or discrete (to avoid removing features).
The default now is:
env.action_type: continuous
policy.action_type: discrete

The default for eval is kept in mode so that there is no change in behavior with the default configuration.

In local eval eval_simulation: gigaflow
and default parameters, this improved the latest nightly model slightly:
mean: "avg_distance_per_infraction": 16646
mode: "avg_distance_per_infraction": 16127

I verified that these changes have no influence on training performance.

@Kait0 Kait0 mentioned this pull request Jul 27, 2026
Comment thread pufferlib/pufferl.py
Comment thread pufferlib/ocean/torch.py
Comment on lines +337 to +362
self.register_buffer(
"JERK_LONG",
torch.tensor((-15.0, -4.0, 0.0, 4.0), dtype=torch.float32, requires_grad=False),
persistent=False,
)
self.register_buffer(
"JERK_LAT", torch.tensor((-4.0, 0.0, 4.0), dtype=torch.float32, requires_grad=False), persistent=False
)

self.register_buffer(
"ACCELERATION_VALUES",
torch.tensor(
(-4.0000, -2.6670, -1.3330, -0.0000, 1.3330, 2.6670, 4.0000), dtype=torch.float32, requires_grad=False
),
persistent=False,
)
self.register_buffer(
"STEERING_VALUES",
torch.tensor(
(-0.667, -0.500, -0.333, -0.167, 0.000, 0.167, 0.333, 0.500, 0.667),
dtype=torch.float32,
requires_grad=False,
),
persistent=False,
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theses values should come directly from the BINDING defined in env_binding.h

@Kait0 Kait0 Jul 27, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you think that? These are method-specific hyperparameters.
Maybe the min and max possible values should come from the environment?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the min and max possible values should come from the environment? -> Yes, should have been more specific

// Jerk action space (for JERK dynamics model)
static const float JERK_LONG[4] = {-15.0f, -4.0f, 0.0f, 4.0f};
static const float JERK_LAT[3] = {-4.0f, 0.0f, 4.0f};

// Classic action space (for CLASSIC dynamics model)
static const float ACCELERATION_VALUES[7] = {-4.0000f, -2.6670f, -1.3330f, -0.0000f, 1.3330f, 2.6670f, 4.0000f};
static const float STEERING_VALUES[9] = {-0.667f, -0.500f, -0.333f, -0.167f, 0.000f, 0.167f, 0.333f, 0.500f, 0.667f};

We direclty want to use these variables here to avoid duplicate and potential errors

Comment thread pufferlib/ocean/torch.py Outdated
self.is_continuous = isinstance(env.single_action_space, pufferlib.spaces.Box)
self.is_continuous = (
action_type == "continuous"
) # TODO Check if what the `"trajectory"`, `"trajectory_frenet"`, `"trajectory_jerk" features do and if they are considered continuous.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove the comment about traj, it is a mistake from the README.md

Comment thread pufferlib/pytorch.py Outdated
action = logits.sample().view(batch, -1)
if deterministic:
if action_selection != ACTION_SELECT_SAMPLE:
action = logits.loc.view(batch, -1) # TODO - DETERMINISTIC use mean action for eval

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment seems obselete now

Comment thread pufferlib/config/puffer_drive.yaml Outdated
Comment thread pufferlib/config/puffer_drive.yaml Outdated
Comment thread pufferlib/config/puffer_drive.yaml Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants