import{s as ss,n as ts,o as as}from"../chunks/scheduler.eb244325.js";import{S as es,i as ns,e as J,s as e,c as p,h as ps,a as j,d as t,b as n,f as Ol,g as i,j as r,k as ls,l as is,m as a,n as M,t as o,o as y,p as c}from"../chunks/index.3fe63ad3.js";import{C as Ms}from"../chunks/CopyLLMTxtMenu.88bde5f2.js";import{C as T}from"../chunks/CodeBlock.934d290d.js";import{H as w,E as os}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.341974a5.js";function ys(Ql){let U,sl,O,tl,m,al,u,el,I,Yl="This tutorial explains how to integrate your own custom policy implementations into the LeRobot ecosystem, allowing you to leverage all LeRobot tools for training, evaluation, and deployment while using your own algorithms.",nl,b,pl,d,zl="Your custom policy should be organized as an installable Python package following LeRobot’s plugin conventions.",il,h,Ml,f,Sl="Create a package with the prefix <code>lerobot_policy_</code> (IMPORTANT!) followed by your policy name:",ol,C,yl,B,cl,G,Rl="Set up your <code>pyproject.toml</code>:",Jl,_,jl,g,rl,Z,El=`Create a configuration class that inherits from <a href="https://github.com/huggingface/lerobot/blob/main/src/lerobot/configs/policies.py" rel="nofollow"><code>PreTrainedConfig</code></a> and registers your policy type:
Here is a template to get you started, customize the parameters and methods as needed for your policy’s architecture and training requirements.`,wl,A,Ul,N,Tl,k,Hl='Create your policy implementation by inheriting from <a href="https://github.com/huggingface/lerobot/blob/main/src/lerobot/policies/pretrained.py" rel="nofollow"><code>PreTrainedPolicy</code></a>:',ml,X,ul,W,Il,V,Fl='Create processor functions. For a concrete reference, see <a href="https://github.com/huggingface/lerobot/blob/main/src/lerobot/policies/act/processor_act.py" rel="nofollow">processor_act.py</a> or <a href="https://github.com/huggingface/lerobot/blob/main/src/lerobot/policies/diffusion/processor_diffusion.py" rel="nofollow">processor_diffusion.py</a>.',bl,v,dl,$,xl="<strong>Important - function naming:</strong> LeRobot discovers your processor by name. The function <strong>must</strong> be called <code>make_{policy_name}_pre_post_processors</code> (matching the string you passed to <code>@PreTrainedConfig.register_subclass</code>).",hl,Q,fl,Y,ql="Expose your classes in the package’s <code>__init__.py</code>:",Cl,z,Bl,S,Gl,R,_l,E,gl,H,Zl,F,Pl="Once installed, your policy automatically integrates with LeRobot’s training and evaluation tools:",Al,x,Nl,q,kl,P,Ll="Check out these example policy implementations:",Xl,L,Dl='<li><a href="https://github.com/danielsanjosepro/lerobot_policy_ditflow" rel="nofollow">DiTFlow Policy</a> - Diffusion Transformer policy with flow-matching objective. Try it out in this example: <a href="https://github.com/danielsanjosepro/test_lerobot_policy_ditflow" rel="nofollow">DiTFlow Example</a></li>',Wl,D,Kl="Share your policy implementations with the community! 🤗",Vl,K,vl,ll,$l;return m=new Ms({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),u=new w({props:{title:"Bring Your Own Policies",local:"bring-your-own-policies",headingTag:"h1"}}),b=new w({props:{title:"Step 1: Create a Policy Package",local:"step-1-create-a-policy-package",headingTag:"h2"}}),h=new w({props:{title:"Package Structure",local:"package-structure",headingTag:"h3"}}),C=new T({props:{code:"bGVyb2JvdF9wb2xpY3lfbXlfY3VzdG9tX3BvbGljeSUyRiUwQSVFMiU5NCU5QyVFMiU5NCU4MCVFMiU5NCU4MCUyMHB5cHJvamVjdC50b21sJTBBJUUyJTk0JTk0JUUyJTk0JTgwJUUyJTk0JTgwJTIwc3JjJTJGJTBBJTIwJTIwJTIwJTIwJUUyJTk0JTk0JUUyJTk0JTgwJUUyJTk0JTgwJTIwbGVyb2JvdF9wb2xpY3lfbXlfY3VzdG9tX3BvbGljeSUyRiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCVFMiU5NCU5QyVFMiU5NCU4MCVFMiU5NCU4MCUyMF9faW5pdF9fLnB5JTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJUUyJTk0JTlDJUUyJTk0JTgwJUUyJTk0JTgwJTIwY29uZmlndXJhdGlvbl9teV9jdXN0b21fcG9saWN5LnB5JTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJUUyJTk0JTlDJUUyJTk0JTgwJUUyJTk0JTgwJTIwbW9kZWxpbmdfbXlfY3VzdG9tX3BvbGljeS5weSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCVFMiU5NCU5NCVFMiU5NCU4MCVFMiU5NCU4MCUyMHByb2Nlc3Nvcl9teV9jdXN0b21fcG9saWN5LnB5",highlighted:`lerobot_policy_my_custom_policy/
├── pyproject.toml
└── src/
    └── lerobot_policy_my_custom_policy/
        ├── __init__.py
        ├── configuration_my_custom_policy.py
        ├── modeling_my_custom_policy.py
        └── processor_my_custom_policy.py`,wrap:!1}}),B=new w({props:{title:"Package Configuration",local:"package-configuration",headingTag:"h3"}}),_=new T({props:{code:"JTVCcHJvamVjdCU1RCUwQW5hbWUlMjAlM0QlMjAlMjJsZXJvYm90X3BvbGljeV9teV9jdXN0b21fcG9saWN5JTIyJTBBdmVyc2lvbiUyMCUzRCUyMCUyMjAuMS4wJTIyJTBBZGVwZW5kZW5jaWVzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTIzJTIweW91ciUyMHBvbGljeS1zcGVjaWZpYyUyMGRlcGVuZGVuY2llcyUwQSU1RCUwQXJlcXVpcmVzLXB5dGhvbiUyMCUzRCUyMCUyMiUzRSUzRCUyMDMuMTIlMjIlMEElMEElNUJidWlsZC1zeXN0ZW0lNUQlMEFidWlsZC1iYWNrZW5kJTIwJTNEJTIwJTIzJTIweW91ci1idWlsZC1iYWNrZW5kJTBBcmVxdWlyZXMlMjAlM0QlMjAlMjMlMjB5b3VyLWJ1aWxkLXN5c3RlbQ==",highlighted:`<span class="hljs-section">[project]</span>
