-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Feature/leapp export integration #5105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
frlai
wants to merge
20
commits into
isaac-sim:develop
Choose a base branch
from
frlai:feature/leapp_export_integration
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8eaf56c
Add LEAPP export integration for manager-based RSL-RL environments
frlai d8f89a0
updated scripts to handle warp kernels
frlai 8c7c43d
leapp now automatically propagates into buffered values
frlai 450a7ab
changed i/o intercepting. added semantics to all the articulation data
frlai 1b821c0
propagated tensor semantics to all input datatypes
frlai ad6ac03
reorganized some files
frlai 03e6b0e
updated tensor semantics to create isaac lab connection. simplified s…
frlai 2ee62de
fix direct deployment for new env architecture
frlai e9a87d5
precommit updates
frlai 258772b
added changelogs and updated versions
frlai 68b34c9
added myself to contributors
frlai 4e9a558
fixed some comments
frlai 6705d80
added init, made leapp import lazy. leapp is no longer a hard require…
frlai c9d417f
added docs on exporting managed environments. added direct rl example…
frlai de9a7ac
updated docs for exporting direct deployment policies
frlai bc39385
minor cleanup adding docstrigs
frlai 0904877
added semantic annotations to the new pva dataclass
frlai cb2622c
added some import gaurds, improved code readability
frlai 98db172
added docstrings and addressed comments
frlai bb76135
moved file location, updated docs, fixed deploy.py bug with mapping e…
frlai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
262 changes: 262 additions & 0 deletions
262
docs/source/policy_deployment/05_leapp/exporting_policies_with_leapp.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,262 @@ | ||
| Exporting Policies with LEAPP | ||
| ============================= | ||
|
|
||
| .. currentmodule:: isaaclab | ||
|
|
||
| This guide covers how to export trained reinforcement learning policies from Isaac Lab using | ||
| `LEAPP <LEAPP_REPO_LINK_PLACEHOLDER>`_ (Lightweight Export Annotations for Policy Pipelines). | ||
| The main goal of the LEAPP export path is to package the policy together with the input and | ||
| output semantics needed for deployment, so downstream users do not need to reimplement Isaac Lab | ||
| observation preprocessing, action postprocessing, or recurrent-state handling by hand. | ||
|
|
||
|
frlai marked this conversation as resolved.
|
||
| In practice, this makes the exported policy a much better fit for Isaac deployment libraries. | ||
| Isaac Lab can already consume these exports through :class:`~envs.DirectDeploymentEnv`, and Isaac | ||
| ROS will add direct support for running LEAPP-exported policies in a future release. | ||
|
|
||
| .. note:: | ||
|
|
||
| This export path currently supports **manager-based RL environments** (``ManagerBasedRLEnv``) | ||
| trained with **RSL-RL** only. Other environments are not yet supported. | ||
|
|
||
|
|
||
| Prerequisites | ||
| ------------- | ||
|
|
||
| .. admonition:: TODO | ||
| :class: warning | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO Items: Multiple TODO admonitions should be tracked in an issue to ensure they're addressed before the feature is considered complete. Consider creating a tracking issue. |
||
| Installation instructions will be finalized once LEAPP is publicly released. | ||
|
|
||
| LEAPP requires Python >= 3.8 and PyTorch >= 2.6. Install it with: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| # PLACEHOLDER — replace with the actual install command once available | ||
| pip install leapp | ||
|
|
||
| Ensure you have a trained RSL-RL checkpoint before proceeding. The standard Isaac Lab | ||
| training workflow produces checkpoints under ``logs/rsl_rl/<experiment_name>/``. | ||
|
|
||
|
|
||
| Why Export with LEAPP | ||
| --------------------- | ||
|
|
||
| Running the export script generates a self-contained export directory alongside your | ||
| checkpoint (or at a custom path). The directory contains: | ||
|
|
||
| - **Exported model files** — ``.onnx`` (default) or ``.pt`` depending on the chosen backend. | ||
| - **Export metadata** — LEAPP records the semantic information and wiring needed by downstream | ||
| deployment runtimes. | ||
| - **Initial values** — a ``.safetensors`` file for any feedback state, such as recurrent hidden | ||
| state or last action. | ||
| - **A graph visualization** — a ``.png`` diagram of the pipeline (can be disabled). | ||
|
|
||
| The important outcome for Isaac deployment workflows is that the exported artifact preserves the | ||
| same dataflow that was used during training and inference inside Isaac Lab. That means downstream | ||
| consumers can run the policy without reconstructing observation ordering, command wiring, actuator | ||
| targets, or policy feedback loops themselves. | ||
|
|
||
| For a detailed description of LEAPP's generated artifacts and APIs, refer to the | ||
| `LEAPP documentation <LEAPP_REPO_LINK_PLACEHOLDER>`_. | ||
|
|
||
|
|
||
| Exporting a Policy | ||
| ------------------ | ||
|
|
||
| Use the RSL-RL export script to export a trained checkpoint: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| ./isaaclab.sh -p scripts/reinforcement_learning/leapp/rsl_rl/export.py \ | ||
| --task <TASK_NAME> \ | ||
| --checkpoint <PATH_TO_CHECKPOINT> | ||
|
|
||
| For example, to export a UR10 reach policy: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| ./isaaclab.sh -p scripts/reinforcement_learning/leapp/rsl_rl/export.py \ | ||
| --task Isaac-Reach-UR10-v0 \ | ||
| --checkpoint logs/rsl_rl/ur10_reach/< date timestamp >/model_4999.pt | ||
|
|
||
| By default, the export artifacts are saved in the same directory as the checkpoint. The | ||
| exported graph is named after the task. | ||
|
|
||
|
|
||
| CLI Options | ||
| ^^^^^^^^^^^ | ||
|
|
||
| The export script accepts the following LEAPP-specific arguments in addition to the standard | ||
| RSL-RL and AppLauncher arguments: | ||
|
|
||
| .. list-table:: | ||
| :widths: 30 15 55 | ||
| :header-rows: 1 | ||
|
|
||
| * - Argument | ||
| - Default | ||
| - Description | ||
| * - ``--export_task_name`` | ||
| - Task name | ||
| - Name for the exported graph and output directory. | ||
| * - ``--export_method`` | ||
| - ``onnx-dynamo`` | ||
| - Export backend. Choices: ``onnx-dynamo``, ``onnx-torchscript``, ``jit-script``, | ||
| ``jit-trace``. | ||
| * - ``--export_save_path`` | ||
| - Checkpoint dir | ||
| - Base directory for export output. | ||
| * - ``--validation_steps`` | ||
| - ``5`` | ||
| - Number of environment steps to run during the traced rollout. Set to ``0`` to skip | ||
| validation. | ||
| * - ``--disable_graph_visualization`` | ||
| - ``False`` | ||
| - Skip generating the pipeline graph PNG. | ||
|
|
||
| The script also accepts the standard ``--checkpoint``, ``--load_run``, ``--load_checkpoint``, | ||
| and ``--use_pretrained_checkpoint`` arguments for locating the trained model. | ||
|
|
||
|
|
||
| How It Works (High Level) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| The export script performs the following steps: | ||
|
|
||
| 1. **Creates the environment** with ``num_envs=1`` and loads the trained checkpoint. | ||
| 2. **Patches the environment** for export. This step injects annotations into the environment | ||
| so that tensor i/o to the pipeline are identified by LEAPP during execution. | ||
| 3. **Runs a short rollout** (controlled by ``--validation_steps``) with LEAPP tracing | ||
| active. During this rollout, LEAPP traces all tensor operations in the pipeline and automatically | ||
| builds an onnx file. | ||
| 4. **Compiles the graph** so the exported model and deployment metadata can be consumed by | ||
| downstream runtimes, and optionally validates that the exported model reproduces the traced | ||
| outputs. | ||
|
|
||
| The patching is transparent to the policy — no changes to your training code or environment | ||
| configuration are needed. | ||
|
|
||
| .. warning:: | ||
|
|
||
| LEAPP is designed to support a broad range of model architectures, but the current | ||
| implementation has a few important limitations: | ||
|
|
||
| - **Dynamic control flow** is not supported when the condition depends on runtime tensor | ||
| values, such as tensor-dependent ``if``, ``for``, or ``while`` logic. | ||
| - **Complex slicing** is not fully supported. Examples include dynamic masked indexing | ||
| using multiple traced tensors such as ``tensor[traced1, traced2]``. Slicing with constant values | ||
| or with a single traced tensor is supported such as ``tensor[mask]`` or ``tensor[1:5]``. | ||
| - **Critical traced operations must be written in PyTorch.** For this release, Warp and | ||
| NumPy operations cannot be traced by LEAPP. | ||
|
|
||
|
|
||
| Verifying an Export | ||
| ------------------- | ||
|
|
||
| After export, we recommend validating the result in three ways. | ||
|
|
||
| 1. **Use LEAPP's automatic verification on seen traced data.** | ||
| 2. **Inspect the generated graph visualization.** | ||
| 3. **Read the LEAPP log carefully, especially when the export fails or emits warnings.** | ||
|
|
||
| Automatic Verification on Seen Data | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| By default, Isaac Lab asks LEAPP to validate the exported model after compilation. LEAPP does | ||
| this by replaying the data it already saw during the traced rollout and checking that the | ||
| exported artifact reproduces the same outputs. | ||
|
|
||
| This is a strong first-line check because it is good at catching export-time issues such as: | ||
|
|
||
| - backend conversion problems | ||
| - unsupported or incorrectly lowered operators | ||
| - output shape or dtype mismatches | ||
| - numerical discrepancies between the original policy and the exported artifact | ||
| - recurrent or feedback-state handling mistakes that show up during replay | ||
|
|
||
| This validation is controlled by ``--validation_steps``. Setting it to a positive value gives | ||
| LEAPP rollout data to validate against. Setting it to ``0`` skips this automatic check, which | ||
| is useful for debugging but not recommended for normal export workflows. | ||
|
|
||
| Inspect the Graph Visualization | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| LEAPP can generate a diagram of the exported pipeline as part of ``compile_graph()``. Even when | ||
| automatic verification passes, it is still worth opening the diagram and doing a quick visual | ||
| inspection. | ||
|
|
||
| This is especially useful for catching structural issues such as: | ||
|
|
||
| - missing inputs or outputs | ||
| - unexpected extra nodes | ||
| - incorrect feedback edges | ||
| - naming mistakes that make deployment harder to reason about | ||
|
|
||
| You can disable the diagram with ``--disable_graph_visualization``, but we recommend keeping it | ||
| enabled while developing and validating a new export path. | ||
|
|
||
| Inspect the LEAPP Log | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| If something breaks, the LEAPP-generated log is usually the best place to determine exactly what | ||
| happened. Read it closely and pay attention to both hard errors and warnings. | ||
|
|
||
| The log is useful for diagnosing issues such as: | ||
|
|
||
| - export backend failures | ||
| - warnings about graph construction or validation | ||
| - missing metadata | ||
| - unsupported model patterns | ||
| - file generation problems | ||
|
|
||
| In practice, this should be your first stop when the export does not complete or when the output | ||
| artifacts do not look correct. | ||
|
|
||
|
|
||
| Export Backends | ||
| ^^^^^^^^^^^^^^^ | ||
|
|
||
| The ``--export_method`` argument controls how the policy network is serialized: | ||
|
|
||
| - **onnx-dynamo** (default) — Uses ``torch.onnx.dynamo_export``. Best compatibility with | ||
| modern PyTorch features. | ||
| - **onnx-torchscript** — Uses the legacy ``torch.onnx.export`` path. May be needed for | ||
| certain model architectures. | ||
| - **jit-script** / **jit-trace** — Produces TorchScript ``.pt`` files instead of ONNX. | ||
|
|
||
|
|
||
| Recurrent Policies | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| Recurrent policies (e.g., using GRU or LSTM memory) are supported automatically. The export | ||
| script detects recurrent hidden state in the RSL-RL policy, registers it as LEAPP feedback | ||
| state, and ensures it appears in the ``feedback_flow`` section of the output YAML. The | ||
| initial hidden state values are saved in the ``.safetensors`` file. | ||
|
|
||
|
|
||
| Running the Exported Policy in Simulation | ||
| ----------------------------------------- | ||
|
|
||
| Isaac Lab provides :class:`~envs.DirectDeploymentEnv` for running exported policies back in | ||
| simulation without the training infrastructure. This is the Isaac Lab deployment path for | ||
| LEAPP-exported policies and is useful for validating that the packaged policy still behaves | ||
| correctly when driven through the deployment stack instead of the training stack. | ||
|
|
||
| For direct deployment policies, see the | ||
| :doc:`direct deployment LEAPP export tutorial </source/tutorials/06_exporting/exporting_direct_deployment_policies_with_leapp>`. | ||
| That guide shows how to add LEAPP annotations to a direct RL environment so it can be | ||
| exported with ``scripts/reinforcement_learning/leapp/rsl_rl/export.py``. Direct | ||
| deployment policies are not currently supported by ``scripts/reinforcement_learning/leapp/deploy.py``. | ||
|
|
||
| .. admonition:: TODO | ||
| :class: warning | ||
|
|
||
| Add a link to the Isaac ROS feature that directly runs LEAPP-exported policies once that | ||
| documentation is available. | ||
|
|
||
|
|
||
| Further Reading | ||
| --------------- | ||
|
|
||
| - `LEAPP documentation and API reference <LEAPP_REPO_LINK_PLACEHOLDER>`_ | ||
| - :class:`~envs.DirectDeploymentEnv` API reference | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.