import{S as _t,i as Tt,s as yt,e as o,k as p,w as b,t as s,M as vt,c as a,d as t,m as g,a as n,x as $,h as i,b as l,G as r,g as h,y as k,q as C,o as x,B as M,v as jt,L as gt}from"../../chunks/vendor-hf-doc-builder.js";import{T as wt}from"../../chunks/Tip-hf-doc-builder.js";import{D as Ir}from"../../chunks/Docstring-hf-doc-builder.js";import{C as ut}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as Je}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{E as pt}from"../../chunks/ExampleCodeBlock-hf-doc-builder.js";function bt(R){let d,_;return d=new ut({props:{code:`from transformers import TrajectoryTransformerConfig, TrajectoryTransformerModel

# Initializing a TrajectoryTransformer CarlCochet/trajectory-transformer-halfcheetah-medium-v2 style configuration
configuration = TrajectoryTransformerConfig()

# Initializing a model (with random weights) from the CarlCochet/trajectory-transformer-halfcheetah-medium-v2 style configuration
model = TrajectoryTransformerModel(configuration)

# Accessing the model configuration
configuration = model.config`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrajectoryTransformerConfig, TrajectoryTransformerModel

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a TrajectoryTransformer CarlCochet/trajectory-transformer-halfcheetah-medium-v2 style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = TrajectoryTransformerConfig()

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Initializing a model (with random weights) from the CarlCochet/trajectory-transformer-halfcheetah-medium-v2 style configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model = TrajectoryTransformerModel(configuration)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Accessing the model configuration</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>configuration = model.config`}}),{c(){b(d.$$.fragment)},l(m){$(d.$$.fragment,m)},m(m,u){k(d,m,u),_=!0},p:gt,i(m){_||(C(d.$$.fragment,m),_=!0)},o(m){x(d.$$.fragment,m),_=!1},d(m){M(d,m)}}}function $t(R){let d,_,m,u,y;return{c(){d=o("p"),_=s("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=o("code"),u=s("Module"),y=s(`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`)},l(f){d=a(f,"P",{});var T=n(d);_=i(T,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(T,"CODE",{});var S=n(m);u=i(S,"Module"),S.forEach(t),y=i(T,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),T.forEach(t)},m(f,T){h(f,d,T),r(d,_),r(d,m),r(m,u),r(d,y)},d(f){f&&t(d)}}}function kt(R){let d,_,m,u,y;return u=new ut({props:{code:`from transformers import TrajectoryTransformerModel
import torch

model = TrajectoryTransformerModel.from_pretrained(
    "CarlCochet/trajectory-transformer-halfcheetah-medium-v2"
)
model.to(device)
model.eval()

observations_dim, action_dim, batch_size = 17, 6, 256
seq_length = observations_dim + action_dim + 1

trajectories = torch.LongTensor([np.random.permutation(self.seq_length) for _ in range(batch_size)]).to(
    device
)
targets = torch.LongTensor([np.random.permutation(self.seq_length) for _ in range(batch_size)]).to(device)

outputs = model(
    trajectories,
    targets=targets,
    use_cache=True,
    output_attentions=True,
    output_hidden_states=True,
    return_dict=True,
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrajectoryTransformerModel
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TrajectoryTransformerModel.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;CarlCochet/trajectory-transformer-halfcheetah-medium-v2&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.to(device)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.<span class="hljs-built_in">eval</span>()

<span class="hljs-meta">&gt;&gt;&gt; </span>observations_dim, action_dim, batch_size = <span class="hljs-number">17</span>, <span class="hljs-number">6</span>, <span class="hljs-number">256</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>seq_length = observations_dim + action_dim + <span class="hljs-number">1</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>trajectories = torch.LongTensor([np.random.permutation(self.seq_length) <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(batch_size)]).to(
<span class="hljs-meta">... </span>    device
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>targets = torch.LongTensor([np.random.permutation(self.seq_length) <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(batch_size)]).to(device)

<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model(
<span class="hljs-meta">... </span>    trajectories,
<span class="hljs-meta">... </span>    targets=targets,
<span class="hljs-meta">... </span>    use_cache=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    output_attentions=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    output_hidden_states=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    return_dict=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>)`}}),{c(){d=o("p"),_=s("Examples:"),m=p(),b(u.$$.fragment)},l(f){d=a(f,"P",{});var T=n(d);_=i(T,"Examples:"),T.forEach(t),m=g(f),$(u.$$.fragment,f)},m(f,T){h(f,d,T),r(d,_),h(f,m,T),k(u,f,T),y=!0},p:gt,i(f){y||(C(u.$$.fragment,f),y=!0)},o(f){x(u.$$.fragment,f),y=!1},d(f){f&&t(d),f&&t(m),M(u,f)}}}function Ct(R){let d,_,m,u,y,f,T,S,Ue,ze,z,N,ye,U,Qe,ve,Ke,qe,D,Xe,Q,Ye,Ze,Pe,ie,er,Le,le,je,rr,Ae,ce,tr,Oe,de,or,Re,E,ar,K,nr,sr,X,ir,lr,Se,q,F,we,Y,cr,be,dr,Ne,v,Z,mr,P,fr,me,hr,pr,ee,gr,ur,_r,L,Tr,fe,yr,vr,he,jr,wr,br,I,De,A,W,$e,re,$r,ke,kr,Fe,j,te,Cr,oe,xr,ae,Mr,Er,zr,Ce,qr,Pr,w,ne,Lr,O,Ar,pe,Or,Rr,xe,Sr,Nr,Dr,H,Fr,B,Ie;return f=new Je({}),U=new Je({}),Y=new Je({}),Z=new Ir({props:{name:"class transformers.TrajectoryTransformerConfig",anchor:"transformers.TrajectoryTransformerConfig",parameters:[{name:"vocab_size",val:" = 100"},{name:"action_weight",val:" = 5"},{name:"reward_weight",val:" = 1"},{name:"value_weight",val:" = 1"},{name:"block_size",val:" = 249"},{name:"action_dim",val:" = 6"},{name:"observation_dim",val:" = 17"},{name:"transition_dim",val:" = 25"},{name:"n_layer",val:" = 4"},{name:"n_head",val:" = 4"},{name:"n_embd",val:" = 128"},{name:"embd_pdrop",val:" = 0.1"},{name:"attn_pdrop",val:" = 0.1"},{name:"resid_pdrop",val:" = 0.1"},{name:"learning_rate",val:" = 0.0006"},{name:"max_position_embeddings",val:" = 512"},{name:"initializer_range",val:" = 0.02"},{name:"layer_norm_eps",val:" = 1e-12"},{name:"kaiming_initializer_range",val:" = 1"},{name:"use_cache",val:" = True"},{name:"pad_token_id",val:" = 1"},{name:"bos_token_id",val:" = 50256"},{name:"eos_token_id",val:" = 50256"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.TrajectoryTransformerConfig.vocab_size",description:`<strong>vocab_size</strong> (<code>int</code>, <em>optional</em>, defaults to 100) &#x2014;
Vocabulary size of the TrajectoryTransformer model. Defines the number of different tokens that can be
represented by the <code>trajectories</code> passed when calling <a href="/docs/transformers/v4.29.0/en/model_doc/trajectory_transformer#transformers.TrajectoryTransformerModel">TrajectoryTransformerModel</a>`,name:"vocab_size"},{anchor:"transformers.TrajectoryTransformerConfig.action_weight",description:`<strong>action_weight</strong> (<code>int</code>, <em>optional</em>, defaults to 5) &#x2014;
Weight of the action in the loss function`,name:"action_weight"},{anchor:"transformers.TrajectoryTransformerConfig.reward_weight",description:`<strong>reward_weight</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
Weight of the reward in the loss function`,name:"reward_weight"},{anchor:"transformers.TrajectoryTransformerConfig.value_weight",description:`<strong>value_weight</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
Weight of the value in the loss function`,name:"value_weight"},{anchor:"transformers.TrajectoryTransformerConfig.block_size",description:`<strong>block_size</strong> (<code>int</code>, <em>optional</em>, defaults to 249) &#x2014;
Size of the blocks in the trajectory transformer.`,name:"block_size"},{anchor:"transformers.TrajectoryTransformerConfig.action_dim",description:`<strong>action_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 6) &#x2014;
Dimension of the action space.`,name:"action_dim"},{anchor:"transformers.TrajectoryTransformerConfig.observation_dim",description:`<strong>observation_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 17) &#x2014;
Dimension of the observation space.`,name:"observation_dim"},{anchor:"transformers.TrajectoryTransformerConfig.transition_dim",description:`<strong>transition_dim</strong> (<code>int</code>, <em>optional</em>, defaults to 25) &#x2014;
Dimension of the transition space.`,name:"transition_dim"},{anchor:"transformers.TrajectoryTransformerConfig.n_layer",description:`<strong>n_layer</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014;
Number of hidden layers in the Transformer encoder.`,name:"n_layer"},{anchor:"transformers.TrajectoryTransformerConfig.n_head",description:`<strong>n_head</strong> (<code>int</code>, <em>optional</em>, defaults to 4) &#x2014;
Number of attention heads for each attention layer in the Transformer encoder.`,name:"n_head"},{anchor:"transformers.TrajectoryTransformerConfig.n_embd",description:`<strong>n_embd</strong> (<code>int</code>, <em>optional</em>, defaults to 128) &#x2014;
Dimensionality of the embeddings and hidden states.`,name:"n_embd"},{anchor:"transformers.TrajectoryTransformerConfig.resid_pdrop",description:`<strong>resid_pdrop</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.`,name:"resid_pdrop"},{anchor:"transformers.TrajectoryTransformerConfig.embd_pdrop",description:`<strong>embd_pdrop</strong> (<code>int</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout ratio for the embeddings.`,name:"embd_pdrop"},{anchor:"transformers.TrajectoryTransformerConfig.attn_pdrop",description:`<strong>attn_pdrop</strong> (<code>float</code>, <em>optional</em>, defaults to 0.1) &#x2014;
The dropout ratio for the attention.`,name:"attn_pdrop"},{anchor:"transformers.TrajectoryTransformerConfig.hidden_act",description:`<strong>hidden_act</strong> (<code>str</code> or <code>function</code>, <em>optional</em>, defaults to <code>&quot;gelu&quot;</code>) &#x2014;
The non-linear activation function (function or string) in the encoder and pooler. If string, <code>&quot;gelu&quot;</code>,
<code>&quot;relu&quot;</code>, <code>&quot;selu&quot;</code> and <code>&quot;gelu_new&quot;</code> are supported.`,name:"hidden_act"},{anchor:"transformers.TrajectoryTransformerConfig.max_position_embeddings",description:`<strong>max_position_embeddings</strong> (<code>int</code>, <em>optional</em>, defaults to 512) &#x2014;
The maximum sequence length that this model might ever be used with. Typically set this to something large
just in case (e.g., 512 or 1024 or 2048).`,name:"max_position_embeddings"},{anchor:"transformers.TrajectoryTransformerConfig.initializer_range",description:`<strong>initializer_range</strong> (<code>float</code>, <em>optional</em>, defaults to 0.02) &#x2014;
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.`,name:"initializer_range"},{anchor:"transformers.TrajectoryTransformerConfig.layer_norm_eps",description:`<strong>layer_norm_eps</strong> (<code>float</code>, <em>optional</em>, defaults to 1e-12) &#x2014;
The epsilon used by the layer normalization layers.`,name:"layer_norm_eps"},{anchor:"transformers.TrajectoryTransformerConfig.kaiming_initializer_range",description:"<strong>kaiming_initializer_range</strong> (`float, <em>optional</em>, defaults to 1) &#x2014;\nA coefficient scaling the negative slope of the kaiming initializer rectifier for EinLinear layers.",name:"kaiming_initializer_range"},{anchor:"transformers.TrajectoryTransformerConfig.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not the model should return the last key/values attentions (not used by all models). Only
relevant if <code>config.is_decoder=True</code>.
Example &#x2014;`,name:"use_cache"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/trajectory_transformer/configuration_trajectory_transformer.py#L31"}}),I=new pt({props:{anchor:"transformers.TrajectoryTransformerConfig.example",$$slots:{default:[bt]},$$scope:{ctx:R}}}),re=new Je({}),te=new Ir({props:{name:"class transformers.TrajectoryTransformerModel",anchor:"transformers.TrajectoryTransformerModel",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"transformers.TrajectoryTransformerModel.config",description:`<strong>config</strong> (<a href="/docs/transformers/v4.29.0/en/model_doc/trajectory_transformer#transformers.TrajectoryTransformerConfig">TrajectoryTransformerConfig</a>) &#x2014; Model configuration class with all the parameters of the model.
Initializing with a config file does not load the weights associated with the model, only the
configuration. Check out the <a href="/docs/transformers/v4.29.0/en/main_classes/model#transformers.PreTrainedModel.from_pretrained">from_pretrained()</a> method to load the model weights.`,name:"config"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/trajectory_transformer/modeling_trajectory_transformer.py#L406"}}),ne=new Ir({props:{name:"forward",anchor:"transformers.TrajectoryTransformerModel.forward",parameters:[{name:"trajectories",val:": typing.Optional[torch.LongTensor] = None"},{name:"past_key_values",val:": typing.Optional[typing.Tuple[typing.Tuple[torch.Tensor]]] = None"},{name:"targets",val:": typing.Optional[torch.FloatTensor] = None"},{name:"attention_mask",val:": typing.Optional[torch.FloatTensor] = None"},{name:"use_cache",val:": typing.Optional[bool] = None"},{name:"output_attentions",val:": typing.Optional[bool] = None"},{name:"output_hidden_states",val:": typing.Optional[bool] = None"},{name:"return_dict",val:": typing.Optional[bool] = None"}],parametersDescription:[{anchor:"transformers.TrajectoryTransformerModel.forward.trajectories",description:`<strong>trajectories</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>) &#x2014;
Batch of trajectories, where a trajectory is a sequence of states, actions and rewards.`,name:"trajectories"},{anchor:"transformers.TrajectoryTransformerModel.forward.past_key_values",description:`<strong>past_key_values</strong> (<code>Tuple[Tuple[torch.Tensor]]</code> of length <code>config.n_layers</code>, <em>optional</em>) &#x2014;
Contains precomputed hidden-states (key and values in the attention blocks) as computed by the model (see
<code>past_key_values</code> output below). Can be used to speed up sequential decoding. The <code>input_ids</code> which have
their past given to this model should not be passed as <code>input_ids</code> as they have already been computed.`,name:"past_key_values"},{anchor:"transformers.TrajectoryTransformerModel.forward.targets",description:`<strong>targets</strong> (<code>torch.LongTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Desired targets used to compute the loss.`,name:"targets"},{anchor:"transformers.TrajectoryTransformerModel.forward.attention_mask",description:`<strong>attention_mask</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length)</code>, <em>optional</em>) &#x2014;
Mask to avoid performing attention on padding token indices. Mask values selected in <code>[0, 1]</code>:</p>
<ul>
<li>1 for tokens that are <strong>not masked</strong>,</li>
<li>0 for tokens that are <strong>masked</strong>.</li>
</ul>
<p><a href="../glossary#attention-mask">What are attention masks?</a>`,name:"attention_mask"},{anchor:"transformers.TrajectoryTransformerModel.forward.use_cache",description:`<strong>use_cache</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
If set to <code>True</code>, <code>past_key_values</code> key value states are returned and can be used to speed up decoding (see
<code>past_key_values</code>).`,name:"use_cache"},{anchor:"transformers.TrajectoryTransformerModel.forward.output_attentions",description:`<strong>output_attentions</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the attentions tensors of all attention layers. See <code>attentions</code> under returned
tensors for more detail.`,name:"output_attentions"},{anchor:"transformers.TrajectoryTransformerModel.forward.output_hidden_states",description:`<strong>output_hidden_states</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return the hidden states of all layers. See <code>hidden_states</code> under returned tensors for
more detail.`,name:"output_hidden_states"},{anchor:"transformers.TrajectoryTransformerModel.forward.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether or not to return a <a href="/docs/transformers/v4.29.0/en/main_classes/output#transformers.utils.ModelOutput">ModelOutput</a> instead of a plain tuple.`,name:"return_dict"}],source:"https://github.com/huggingface/transformers/blob/v4.29.0/src/transformers/models/trajectory_transformer/modeling_trajectory_transformer.py#L467",returnDescription:`
<p>A <code>transformers.models.trajectory_transformer.modeling_trajectory_transformer.TrajectoryTransformerOutput</code> or a tuple of
<code>torch.FloatTensor</code> (if <code>return_dict=False</code> is passed or when <code>config.return_dict=False</code>) comprising various
elements depending on the configuration (<a
  href="/docs/transformers/v4.29.0/en/model_doc/trajectory_transformer#transformers.TrajectoryTransformerConfig"
>TrajectoryTransformerConfig</a>) and inputs.</p>
<ul>
<li><strong>loss</strong> (<code>torch.FloatTensor</code> of shape <code>(1,)</code>, <em>optional</em>, returned when <code>labels</code> is provided) \u2014 Language modeling loss.</li>
<li><strong>logits</strong> (<code>torch.FloatTensor</code> of shape <code>(batch_size, sequence_length, config.vocab_size)</code>) \u2014 Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).</li>
<li><strong>past_key_values</strong> (<code>Tuple[Tuple[torch.Tensor]]</code>, <em>optional</em>, returned when <code>use_cache=True</code> is passed or when <code>config.use_cache=True</code>) \u2014 Tuple of length <code>config.n_layers</code>, containing tuples of tensors of shape <code>(batch_size, num_heads, sequence_length, embed_size_per_head)</code>). Contains pre-computed hidden-states (key and values in the
attention blocks) that can be used (see <code>past_key_values</code> input) to speed up sequential decoding.</li>
<li><strong>hidden_states</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_hidden_states=True</code> is passed or when <code>config.output_hidden_states=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for the output of the embeddings + one for the output of each layer) of
shape <code>(batch_size, sequence_length, hidden_size)</code>. Hidden-states of the model at the output of each layer
plus the initial embedding outputs.</li>
<li><strong>attentions</strong> (<code>tuple(torch.FloatTensor)</code>, <em>optional</em>, returned when <code>output_attentions=True</code> is passed or when <code>config.output_attentions=True</code>) \u2014 Tuple of <code>torch.FloatTensor</code> (one for each layer) of shape <code>(batch_size, num_heads, sequence_length, sequence_length)</code>. GPT2Attentions weights after the attention softmax, used to compute the weighted average
in the self-attention heads.</li>
</ul>
`,returnType:`
<p><code>transformers.models.trajectory_transformer.modeling_trajectory_transformer.TrajectoryTransformerOutput</code> or <code>tuple(torch.FloatTensor)</code></p>
`}}),H=new wt({props:{$$slots:{default:[$t]},$$scope:{ctx:R}}}),B=new pt({props:{anchor:"transformers.TrajectoryTransformerModel.forward.example",$$slots:{default:[kt]},$$scope:{ctx:R}}}),{c(){d=o("meta"),_=p(),m=o("h1"),u=o("a"),y=o("span"),b(f.$$.fragment),T=p(),S=o("span"),Ue=s("Trajectory Transformer"),ze=p(),z=o("h2"),N=o("a"),ye=o("span"),b(U.$$.fragment),Qe=p(),ve=o("span"),Ke=s("Overview"),qe=p(),D=o("p"),Xe=s("The Trajectory Transformer model was proposed in "),Q=o("a"),Ye=s("Offline Reinforcement Learning as One Big Sequence Modeling Problem"),Ze=s("  by Michael Janner, Qiyang Li, Sergey Levine."),Pe=p(),ie=o("p"),er=s("The abstract from the paper is the following:"),Le=p(),le=o("p"),je=o("em"),rr=s(`Reinforcement learning (RL) is typically concerned with estimating stationary policies or single-step models,
leveraging the Markov property to factorize problems in time. However, we can also view RL as a generic sequence
modeling problem, with the goal being to produce a sequence of actions that leads to a sequence of high rewards.
Viewed in this way, it is tempting to consider whether high-capacity sequence prediction models that work well
in other domains, such as natural-language processing, can also provide effective solutions to the RL problem.
To this end, we explore how RL can be tackled with the tools of sequence modeling, using a Transformer architecture
to model distributions over trajectories and repurposing beam search as a planning algorithm. Framing RL as sequence
modeling problem simplifies a range of design decisions, allowing us to dispense with many of the components common
in offline RL algorithms. We demonstrate the flexibility of this approach across long-horizon dynamics prediction,
imitation learning, goal-conditioned RL, and offline RL. Further, we show that this approach can be combined with
existing model-free algorithms to yield a state-of-the-art planner in sparse-reward, long-horizon tasks.`),Ae=p(),ce=o("p"),tr=s("Tips:"),Oe=p(),de=o("p"),or=s(`This Transformer is used for deep reinforcement learning. To use it, you need to create sequences from
actions, states and rewards from all previous timesteps. This model will treat all these elements together
as one big sequence (a trajectory).`),Re=p(),E=o("p"),ar=s("This model was contributed by "),K=o("a"),nr=s("CarlCochet"),sr=s(". The original code can be found "),X=o("a"),ir=s("here"),lr=s("."),Se=p(),q=o("h2"),F=o("a"),we=o("span"),b(Y.$$.fragment),cr=p(),be=o("span"),dr=s("TrajectoryTransformerConfig"),Ne=p(),v=o("div"),b(Z.$$.fragment),mr=p(),P=o("p"),fr=s("This is the configuration class to store the configuration of a "),me=o("a"),hr=s("TrajectoryTransformerModel"),pr=s(`. It is used to
instantiate an TrajectoryTransformer model according to the specified arguments, defining the model architecture.
Instantiating a configuration with the defaults will yield a similar configuration to that of the
TrajectoryTransformer
`),ee=o("a"),gr=s("CarlCochet/trajectory-transformer-halfcheetah-medium-v2"),ur=s(`
architecture.`),_r=p(),L=o("p"),Tr=s("Configuration objects inherit from "),fe=o("a"),yr=s("PretrainedConfig"),vr=s(` and can be used to control the model outputs. Read the
documentation from `),he=o("a"),jr=s("PretrainedConfig"),wr=s(" for more information."),br=p(),b(I.$$.fragment),De=p(),A=o("h2"),W=o("a"),$e=o("span"),b(re.$$.fragment),$r=p(),ke=o("span"),kr=s("TrajectoryTransformerModel"),Fe=p(),j=o("div"),b(te.$$.fragment),Cr=p(),oe=o("p"),xr=s(`The bare TrajectoryTransformer Model transformer outputting raw hidden-states without any specific head on top.
This model is a PyTorch `),ae=o("a"),Mr=s("torch.nn.Module"),Er=s(` sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.`),zr=p(),Ce=o("p"),qr=s("the full GPT language model, with a context size of block_size"),Pr=p(),w=o("div"),b(ne.$$.fragment),Lr=p(),O=o("p"),Ar=s("The "),pe=o("a"),Or=s("TrajectoryTransformerModel"),Rr=s(" forward method, overrides the "),xe=o("code"),Sr=s("__call__"),Nr=s(" special method."),Dr=p(),b(H.$$.fragment),Fr=p(),b(B.$$.fragment),this.h()},l(e){const c=vt('[data-svelte="svelte-1phssyn"]',document.head);d=a(c,"META",{name:!0,content:!0}),c.forEach(t),_=g(e),m=a(e,"H1",{class:!0});var se=n(m);u=a(se,"A",{id:!0,class:!0,href:!0});var Me=n(u);y=a(Me,"SPAN",{});var Ee=n(y);$(f.$$.fragment,Ee),Ee.forEach(t),Me.forEach(t),T=g(se),S=a(se,"SPAN",{});var Wr=n(S);Ue=i(Wr,"Trajectory Transformer"),Wr.forEach(t),se.forEach(t),ze=g(e),z=a(e,"H2",{class:!0});var We=n(z);N=a(We,"A",{id:!0,class:!0,href:!0});var Hr=n(N);ye=a(Hr,"SPAN",{});var Br=n(ye);$(U.$$.fragment,Br),Br.forEach(t),Hr.forEach(t),Qe=g(We),ve=a(We,"SPAN",{});var Vr=n(ve);Ke=i(Vr,"Overview"),Vr.forEach(t),We.forEach(t),qe=g(e),D=a(e,"P",{});var He=n(D);Xe=i(He,"The Trajectory Transformer model was proposed in "),Q=a(He,"A",{href:!0,rel:!0});var Gr=n(Q);Ye=i(Gr,"Offline Reinforcement Learning as One Big Sequence Modeling Problem"),Gr.forEach(t),Ze=i(He,"  by Michael Janner, Qiyang Li, Sergey Levine."),He.forEach(t),Pe=g(e),ie=a(e,"P",{});var Jr=n(ie);er=i(Jr,"The abstract from the paper is the following:"),Jr.forEach(t),Le=g(e),le=a(e,"P",{});var Ur=n(le);je=a(Ur,"EM",{});var Qr=n(je);rr=i(Qr,`Reinforcement learning (RL) is typically concerned with estimating stationary policies or single-step models,
leveraging the Markov property to factorize problems in time. However, we can also view RL as a generic sequence
modeling problem, with the goal being to produce a sequence of actions that leads to a sequence of high rewards.
Viewed in this way, it is tempting to consider whether high-capacity sequence prediction models that work well
in other domains, such as natural-language processing, can also provide effective solutions to the RL problem.
To this end, we explore how RL can be tackled with the tools of sequence modeling, using a Transformer architecture
to model distributions over trajectories and repurposing beam search as a planning algorithm. Framing RL as sequence
modeling problem simplifies a range of design decisions, allowing us to dispense with many of the components common
in offline RL algorithms. We demonstrate the flexibility of this approach across long-horizon dynamics prediction,
imitation learning, goal-conditioned RL, and offline RL. Further, we show that this approach can be combined with
existing model-free algorithms to yield a state-of-the-art planner in sparse-reward, long-horizon tasks.`),Qr.forEach(t),Ur.forEach(t),Ae=g(e),ce=a(e,"P",{});var Kr=n(ce);tr=i(Kr,"Tips:"),Kr.forEach(t),Oe=g(e),de=a(e,"P",{});var Xr=n(de);or=i(Xr,`This Transformer is used for deep reinforcement learning. To use it, you need to create sequences from
actions, states and rewards from all previous timesteps. This model will treat all these elements together
as one big sequence (a trajectory).`),Xr.forEach(t),Re=g(e),E=a(e,"P",{});var ge=n(E);ar=i(ge,"This model was contributed by "),K=a(ge,"A",{href:!0,rel:!0});var Yr=n(K);nr=i(Yr,"CarlCochet"),Yr.forEach(t),sr=i(ge,". The original code can be found "),X=a(ge,"A",{href:!0,rel:!0});var Zr=n(X);ir=i(Zr,"here"),Zr.forEach(t),lr=i(ge,"."),ge.forEach(t),Se=g(e),q=a(e,"H2",{class:!0});var Be=n(q);F=a(Be,"A",{id:!0,class:!0,href:!0});var et=n(F);we=a(et,"SPAN",{});var rt=n(we);$(Y.$$.fragment,rt),rt.forEach(t),et.forEach(t),cr=g(Be),be=a(Be,"SPAN",{});var tt=n(be);dr=i(tt,"TrajectoryTransformerConfig"),tt.forEach(t),Be.forEach(t),Ne=g(e),v=a(e,"DIV",{class:!0});var V=n(v);$(Z.$$.fragment,V),mr=g(V),P=a(V,"P",{});var ue=n(P);fr=i(ue,"This is the configuration class to store the configuration of a "),me=a(ue,"A",{href:!0});var ot=n(me);hr=i(ot,"TrajectoryTransformerModel"),ot.forEach(t),pr=i(ue,`. It is used to
instantiate an TrajectoryTransformer model according to the specified arguments, defining the model architecture.
Instantiating a configuration with the defaults will yield a similar configuration to that of the
TrajectoryTransformer
`),ee=a(ue,"A",{href:!0,rel:!0});var at=n(ee);gr=i(at,"CarlCochet/trajectory-transformer-halfcheetah-medium-v2"),at.forEach(t),ur=i(ue,`
architecture.`),ue.forEach(t),_r=g(V),L=a(V,"P",{});var _e=n(L);Tr=i(_e,"Configuration objects inherit from "),fe=a(_e,"A",{href:!0});var nt=n(fe);yr=i(nt,"PretrainedConfig"),nt.forEach(t),vr=i(_e,` and can be used to control the model outputs. Read the
documentation from `),he=a(_e,"A",{href:!0});var st=n(he);jr=i(st,"PretrainedConfig"),st.forEach(t),wr=i(_e," for more information."),_e.forEach(t),br=g(V),$(I.$$.fragment,V),V.forEach(t),De=g(e),A=a(e,"H2",{class:!0});var Ve=n(A);W=a(Ve,"A",{id:!0,class:!0,href:!0});var it=n(W);$e=a(it,"SPAN",{});var lt=n($e);$(re.$$.fragment,lt),lt.forEach(t),it.forEach(t),$r=g(Ve),ke=a(Ve,"SPAN",{});var ct=n(ke);kr=i(ct,"TrajectoryTransformerModel"),ct.forEach(t),Ve.forEach(t),Fe=g(e),j=a(e,"DIV",{class:!0});var G=n(j);$(te.$$.fragment,G),Cr=g(G),oe=a(G,"P",{});var Ge=n(oe);xr=i(Ge,`The bare TrajectoryTransformer Model transformer outputting raw hidden-states without any specific head on top.
This model is a PyTorch `),ae=a(Ge,"A",{href:!0,rel:!0});var dt=n(ae);Mr=i(dt,"torch.nn.Module"),dt.forEach(t),Er=i(Ge,` sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.`),Ge.forEach(t),zr=g(G),Ce=a(G,"P",{});var mt=n(Ce);qr=i(mt,"the full GPT language model, with a context size of block_size"),mt.forEach(t),Pr=g(G),w=a(G,"DIV",{class:!0});var J=n(w);$(ne.$$.fragment,J),Lr=g(J),O=a(J,"P",{});var Te=n(O);Ar=i(Te,"The "),pe=a(Te,"A",{href:!0});var ft=n(pe);Or=i(ft,"TrajectoryTransformerModel"),ft.forEach(t),Rr=i(Te," forward method, overrides the "),xe=a(Te,"CODE",{});var ht=n(xe);Sr=i(ht,"__call__"),ht.forEach(t),Nr=i(Te," special method."),Te.forEach(t),Dr=g(J),$(H.$$.fragment,J),Fr=g(J),$(B.$$.fragment,J),J.forEach(t),G.forEach(t),this.h()},h(){l(d,"name","hf:doc:metadata"),l(d,"content",JSON.stringify(xt)),l(u,"id","trajectory-transformer"),l(u,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(u,"href","#trajectory-transformer"),l(m,"class","relative group"),l(N,"id","overview"),l(N,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(N,"href","#overview"),l(z,"class","relative group"),l(Q,"href","https://arxiv.org/abs/2106.02039"),l(Q,"rel","nofollow"),l(K,"href","https://huggingface.co/CarlCochet"),l(K,"rel","nofollow"),l(X,"href","https://github.com/jannerm/trajectory-transformer"),l(X,"rel","nofollow"),l(F,"id","transformers.TrajectoryTransformerConfig"),l(F,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(F,"href","#transformers.TrajectoryTransformerConfig"),l(q,"class","relative group"),l(me,"href","/docs/transformers/v4.29.0/en/model_doc/trajectory_transformer#transformers.TrajectoryTransformerModel"),l(ee,"href","https://huggingface.co/CarlCochet/trajectory-transformer-halfcheetah-medium-v2"),l(ee,"rel","nofollow"),l(fe,"href","/docs/transformers/v4.29.0/en/main_classes/configuration#transformers.PretrainedConfig"),l(he,"href","/docs/transformers/v4.29.0/en/main_classes/configuration#transformers.PretrainedConfig"),l(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(W,"id","transformers.TrajectoryTransformerModel"),l(W,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),l(W,"href","#transformers.TrajectoryTransformerModel"),l(A,"class","relative group"),l(ae,"href","https://pytorch.org/docs/stable/nn.html#torch.nn.Module"),l(ae,"rel","nofollow"),l(pe,"href","/docs/transformers/v4.29.0/en/model_doc/trajectory_transformer#transformers.TrajectoryTransformerModel"),l(w,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,c){r(document.head,d),h(e,_,c),h(e,m,c),r(m,u),r(u,y),k(f,y,null),r(m,T),r(m,S),r(S,Ue),h(e,ze,c),h(e,z,c),r(z,N),r(N,ye),k(U,ye,null),r(z,Qe),r(z,ve),r(ve,Ke),h(e,qe,c),h(e,D,c),r(D,Xe),r(D,Q),r(Q,Ye),r(D,Ze),h(e,Pe,c),h(e,ie,c),r(ie,er),h(e,Le,c),h(e,le,c),r(le,je),r(je,rr),h(e,Ae,c),h(e,ce,c),r(ce,tr),h(e,Oe,c),h(e,de,c),r(de,or),h(e,Re,c),h(e,E,c),r(E,ar),r(E,K),r(K,nr),r(E,sr),r(E,X),r(X,ir),r(E,lr),h(e,Se,c),h(e,q,c),r(q,F),r(F,we),k(Y,we,null),r(q,cr),r(q,be),r(be,dr),h(e,Ne,c),h(e,v,c),k(Z,v,null),r(v,mr),r(v,P),r(P,fr),r(P,me),r(me,hr),r(P,pr),r(P,ee),r(ee,gr),r(P,ur),r(v,_r),r(v,L),r(L,Tr),r(L,fe),r(fe,yr),r(L,vr),r(L,he),r(he,jr),r(L,wr),r(v,br),k(I,v,null),h(e,De,c),h(e,A,c),r(A,W),r(W,$e),k(re,$e,null),r(A,$r),r(A,ke),r(ke,kr),h(e,Fe,c),h(e,j,c),k(te,j,null),r(j,Cr),r(j,oe),r(oe,xr),r(oe,ae),r(ae,Mr),r(oe,Er),r(j,zr),r(j,Ce),r(Ce,qr),r(j,Pr),r(j,w),k(ne,w,null),r(w,Lr),r(w,O),r(O,Ar),r(O,pe),r(pe,Or),r(O,Rr),r(O,xe),r(xe,Sr),r(O,Nr),r(w,Dr),k(H,w,null),r(w,Fr),k(B,w,null),Ie=!0},p(e,[c]){const se={};c&2&&(se.$$scope={dirty:c,ctx:e}),I.$set(se);const Me={};c&2&&(Me.$$scope={dirty:c,ctx:e}),H.$set(Me);const Ee={};c&2&&(Ee.$$scope={dirty:c,ctx:e}),B.$set(Ee)},i(e){Ie||(C(f.$$.fragment,e),C(U.$$.fragment,e),C(Y.$$.fragment,e),C(Z.$$.fragment,e),C(I.$$.fragment,e),C(re.$$.fragment,e),C(te.$$.fragment,e),C(ne.$$.fragment,e),C(H.$$.fragment,e),C(B.$$.fragment,e),Ie=!0)},o(e){x(f.$$.fragment,e),x(U.$$.fragment,e),x(Y.$$.fragment,e),x(Z.$$.fragment,e),x(I.$$.fragment,e),x(re.$$.fragment,e),x(te.$$.fragment,e),x(ne.$$.fragment,e),x(H.$$.fragment,e),x(B.$$.fragment,e),Ie=!1},d(e){t(d),e&&t(_),e&&t(m),M(f),e&&t(ze),e&&t(z),M(U),e&&t(qe),e&&t(D),e&&t(Pe),e&&t(ie),e&&t(Le),e&&t(le),e&&t(Ae),e&&t(ce),e&&t(Oe),e&&t(de),e&&t(Re),e&&t(E),e&&t(Se),e&&t(q),M(Y),e&&t(Ne),e&&t(v),M(Z),M(I),e&&t(De),e&&t(A),M(re),e&&t(Fe),e&&t(j),M(te),M(ne),M(H),M(B)}}}const xt={local:"trajectory-transformer",sections:[{local:"overview",title:"Overview"},{local:"transformers.TrajectoryTransformerConfig",title:"TrajectoryTransformerConfig"},{local:"transformers.TrajectoryTransformerModel",title:"TrajectoryTransformerModel"}],title:"Trajectory Transformer"};function Mt(R){return jt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ot extends _t{constructor(d){super();Tt(this,d,Mt,Ct,yt,{})}}export{Ot as default,xt as metadata};