<span class="hljs-attr">name</span> = <span class="hljs-string">&quot;lerobot_policy_my_custom_policy&quot;</span>
<span class="hljs-attr">version</span> = <span class="hljs-string">&quot;0.1.0&quot;</span>
<span class="hljs-attr">dependencies</span> = [
    <span class="hljs-comment"># your policy-specific dependencies</span>
]
<span class="hljs-attr">requires-python</span> = <span class="hljs-string">&quot;&gt;= 3.12&quot;</span>

<span class="hljs-section">[build-system]</span>
build-backend = <span class="hljs-comment"># your-build-backend</span>
requires = <span class="hljs-comment"># your-build-system</span>`,wrap:!1}}),g=new w({props:{title:"Step 2: Define the Policy Configuration",local:"step-2-define-the-policy-configuration",headingTag:"h2"}}),A=new T({props:{code:" ",highlighted:`<span class="hljs-comment"># configuration_my_custom_policy.py</span>
<span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> dataclass, field
<span class="hljs-keyword">from</span> lerobot.configs <span class="hljs-keyword">import</span> PreTrainedConfig
<span class="hljs-keyword">from</span> lerobot.optim <span class="hljs-keyword">import</span> AdamWConfig
<span class="hljs-keyword">from</span> lerobot.optim <span class="hljs-keyword">import</span> CosineDecayWithWarmupSchedulerConfig

