Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scripts/reinforcement_learning/leapp/export_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def add_common_export_args(parser: argparse.ArgumentParser, *, agent_default: st
parser.add_argument(
"--export_method",
type=str,
default="onnx-dynamo",
choices=["onnx-dynamo", "onnx-torchscript", "jit-script", "jit-trace"],
help="Method to export the policy",
default=None,
choices=["onnx-dynamo", "onnx-torchscript", "jit-script", "jit-trace", "pt2"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Suggestion · Api — Unrelated pt2 choice added without documentation

Adding "pt2" widens the accepted values of the public --export_method flag and is forwarded verbatim to patch_env_for_export, but it is unrelated to this change's stated purpose and appears in neither the help text nor the changelog fragment. Either drop it from this change or document it in the help string and changelog alongside the supporting backend support.

help="Method to export the policy. Defaults to onnx-dynamo.",
)
parser.add_argument(
"--export_save_path",
Expand Down
8 changes: 7 additions & 1 deletion scripts/reinforcement_learning/leapp/rl_games/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,17 @@ def export_rl_games_agent(
graph_name = args_cli.export_task_name if args_cli.export_task_name is not None else task_name

if isinstance(env.unwrapped, ManagerBasedRLEnv):
export_method = "onnx-dynamo" if args_cli.export_method is None else args_cli.export_method
patch_env_for_export(
env,
export_method=args_cli.export_method,
export_method=export_method,
required_obs_groups=_required_obs_groups(agent_cfg),
)
elif args_cli.export_method is not None:
raise ValueError(
"--export_method is only supported for manager-based environments. For direct environments, "
"set export_with directly in the annotate.output_tensors() call instead."
)

if isinstance(env.unwrapped.cfg, DirectMARLEnvCfg):
env = multi_agent_to_single_agent(env)
Expand Down
8 changes: 7 additions & 1 deletion scripts/reinforcement_learning/leapp/rsl_rl/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def export_rsl_rl_agent(
graph_name = args_cli.export_task_name if args_cli.export_task_name is not None else task_name

if isinstance(env.unwrapped, ManagerBasedRLEnv):
export_method = "onnx-dynamo" if args_cli.export_method is None else args_cli.export_method
# Patch only the observation groups consumed by the actor policy.
# This filters out the critic and teacher observation groups.
obs_groups_cfg = getattr(agent_cfg, "obs_groups", None)
Expand All @@ -279,9 +280,14 @@ def export_rsl_rl_agent(
required_obs_groups = {"policy"}
patch_env_for_export(
env,
export_method=args_cli.export_method,
export_method=export_method,
required_obs_groups=required_obs_groups,
)
elif args_cli.export_method is not None:
raise ValueError(
"--export_method is only supported for manager-based environments. For direct environments, "
"set export_with directly in the annotate.output_tensors() call instead."
)

env = RslRlVecEnvWrapper(env, clip_actions=agent_cfg.clip_actions)

Expand Down
9 changes: 8 additions & 1 deletion scripts/reinforcement_learning/leapp/sb3/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,18 @@ def export_sb3_agent(
try:
env = gym.make(args_cli.task, cfg=env_cfg, render_mode=None)
if not isinstance(env.unwrapped, ManagerBasedRLEnv):
if args_cli.export_method is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Warning · Implementation — SB3 direct-env error masks unsupported-environment message

SB3 LEAPP export does not support direct environments at all (the following NotImplementedError). Checking --export_method first replaces that accurate message with advice to "set export_with directly in the annotate.output_tensors() call", which cannot be followed here and implies direct export works for SB3. Raise the NotImplementedError first, or drop this extra check in the SB3 backend.

raise ValueError(
"--export_method is only supported for manager-based environments. For direct environments, "
"set export_with directly in the annotate.output_tensors() call instead."
)
raise NotImplementedError("SB3 LEAPP export currently supports manager-based environments only.")

export_method = "onnx-dynamo" if args_cli.export_method is None else args_cli.export_method

policy_node_name = ensure_env_spec_id(env)
graph_name = args_cli.export_task_name if args_cli.export_task_name is not None else task_name
patch_env_for_export(env, export_method=args_cli.export_method, required_obs_groups={"policy"})
patch_env_for_export(env, export_method=export_method, required_obs_groups={"policy"})

print(f"[INFO] Loading model checkpoint from: {checkpoint_path}")
agent = _load_agent(checkpoint_path, device=env.unwrapped.device)
Expand Down
8 changes: 7 additions & 1 deletion scripts/reinforcement_learning/leapp/skrl/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,13 @@ def export_skrl_agent(
graph_name = args_cli.export_task_name if args_cli.export_task_name is not None else task_name

if isinstance(env.unwrapped, ManagerBasedRLEnv):
patch_env_for_export(env, export_method=args_cli.export_method, required_obs_groups={"policy"})
export_method = "onnx-dynamo" if args_cli.export_method is None else args_cli.export_method
patch_env_for_export(env, export_method=export_method, required_obs_groups={"policy"})
elif args_cli.export_method is not None:
raise ValueError(
"--export_method is only supported for manager-based environments. For direct environments, "
"set export_with directly in the annotate.output_tensors() call instead."
)

if isinstance(env.unwrapped.cfg, DirectMARLEnvCfg) and algorithm in ["ppo"]:
env = multi_agent_to_single_agent(env)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fixed
^^^^^

* Raised an error when ``--export_method`` is used to export a direct RL environment with LEAPP.
Loading