<span class="hljs-meta">@PreTrainedConfig.register_subclass(<span class="hljs-params"><span class="hljs-string">&quot;my_custom_policy&quot;</span></span>)</span>
<span class="hljs-meta">@dataclass</span>
<span class="hljs-keyword">class</span> <span class="hljs-title class_">MyCustomPolicyConfig</span>(<span class="hljs-title class_ inherited__">PreTrainedConfig</span>):
    <span class="hljs-string">&quot;&quot;&quot;Configuration class for MyCustomPolicy.

    Args:
        n_obs_steps: Number of observation steps to use as input
        horizon: Action prediction horizon
        n_action_steps: Number of action steps to execute
        hidden_dim: Hidden dimension for the policy network
        # Add your policy-specific parameters here
    &quot;&quot;&quot;</span>

    horizon: <span class="hljs-built_in">int</span> = <span class="hljs-number">50</span>
    n_action_steps: <span class="hljs-built_in">int</span> = <span class="hljs-number">50</span>
    hidden_dim: <span class="hljs-built_in">int</span> = <span class="hljs-number">256</span>

    optimizer_lr: <span class="hljs-built_in">float</span> = <span class="hljs-number">1e-4</span>
    optimizer_weight_decay: <span class="hljs-built_in">float</span> = <span class="hljs-number">1e-4</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__post_init__</span>(<span class="hljs-params">self</span>):
        <span class="hljs-built_in">super</span>().__post_init__()
        <span class="hljs-keyword">if</span> self.n_action_steps &gt; self.horizon:
            <span class="hljs-keyword">raise</span> ValueError(<span class="hljs-string">&quot;n_action_steps cannot exceed horizon&quot;</span>)

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">validate_features</span>(<span class="hljs-params">self</span>) -&gt; <span class="hljs-literal">None</span>:
        <span class="hljs-string">&quot;&quot;&quot;Validate input/output feature compatibility.&quot;&quot;&quot;</span>
        <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> self.image_features:
            <span class="hljs-keyword">raise</span> ValueError(<span class="hljs-string">&quot;MyCustomPolicy requires at least one image feature.&quot;</span>)
        <span class="hljs-keyword">if</span> self.action_feature <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:
            <span class="hljs-keyword">raise</span> ValueError(<span class="hljs-string">&quot;MyCustomPolicy requires &#x27;action&#x27; in output_features.&quot;</span>)

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_optimizer_preset</span>(<span class="hljs-params">self</span>) -&gt; AdamWConfig:
        <span class="hljs-keyword">return</span> AdamWConfig(lr=self.optimizer_lr, weight_decay=self.optimizer_weight_decay)

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_scheduler_preset</span>(<span class="hljs-params">self</span>):
        <span class="hljs-keyword">return</span> <span class="hljs-literal">None</span>

<span class="hljs-meta">    @property</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">observation_delta_indices</span>(<span class="hljs-params">self</span>) -&gt; <span class="hljs-built_in">list</span>[<span class="hljs-built_in">int</span>] | <span class="hljs-literal">None</span>:
        <span class="hljs-string">&quot;&quot;&quot;Relative timestep offsets the dataset loader provides per observation.

        Return \`None\` for single-frame policies. For temporal policies that consume
        multiple past or future frames, return a list of offsets, e.g. \`[-20, -10, 0, 10]\` for
        3 past frames at stride 10 and 1 future frame at stride 10.
        &quot;&quot;&quot;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-literal">None</span>

<span class="hljs-meta">    @property</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">action_delta_indices</span>(<span class="hljs-params">self</span>) -&gt; <span class="hljs-built_in">list</span>[<span class="hljs-built_in">int</span>]:
        <span class="hljs-string">&quot;&quot;&quot;Relative timestep offsets for the action chunk the dataset loader returns.
        &quot;&quot;&quot;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">list</span>(<span class="hljs-built_in">range</span>(self.horizon))

<span class="hljs-meta">    @property</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">reward_delta_indices</span>(<span class="hljs-params">self</span>) -&gt; <span class="hljs-literal">None</span>:
        <span class="hljs-keyword">return</span> <span class="hljs-literal">None</span>`,wrap:!1}}),N=new w({props:{title:"Step 3: Implement the Policy Class",local:"step-3-implement-the-policy-class",headingTag:"h2"}}),X=new T({props:{code:"JTIzJTIwbW9kZWxpbmdfbXlfY3VzdG9tX3BvbGljeS5weSUwQWltcG9ydCUyMHRvcmNoJTBBaW1wb3J0JTIwdG9yY2gubm4lMjBhcyUyMG5uJTBBZnJvbSUyMHR5cGluZyUyMGltcG9ydCUyMEFueSUwQSUwQWZyb20lMjBsZXJvYm90LnBvbGljaWVzJTIwaW1wb3J0JTIwUHJlVHJhaW5lZFBvbGljeSUwQWZyb20lMjBsZXJvYm90LnV0aWxzLmNvbnN0YW50cyUyMGltcG9ydCUyMEFDVElPTiUwQWZyb20lMjAuY29uZmlndXJhdGlvbl9teV9jdXN0b21fcG9saWN5JTIwaW1wb3J0JTIwTXlDdXN0b21Qb2xpY3lDb25maWclMEElMEFjbGFzcyUyME15Q3VzdG9tUG9saWN5KFByZVRyYWluZWRQb2xpY3kpJTNBJTBBJTIwJTIwJTIwJTIwY29uZmlnX2NsYXNzJTIwJTNEJTIwTXlDdXN0b21Qb2xpY3lDb25maWclMjAlMjAlMjMlMjBtdXN0JTIwbWF0Y2glMjB0aGUlMjBzdHJpbmclMjBpbiUyMCU0MHJlZ2lzdGVyX3N1YmNsYXNzJTBBJTIwJTIwJTIwJTIwbmFtZSUyMCU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JTIwdG9yY2guVGVuc29yJTVEKSUyMC0lM0UlMjBkaWN0JTVCc3RyJTJDJTIwdG9yY2guVGVuc29yJTVEJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyJTIyJTIyQ29tcHV0ZSUyMHRoZSUyMHRyYWluaW5nJTIwbG9zcy4lMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlNjBiYXRjaCU1QiUyMmFjdGlvbl9pc19wYWQlMjIlNUQlNjAlMjBpcyUyMGElMjBib29sJTIwbWFzayUyMG9mJTIwc2hhcGUlMjAoQiUyQyUyMGhvcml6b24pJTIwdGhhdCUyMG1hcmtzJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdGltZXN0ZXBzJTIwcGFkZGVkJTIwYmVjYXVzZSUyMHRoZSUyMGVwaXNvZGUlMjBlbmRlZCUyMGJlZm9yZSUyMCU2MGhvcml6b24lNjAlMjBzdGVwcyUyQyUyMHlvdSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGNhbiUyMGV4Y2x1ZGUlMjB0aG9zZSUyMGZyb20lMjB5b3VyJTIwbG9zcy4lMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjIlMjIlMjIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhY3Rpb25zJTIwJTNEJTIwYmF0Y2glNUJBQ1RJT04lNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhY3Rpb25faXNfcGFkJTIwJTNEJTIwYmF0Y2guZ2V0KCUyMmFjdGlvbl9pc19wYWQlMjIpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwLi4uJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmV0dXJuJTIwJTdCJTIybG9zcyUyMiUzQSUyMC4uLiU3RA==",highlighted:`<span class="hljs-comment"># modeling_my_custom_policy.py</span>
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> torch.nn <span class="hljs-keyword">as</span> nn
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> <span class="hljs-type">Any</span>

<span class="hljs-keyword">from</span> lerobot.policies <span class="hljs-keyword">import</span> PreTrainedPolicy
<span class="hljs-keyword">from</span> lerobot.utils.constants <span class="hljs-keyword">import</span> ACTION
<span class="hljs-keyword">from</span> .configuration_my_custom_policy <span class="hljs-keyword">import</span> MyCustomPolicyConfig

<span class="hljs-keyword">class</span> <span class="hljs-title class_">MyCustomPolicy</span>(<span class="hljs-title class_ inherited__">PreTrainedPolicy</span>):
    config_class = MyCustomPolicyConfig  <span class="hljs-comment"># must match the string in @register_subclass</span>
    name = <span class="hljs-string">&quot;my_custom_policy&quot;</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, config: MyCustomPolicyConfig, dataset_stats: <span class="hljs-built_in">dict</span>[<span class="hljs-built_in">str</span>, <span class="hljs-type">Any</span>] = <span class="hljs-literal">None</span></span>):
        <span class="hljs-built_in">super</span>().__init__(config, dataset_stats)
        config.validate_features()  <span class="hljs-comment"># not called automatically by the base class</span>
        self.config = config
        self.model = ...  <span class="hljs-comment"># your nn.Module here</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">reset</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">&quot;&quot;&quot;Reset episode state.&quot;&quot;&quot;</span>
        ...

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_optim_params</span>(<span class="hljs-params">self</span>) -&gt; <span class="hljs-built_in">dict</span>:
        <span class="hljs-string">&quot;&quot;&quot;Return parameters to pass to the optimizer (e.g. with per-group lr/wd).&quot;&quot;&quot;</span>
        <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;params&quot;</span>: self.parameters()}

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">predict_action_chunk</span>(<span class="hljs-params">self, batch: <span class="hljs-built_in">dict</span>[<span class="hljs-built_in">str</span>, torch.Tensor], **kwargs</span>) -&gt; torch.Tensor:
        <span class="hljs-string">&quot;&quot;&quot;Return the full action chunk (B, chunk_size, action_dim) for the current observation.&quot;&quot;&quot;</span>
        ...

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">select_action</span>(<span class="hljs-params">self, batch: <span class="hljs-built_in">dict</span>[<span class="hljs-built_in">str</span>, torch.Tensor], **kwargs</span>) -&gt; torch.Tensor:
        <span class="hljs-string">&quot;&quot;&quot;Return a single action for the current timestep (called at inference).&quot;&quot;&quot;</span>
        ...

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, batch: <span class="hljs-built_in">dict</span>[<span class="hljs-built_in">str</span>, torch.Tensor]</span>) -&gt; <span class="hljs-built_in">dict</span>[<span class="hljs-built_in">str</span>, torch.Tensor]:
        <span class="hljs-string">&quot;&quot;&quot;Compute the training loss.

        \`batch[&quot;action_is_pad&quot;]\` is a bool mask of shape (B, horizon) that marks
        timesteps padded because the episode ended before \`horizon\` steps, you
        can exclude those from your loss.
        &quot;&quot;&quot;</span>
        actions = batch[ACTION]
        action_is_pad = batch.get(<span class="hljs-string">&quot;action_is_pad&quot;</span>)
        ...
        <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;loss&quot;</span>: ...}`,wrap:!1}}),W=new w({props:{title:"Step 4: Add Data Processors",local:"step-4-add-data-processors",headingTag:"h2"}}),v=new T({props:{code:"JTIzJTIwcHJvY2Vzc29yX215X2N1c3RvbV9wb2xpY3kucHklMEFmcm9tJTIwdHlwaW5nJTIwaW1wb3J0JTIwQW55JTBBaW1wb3J0JTIwdG9yY2glMEElMEFmcm9tJTIwbGVyb2JvdC5wcm9jZXNzb3IlMjBpbXBvcnQlMjBQb2xpY3lBY3Rpb24lMkMlMjBQb2xpY3lQcm9jZXNzb3JQaXBlbGluZSUwQSUwQSUwQWRlZiUyMG1ha2VfbXlfY3VzdG9tX3BvbGljeV9wcmVfcG9zdF9wcm9jZXNzb3JzKCUwQSUyMCUyMCUyMCUyMGNvbmZpZyUyQyUwQSUyMCUyMCUyMCUyMGRhdGFzZXRfc3RhdHMlM0ElMjBkaWN0JTVCc3RyJTJDJTIwZGljdCU1QnN0ciUyQyUyMHRvcmNoLlRlbnNvciU1RCU1RCUyMCU3QyUyME5vbmUlMjAlM0QlMjBOb25lJTJDJTBBKSUyMC0lM0UlMjB0dXBsZSU1QiUwQSUyMCUyMCUyMCUyMFBvbGljeVByb2Nlc3NvclBpcGVsaW5lJTVCZGljdCU1QnN0ciUyQyUyMEFueSU1RCUyQyUyMGRpY3QlNUJzdHIlMkMlMjBBbnklNUQlNUQlMkMlMEElMjAlMjAlMjAlMjBQb2xpY3lQcm9jZXNzb3JQaXBlbGluZSU1QlBvbGljeUFjdGlvbiUyQyUyMFBvbGljeUFjdGlvbiU1RCUyQyUwQSU1RCUzQSUwQSUyMCUyMCUyMCUyMHByZXByb2Nlc3NvciUyMCUzRCUyMC4uLiUyMCUyMCUyMCUyMyUyMGJ1aWxkJTIweW91ciUyMFBvbGljeVByb2Nlc3NvclBpcGVsaW5lJTIwZm9yJTIwaW5wdXRzJTBBJTIwJTIwJTIwJTIwcG9zdHByb2Nlc3NvciUyMCUzRCUyMC4uLiUyMCUyMCUyMyUyMGJ1aWxkJTIweW91ciUyMFBvbGljeVByb2Nlc3NvclBpcGVsaW5lJTIwZm9yJTIwb3V0cHV0cyUwQSUyMCUyMCUyMCUyMHJldHVybiUyMHByZXByb2Nlc3NvciUyQyUyMHBvc3Rwcm9jZXNzb3I=",highlighted:`<span class="hljs-comment"># processor_my_custom_policy.py</span>
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> <span class="hljs-type">Any</span>
<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> lerobot.processor <span class="hljs-keyword">import</span> PolicyAction, PolicyProcessorPipeline


<span class="hljs-keyword">def</span> <span class="hljs-title function_">make_my_custom_policy_pre_post_processors</span>(<span class="hljs-params">
    config,
    dataset_stats: <span class="hljs-built_in">dict</span>[<span class="hljs-built_in">str</span>, <span class="hljs-built_in">dict</span>[<span class="hljs-built_in">str</span>, torch.Tensor]] | <span class="hljs-literal">None</span> = <span class="hljs-literal">None</span>,
</span>) -&gt; <span class="hljs-built_in">tuple</span>[
    PolicyProcessorPipeline[<span class="hljs-built_in">dict</span>[<span class="hljs-built_in">str</span>, <span class="hljs-type">Any</span>], <span class="hljs-built_in">dict</span>[<span class="hljs-built_in">str</span>, <span class="hljs-type">Any</span>]],
    PolicyProcessorPipeline[PolicyAction, PolicyAction],
]:
    preprocessor = ...   <span class="hljs-comment"># build your PolicyProcessorPipeline for inputs</span>
    postprocessor = ...  <span class="hljs-comment"># build your PolicyProcessorPipeline for outputs</span>
    <span class="hljs-keyword">return</span> preprocessor, postprocessor`,wrap:!1}}),Q=new w({props:{title:"Step 5: Package Initialization",local:"step-5-package-initialization",headingTag:"h2"}}),z=new T({props:{code:"JTIzJTIwX19pbml0X18ucHklMEElMjIlMjIlMjJDdXN0b20lMjBwb2xpY3klMjBwYWNrYWdlJTIwZm9yJTIwTGVSb2JvdC4lMjIlMjIlMjIlMEElMEF0cnklM0ElMEElMjAlMjAlMjAlMjBpbXBvcnQlMjBsZXJvYm90JTIwJTIwJTIzJTIwbm9xYSUzQSUyMEY0MDElMEFleGNlcHQlMjBJbXBvcnRFcnJvciUzQSUwQSUyMCUyMCUyMCUyMHJhaXNlJTIwSW1wb3J0RXJyb3IoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIybGVyb2JvdCUyMGlzJTIwbm90JTIwaW5zdGFsbGVkLiUyMFBsZWFzZSUyMGluc3RhbGwlMjBsZXJvYm90JTIwdG8lMjB1c2UlMjB0aGlzJTIwcG9saWN5JTIwcGFja2FnZS4lMjIlMEElMjAlMjAlMjAlMjApJTBBJTBBZnJvbSUyMC5jb25maWd1cmF0aW9uX215X2N1c3RvbV9wb2xpY3klMjBpbXBvcnQlMjBNeUN1c3RvbVBvbGljeUNvbmZpZyUwQWZyb20lMjAubW9kZWxpbmdfbXlfY3VzdG9tX3BvbGljeSUyMGltcG9ydCUyME15Q3VzdG9tUG9saWN5JTBBZnJvbSUyMC5wcm9jZXNzb3JfbXlfY3VzdG9tX3BvbGljeSUyMGltcG9ydCUyMG1ha2VfbXlfY3VzdG9tX3BvbGljeV9wcmVfcG9zdF9wcm9jZXNzb3JzJTBBJTBBX19hbGxfXyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMk15Q3VzdG9tUG9saWN5Q29uZmlnJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIyTXlDdXN0b21Qb2xpY3klMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJtYWtlX215X2N1c3RvbV9wb2xpY3lfcHJlX3Bvc3RfcHJvY2Vzc29ycyUyMiUyQyUwQSU1RA==",highlighted:`<span class="hljs-comment"># __init__.py</span>
<span class="hljs-string">&quot;&quot;&quot;Custom policy package for LeRobot.&quot;&quot;&quot;</span>

<span class="hljs-keyword">try</span>:
    <span class="hljs-keyword">import</span> lerobot  <span class="hljs-comment"># noqa: F401</span>
<span class="hljs-keyword">except</span> ImportError:
    <span class="hljs-keyword">raise</span> ImportError(
        <span class="hljs-string">&quot;lerobot is not installed. Please install lerobot to use this policy package.&quot;</span>
    )

<span class="hljs-keyword">from</span> .configuration_my_custom_policy <span class="hljs-keyword">import</span> MyCustomPolicyConfig
<span class="hljs-keyword">from</span> .modeling_my_custom_policy <span class="hljs-keyword">import</span> MyCustomPolicy
<span class="hljs-keyword">from</span> .processor_my_custom_policy <span class="hljs-keyword">import</span> make_my_custom_policy_pre_post_processors

__all__ = [
    <span class="hljs-string">&quot;MyCustomPolicyConfig&quot;</span>,
    <span class="hljs-string">&quot;MyCustomPolicy&quot;</span>,
    <span class="hljs-string">&quot;make_my_custom_policy_pre_post_processors&quot;</span>,
]`,wrap:!1}}),S=new w({props:{title:"Step 6: Installation and Usage",local:"step-6-installation-and-usage",headingTag:"h2"}}),R=new w({props:{title:"Install Your Policy Package",local:"install-your-policy-package",headingTag:"h3"}}),E=new T({props:{code:"Y2QlMjBsZXJvYm90X3BvbGljeV9teV9jdXN0b21fcG9saWN5JTBBcGlwJTIwaW5zdGFsbCUyMC1lJTIwLiUwQSUwQSUyMyUyME9yJTIwaW5zdGFsbCUyMGZyb20lMjBQeVBJJTIwaWYlMjBwdWJsaXNoZWQlMEFwaXAlMjBpbnN0YWxsJTIwbGVyb2JvdF9wb2xpY3lfbXlfY3VzdG9tX3BvbGljeQ==",highlighted:`<span class="hljs-built_in">cd</span> lerobot_policy_my_custom_policy
pip install -e .

<span class="hljs-comment"># Or install from PyPI if published</span>
pip install lerobot_policy_my_custom_policy`,wrap:!1}}),H=new w({props:{title:"Use Your Policy",local:"use-your-policy",headingTag:"h3"}}),x=new T({props:{code:"bGVyb2JvdC10cmFpbiUyMCU1QyUwQSUyMCUyMCUyMCUyMC0tcG9saWN5LnR5cGUlMjBteV9jdXN0b21fcG9saWN5JTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1lbnYudHlwZSUyMHB1c2h0JTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1zdGVwcyUyMDIwMDAwMA==",highlighted:`lerobot-train \\
    --policy.type my_custom_policy \\
    --env.type pusht \\
    --steps 200000`,wrap:!1}}),q=new w({props:{title:"Examples and Community Contributions",local:"examples-and-community-contributions",headingTag:"h2"}}),K=new os({props:{source:"https://github.com/huggingface/lerobot/blob/main/docs/source/bring_your_own_policies.mdx"}}),{c(){U=J("meta"),sl=e(),O=J("p"),tl=e(),p(m.$$.fragment),al=e(),p(u.$$.fragment),el=e(),I=J("p"),I.textContent=Yl,nl=e(),p(b.$$.fragment),pl=e(),d=J("p"),d.textContent=zl,il=e(),p(h.$$.fragment),Ml=e(),f=J("p"),f.innerHTML=Sl,ol=e(),p(C.$$.fragment),yl=e(),p(B.$$.fragment),cl=e(),G=J("p"),G.innerHTML=Rl,Jl=e(),p(_.$$.fragment),jl=e(),p(g.$$.fragment),rl=e(),Z=J("p"),Z.innerHTML=El,wl=e(),p(A.$$.fragment),Ul=e(),p(N.$$.fragment),Tl=e(),k=J("p"),k.innerHTML=Hl,ml=e(),p(X.$$.fragment),ul=e(),p(W.$$.fragment),Il=e(),V=J("p"),V.innerHTML=Fl,bl=e(),p(v.$$.fragment),dl=e(),$=J("p"),$.innerHTML=xl,hl=e(),p(Q.$$.fragment),fl=e(),Y=J("p"),Y.innerHTML=ql,Cl=e(),p(z.$$.fragment),Bl=e(),p(S.$$.fragment),Gl=e(),p(R.$$.fragment),_l=e(),p(E.$$.fragment),gl=e(),p(H.$$.fragment),Zl=e(),F=J("p"),F.textContent=Pl,Al=e(),p(x.$$.fragment),Nl=e(),p(q.$$.fragment),kl=e(),P=J("p"),P.textContent=Ll,Xl=e(),L=J("ul"),L.innerHTML=Dl,Wl=e(),D=J("p"),D.textContent=Kl,Vl=e(),p(K.$$.fragment),vl=e(),ll=J("p"),this.h()},l(l){const s=ps("svelte-u9bgzb",document.head);U=j(s,"META",{name:!0,content:!0}),s.forEach(t),sl=n(l),O=j(l,"P",{}),Ol(O).forEach(t),tl=n(l),i(m.$$.fragment,l),al=n(l),i(u.$$.fragment,l),el=n(l),I=j(l,"P",{"data-svelte-h":!0}),r(I)!=="svelte-1n98dr9"&&(I.textContent=Yl),nl=n(l),i(b.$$.fragment,l),pl=n(l),d=j(l,"P",{"data-svelte-h":!0}),r(d)!=="svelte-fyljci"&&(d.textContent=zl),il=n(l),i(h.$$.fragment,l),Ml=n(l),f=j(l,"P",{"data-svelte-h":!0}),r(f)!=="svelte-poarhp"&&(f.innerHTML=Sl),ol=n(l),i(C.$$.fragment,l),yl=n(l),i(B.$$.fragment,l),cl=n(l),G=j(l,"P",{"data-svelte-h":!0}),r(G)!=="svelte-1tl7d2l"&&(G.innerHTML=Rl),Jl=n(l),i(_.$$.fragment,l),jl=n(l),i(g.$$.fragment,l),rl=n(l),Z=j(l,"P",{"data-svelte-h":!0}),r(Z)!=="svelte-zdwenp"&&(Z.innerHTML=El),wl=n(l),i(A.$$.fragment,l),Ul=n(l),i(N.$$.fragment,l),Tl=n(l),k=j(l,"P",{"data-svelte-h":!0}),r(k)!=="svelte-1a24gp9"&&(k.innerHTML=Hl),ml=n(l),i(X.$$.fragment,l),ul=n(l),i(W.$$.fragment,l),Il=n(l),V=j(l,"P",{"data-svelte-h":!0}),r(V)!=="svelte-119s15c"&&(V.innerHTML=Fl),bl=n(l),i(v.$$.fragment,l),dl=n(l),$=j(l,"P",{"data-svelte-h":!0}),r($)!=="svelte-k47civ"&&($.innerHTML=xl),hl=n(l),i(Q.$$.fragment,l),fl=n(l),Y=j(l,"P",{"data-svelte-h":!0}),r(Y)!=="svelte-1m1en5f"&&(Y.innerHTML=ql),Cl=n(l),i(z.$$.fragment,l),Bl=n(l),i(S.$$.fragment,l),Gl=n(l),i(R.$$.fragment,l),_l=n(l),i(E.$$.fragment,l),gl=n(l),i(H.$$.fragment,l),Zl=n(l),F=j(l,"P",{"data-svelte-h":!0}),r(F)!=="svelte-zi2hd8"&&(F.textContent=Pl),Al=n(l),i(x.$$.fragment,l),Nl=n(l),i(q.$$.fragment,l),kl=n(l),P=j(l,"P",{"data-svelte-h":!0}),r(P)!=="svelte-7eu84c"&&(P.textContent=Ll),Xl=n(l),L=j(l,"UL",{"data-svelte-h":!0}),r(L)!=="svelte-1y6jp3"&&(L.innerHTML=Dl),Wl=n(l),D=j(l,"P",{"data-svelte-h":!0}),r(D)!=="svelte-12scgm3"&&(D.textContent=Kl),Vl=n(l),i(K.$$.fragment,l),vl=n(l),ll=j(l,"P",{}),Ol(ll).forEach(t),this.h()},h(){ls(U,"name","hf:doc:metadata"),ls(U,"content",cs)},m(l,s){is(document.head,U),a(l,sl,s),a(l,O,s),a(l,tl,s),M(m,l,s),a(l,al,s),M(u,l,s),a(l,el,s),a(l,I,s),a(l,nl,s),M(b,l,s),a(l,pl,s),a(l,d,s),a(l,il,s),M(h,l,s),a(l,Ml,s),a(l,f,s),a(l,ol,s),M(C,l,s),a(l,yl,s),M(B,l,s),a(l,cl,s),a(l,G,s),a(l,Jl,s),M(_,l,s),a(l,jl,s),M(g,l,s),a(l,rl,s),a(l,Z,s),a(l,wl,s),M(A,l,s),a(l,Ul,s),M(N,l,s),a(l,Tl,s),a(l,k,s),a(l,ml,s),M(X,l,s),a(l,ul,s),M(W,l,s),a(l,Il,s),a(l,V,s),a(l,bl,s),M(v,l,s),a(l,dl,s),a(l,$,s),a(l,hl,s),M(Q,l,s),a(l,fl,s),a(l,Y,s),a(l,Cl,s),M(z,l,s),a(l,Bl,s),M(S,l,s),a(l,Gl,s),M(R,l,s),a(l,_l,s),M(E,l,s),a(l,gl,s),M(H,l,s),a(l,Zl,s),a(l,F,s),a(l,Al,s),M(x,l,s),a(l,Nl,s),M(q,l,s),a(l,kl,s),a(l,P,s),a(l,Xl,s),a(l,L,s),a(l,Wl,s),a(l,D,s),a(l,Vl,s),M(K,l,s),a(l,vl,s),a(l,ll,s),$l=!0},p:ts,i(l){$l||(o(m.$$.fragment,l),o(u.$$.fragment,l),o(b.$$.fragment,l),o(h.$$.fragment,l),o(C.$$.fragment,l),o(B.$$.fragment,l),o(_.$$.fragment,l),o(g.$$.fragment,l),o(A.$$.fragment,l),o(N.$$.fragment,l),o(X.$$.fragment,l),o(W.$$.fragment,l),o(v.$$.fragment,l),o(Q.$$.fragment,l),o(z.$$.fragment,l),o(S.$$.fragment,l),o(R.$$.fragment,l),o(E.$$.fragment,l),o(H.$$.fragment,l),o(x.$$.fragment,l),o(q.$$.fragment,l),o(K.$$.fragment,l),$l=!0)},o(l){y(m.$$.fragment,l),y(u.$$.fragment,l),y(b.$$.fragment,l),y(h.$$.fragment,l),y(C.$$.fragment,l),y(B.$$.fragment,l),y(_.$$.fragment,l),y(g.$$.fragment,l),y(A.$$.fragment,l),y(N.$$.fragment,l),y(X.$$.fragment,l),y(W.$$.fragment,l),y(v.$$.fragment,l),y(Q.$$.fragment,l),y(z.$$.fragment,l),y(S.$$.fragment,l),y(R.$$.fragment,l),y(E.$$.fragment,l),y(H.$$.fragment,l),y(x.$$.fragment,l),y(q.$$.fragment,l),y(K.$$.fragment,l),$l=!1},d(l){l&&(t(sl),t(O),t(tl),t(al),t(el),t(I),t(nl),t(pl),t(d),t(il),t(Ml),t(f),t(ol),t(yl),t(cl),t(G),t(Jl),t(jl),t(rl),t(Z),t(wl),t(Ul),t(Tl),t(k),t(ml),t(ul),t(Il),t(V),t(bl),t(dl),t($),t(hl),t(fl),t(Y),t(Cl),t(Bl),t(Gl),t(_l),t(gl),t(Zl),t(F),t(Al),t(Nl),t(kl),t(P),t(Xl),t(L),t(Wl),t(D),t(Vl),t(vl),t(ll)),t(U),c(m,l),c(u,l),c(b,l),c(h,l),c(C,l),c(B,l),c(_,l),c(g,l),c(A,l),c(N,l),c(X,l),c(W,l),c(v,l),c(Q,l),c(z,l),c(S,l),c(R,l),c(E,l),c(H,l),c(x,l),c(q,l),c(K,l)}}}const cs='{"title":"Bring Your Own Policies","local":"bring-your-own-policies","sections":[{"title":"Step 1: Create a Policy Package","local":"step-1-create-a-policy-package","sections":[{"title":"Package Structure","local":"package-structure","sections":[],"depth":3},{"title":"Package Configuration","local":"package-configuration","sections":[],"depth":3}],"depth":2},{"title":"Step 2: Define the Policy Configuration","local":"step-2-define-the-policy-configuration","sections":[],"depth":2},{"title":"Step 3: Implement the Policy Class","local":"step-3-implement-the-policy-class","sections":[],"depth":2},{"title":"Step 4: Add Data Processors","local":"step-4-add-data-processors","sections":[],"depth":2},{"title":"Step 5: Package Initialization","local":"step-5-package-initialization","sections":[],"depth":2},{"title":"Step 6: Installation and Usage","local":"step-6-installation-and-usage","sections":[{"title":"Install Your Policy Package","local":"install-your-policy-package","sections":[],"depth":3},{"title":"Use Your Policy","local":"use-your-policy","sections":[],"depth":3}],"depth":2},{"title":"Examples and Community Contributions","local":"examples-and-community-contributions","sections":[],"depth":2}],"depth":1}';function Js(Ql){return as(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ms extends es{constructor(U){super(),ns(this,U,Js,ys,ss,{})}}export{ms as component};
