import{S as _o,i as To,s as vo,e as r,k as p,w as j,t as s,M as bo,c as a,d as o,m as u,a as n,x as M,h as i,b as l,G as t,g as f,y as $,q as C,o as k,B as U,v as wo,L as go}from"../../chunks/vendor-hf-doc-builder.js";import{T as jo}from"../../chunks/Tip-hf-doc-builder.js";import{D as Vt}from"../../chunks/Docstring-hf-doc-builder.js";import{C as yo}from"../../chunks/CodeBlock-hf-doc-builder.js";import{I as Ae}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{E as uo}from"../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Mo(N){let d,y;return d=new yo({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWplY3RvcnlUcmFuc2Zvcm1lckNvbmZpZyUyQyUyMFRyYWplY3RvcnlUcmFuc2Zvcm1lck1vZGVsJTBBJTBBJTIzJTIwSW5pdGlhbGl6aW5nJTIwYSUyMFRyYWplY3RvcnlUcmFuc2Zvcm1lciUyMENhcmxDb2NoZXQlMkZ0cmFqZWN0b3J5LXRyYW5zZm9ybWVyLWhhbGZjaGVldGFoLW1lZGl1bS12MiUyMHN0eWxlJTIwY29uZmlndXJhdGlvbiUwQWNvbmZpZ3VyYXRpb24lMjAlM0QlMjBUcmFqZWN0b3J5VHJhbnNmb3JtZXJDb25maWcoKSUwQSUwQSUyMyUyMEluaXRpYWxpemluZyUyMGElMjBtb2RlbCUyMCh3aXRoJTIwcmFuZG9tJTIwd2VpZ2h0cyklMjBmcm9tJTIwdGhlJTIwQ2FybENvY2hldCUyRnRyYWplY3RvcnktdHJhbnNmb3JtZXItaGFsZmNoZWV0YWgtbWVkaXVtLXYyJTIwc3R5bGUlMjBjb25maWd1cmF0aW9uJTBBbW9kZWwlMjAlM0QlMjBUcmFqZWN0b3J5VHJhbnNmb3JtZXJNb2RlbChjb25maWd1cmF0aW9uKSUwQSUwQSUyMyUyMEFjY2Vzc2luZyUyMHRoZSUyMG1vZGVsJTIwY29uZmlndXJhdGlvbiUwQWNvbmZpZ3VyYXRpb24lMjAlM0QlMjBtb2RlbC5jb25maWc=",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(){j(d.$$.fragment)},l(m){M(d.$$.fragment,m)},m(m,g){$(d,m,g),y=!0},p:go,i(m){y||(C(d.$$.fragment,m),y=!0)},o(m){k(d.$$.fragment,m),y=!1},d(m){U(d,m)}}}function $o(N){let d,y,m,g,T;return{c(){d=r("p"),y=s("Although the recipe for forward pass needs to be defined within this function, one should call the "),m=r("code"),g=s("Module"),T=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(h){d=a(h,"P",{});var _=n(d);y=i(_,"Although the recipe for forward pass needs to be defined within this function, one should call the "),m=a(_,"CODE",{});var S=n(m);g=i(S,"Module"),S.forEach(o),T=i(_,`
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
the latter silently ignores them.`),_.forEach(o)},m(h,_){f(h,d,_),t(d,y),t(d,m),t(m,g),t(d,T)},d(h){h&&o(d)}}}function Co(N){let d,y,m,g,T;return g=new yo({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWplY3RvcnlUcmFuc2Zvcm1lck1vZGVsJTBBaW1wb3J0JTIwdG9yY2glMEElMEFtb2RlbCUyMCUzRCUyMFRyYWplY3RvcnlUcmFuc2Zvcm1lck1vZGVsLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJDYXJsQ29jaGV0JTJGdHJhamVjdG9yeS10cmFuc2Zvcm1lci1oYWxmY2hlZXRhaC1tZWRpdW0tdjIlMjIlMEEpJTBBbW9kZWwudG8oZGV2aWNlKSUwQW1vZGVsLmV2YWwoKSUwQSUwQW9ic2VydmF0aW9uc19kaW0lMkMlMjBhY3Rpb25fZGltJTJDJTIwYmF0Y2hfc2l6ZSUyMCUzRCUyMDE3JTJDJTIwNiUyQyUyMDI1NiUwQXNlcV9sZW5ndGglMjAlM0QlMjBvYnNlcnZhdGlvbnNfZGltJTIwJTJCJTIwYWN0aW9uX2RpbSUyMCUyQiUyMDElMEElMEF0cmFqZWN0b3JpZXMlMjAlM0QlMjB0b3JjaC5Mb25nVGVuc29yKCU1Qm5wLnJhbmRvbS5wZXJtdXRhdGlvbihzZWxmLnNlcV9sZW5ndGgpJTIwZm9yJTIwXyUyMGluJTIwcmFuZ2UoYmF0Y2hfc2l6ZSklNUQpLnRvKCUwQSUyMCUyMCUyMCUyMGRldmljZSUwQSklMEF0YXJnZXRzJTIwJTNEJTIwdG9yY2guTG9uZ1RlbnNvciglNUJucC5yYW5kb20ucGVybXV0YXRpb24oc2VsZi5zZXFfbGVuZ3RoKSUyMGZvciUyMF8lMjBpbiUyMHJhbmdlKGJhdGNoX3NpemUpJTVEKS50byhkZXZpY2UpJTBBJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsKCUwQSUyMCUyMCUyMCUyMHRyYWplY3RvcmllcyUyQyUwQSUyMCUyMCUyMCUyMHRhcmdldHMlM0R0YXJnZXRzJTJDJTBBJTIwJTIwJTIwJTIwdXNlX2NhY2hlJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMG91dHB1dF9hdHRlbnRpb25zJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMG91dHB1dF9oaWRkZW5fc3RhdGVzJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHJldHVybl9kaWN0JTNEVHJ1ZSUyQyUwQSk=",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=r("p"),y=s("Examples:"),m=p(),j(g.$$.fragment)},l(h){d=a(h,"P",{});var _=n(d);y=i(_,"Examples:"),_.forEach(o),m=u(h),M(g.$$.fragment,h)},m(h,_){f(h,d,_),t(d,y),f(h,m,_),$(g,h,_),T=!0},p:go,i(h){T||(C(g.$$.fragment,h),T=!0)},o(h){k(g.$$.fragment,h),T=!1},d(h){h&&o(d),h&&o(m),U(g,h)}}}function ko(N){let d,y,m,g,T,h,_,S,Be,Ee,E,G,Te,B,Xe,ve,He,Ze,q,De,X,Oe,Ke,Re,ie,et,xe,le,be,tt,We,ce,ot,ze,de,rt,Ne,J,at,H,nt,st,D,it,lt,Se,Z,F,we,O,ct,je,dt,Ge,v,K,mt,R,ht,me,ft,pt,ee,ut,gt,yt,x,_t,he,Tt,vt,fe,bt,wt,jt,V,qe,W,Y,Me,te,Mt,$e,$t,Fe,b,oe,Ct,re,kt,ae,Ut,Jt,Et,Ce,Zt,Rt,w,ne,xt,z,Wt,pe,zt,Nt,ke,St,Gt,qt,L,Ft,P,Ve;return h=new Ae({}),B=new Ae({}),O=new Ae({}),K=new Vt({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.30.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.30.0/src/transformers/models/trajectory_transformer/configuration_trajectory_transformer.py#L31"}}),V=new uo({props:{anchor:"transformers.TrajectoryTransformerConfig.example",$$slots:{default:[Mo]},$$scope:{ctx:N}}}),te=new Ae({}),oe=new Vt({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.30.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.30.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.30.0/src/transformers/models/trajectory_transformer/modeling_trajectory_transformer.py#L406"}}),ne=new Vt({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.30.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.30.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.30.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>
`}}),L=new jo({props:{$$slots:{default:[$o]},$$scope:{ctx:N}}}),P=new uo({props:{anchor:"transformers.TrajectoryTransformerModel.forward.example",$$slots:{default:[Co]},$$scope:{ctx:N}}}),{c(){d=r("meta"),y=p(),m=r("h1"),g=r("a"),T=r("span"),j(h.$$.fragment),_=p(),S=r("span"),Be=s("Trajectory Transformer"),Ee=p(),E=r("h2"),G=r("a"),Te=r("span"),j(B.$$.fragment),Xe=p(),ve=r("span"),He=s("Overview"),Ze=p(),q=r("p"),De=s("The Trajectory Transformer model was proposed in "),X=r("a"),Oe=s("Offline Reinforcement Learning as One Big Sequence Modeling Problem"),Ke=s("  by Michael Janner, Qiyang Li, Sergey Levine."),Re=p(),ie=r("p"),et=s("The abstract from the paper is the following:"),xe=p(),le=r("p"),be=r("em"),tt=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.`),We=p(),ce=r("p"),ot=s("Tips:"),ze=p(),de=r("p"),rt=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).`),Ne=p(),J=r("p"),at=s("This model was contributed by "),H=r("a"),nt=s("CarlCochet"),st=s(". The original code can be found "),D=r("a"),it=s("here"),lt=s("."),Se=p(),Z=r("h2"),F=r("a"),we=r("span"),j(O.$$.fragment),ct=p(),je=r("span"),dt=s("TrajectoryTransformerConfig"),Ge=p(),v=r("div"),j(K.$$.fragment),mt=p(),R=r("p"),ht=s("This is the configuration class to store the configuration of a "),me=r("a"),ft=s("TrajectoryTransformerModel"),pt=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=r("a"),ut=s("CarlCochet/trajectory-transformer-halfcheetah-medium-v2"),gt=s(`
architecture.`),yt=p(),x=r("p"),_t=s("Configuration objects inherit from "),he=r("a"),Tt=s("PretrainedConfig"),vt=s(` and can be used to control the model outputs. Read the
documentation from `),fe=r("a"),bt=s("PretrainedConfig"),wt=s(" for more information."),jt=p(),j(V.$$.fragment),qe=p(),W=r("h2"),Y=r("a"),Me=r("span"),j(te.$$.fragment),Mt=p(),$e=r("span"),$t=s("TrajectoryTransformerModel"),Fe=p(),b=r("div"),j(oe.$$.fragment),Ct=p(),re=r("p"),kt=s(`The bare TrajectoryTransformer Model transformer outputting raw hidden-states without any specific head on top.
This model is a PyTorch `),ae=r("a"),Ut=s("torch.nn.Module"),Jt=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.`),Et=p(),Ce=r("p"),Zt=s("the full GPT language model, with a context size of block_size"),Rt=p(),w=r("div"),j(ne.$$.fragment),xt=p(),z=r("p"),Wt=s("The "),pe=r("a"),zt=s("TrajectoryTransformerModel"),Nt=s(" forward method, overrides the "),ke=r("code"),St=s("__call__"),Gt=s(" special method."),qt=p(),j(L.$$.fragment),Ft=p(),j(P.$$.fragment),this.h()},l(e){const c=bo('[data-svelte="svelte-1phssyn"]',document.head);d=a(c,"META",{name:!0,content:!0}),c.forEach(o),y=u(e),m=a(e,"H1",{class:!0});var se=n(m);g=a(se,"A",{id:!0,class:!0,href:!0});var Ue=n(g);T=a(Ue,"SPAN",{});var Je=n(T);M(h.$$.fragment,Je),Je.forEach(o),Ue.forEach(o),_=u(se),S=a(se,"SPAN",{});var Yt=n(S);Be=i(Yt,"Trajectory Transformer"),Yt.forEach(o),se.forEach(o),Ee=u(e),E=a(e,"H2",{class:!0});var Ye=n(E);G=a(Ye,"A",{id:!0,class:!0,href:!0});var Lt=n(G);Te=a(Lt,"SPAN",{});var Pt=n(Te);M(B.$$.fragment,Pt),Pt.forEach(o),Lt.forEach(o),Xe=u(Ye),ve=a(Ye,"SPAN",{});var It=n(ve);He=i(It,"Overview"),It.forEach(o),Ye.forEach(o),Ze=u(e),q=a(e,"P",{});var Le=n(q);De=i(Le,"The Trajectory Transformer model was proposed in "),X=a(Le,"A",{href:!0,rel:!0});var Qt=n(X);Oe=i(Qt,"Offline Reinforcement Learning as One Big Sequence Modeling Problem"),Qt.forEach(o),Ke=i(Le,"  by Michael Janner, Qiyang Li, Sergey Levine."),Le.forEach(o),Re=u(e),ie=a(e,"P",{});var At=n(ie);et=i(At,"The abstract from the paper is the following:"),At.forEach(o),xe=u(e),le=a(e,"P",{});var Bt=n(le);be=a(Bt,"EM",{});var Xt=n(be);tt=i(Xt,`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.`),Xt.forEach(o),Bt.forEach(o),We=u(e),ce=a(e,"P",{});var Ht=n(ce);ot=i(Ht,"Tips:"),Ht.forEach(o),ze=u(e),de=a(e,"P",{});var Dt=n(de);rt=i(Dt,`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).`),Dt.forEach(o),Ne=u(e),J=a(e,"P",{});var ue=n(J);at=i(ue,"This model was contributed by "),H=a(ue,"A",{href:!0,rel:!0});var Ot=n(H);nt=i(Ot,"CarlCochet"),Ot.forEach(o),st=i(ue,". The original code can be found "),D=a(ue,"A",{href:!0,rel:!0});var Kt=n(D);it=i(Kt,"here"),Kt.forEach(o),lt=i(ue,"."),ue.forEach(o),Se=u(e),Z=a(e,"H2",{class:!0});var Pe=n(Z);F=a(Pe,"A",{id:!0,class:!0,href:!0});var eo=n(F);we=a(eo,"SPAN",{});var to=n(we);M(O.$$.fragment,to),to.forEach(o),eo.forEach(o),ct=u(Pe),je=a(Pe,"SPAN",{});var oo=n(je);dt=i(oo,"TrajectoryTransformerConfig"),oo.forEach(o),Pe.forEach(o),Ge=u(e),v=a(e,"DIV",{class:!0});var I=n(v);M(K.$$.fragment,I),mt=u(I),R=a(I,"P",{});var ge=n(R);ht=i(ge,"This is the configuration class to store the configuration of a "),me=a(ge,"A",{href:!0});var ro=n(me);ft=i(ro,"TrajectoryTransformerModel"),ro.forEach(o),pt=i(ge,`. 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(ge,"A",{href:!0,rel:!0});var ao=n(ee);ut=i(ao,"CarlCochet/trajectory-transformer-halfcheetah-medium-v2"),ao.forEach(o),gt=i(ge,`
architecture.`),ge.forEach(o),yt=u(I),x=a(I,"P",{});var ye=n(x);_t=i(ye,"Configuration objects inherit from "),he=a(ye,"A",{href:!0});var no=n(he);Tt=i(no,"PretrainedConfig"),no.forEach(o),vt=i(ye,` and can be used to control the model outputs. Read the
documentation from `),fe=a(ye,"A",{href:!0});var so=n(fe);bt=i(so,"PretrainedConfig"),so.forEach(o),wt=i(ye," for more information."),ye.forEach(o),jt=u(I),M(V.$$.fragment,I),I.forEach(o),qe=u(e),W=a(e,"H2",{class:!0});var Ie=n(W);Y=a(Ie,"A",{id:!0,class:!0,href:!0});var io=n(Y);Me=a(io,"SPAN",{});var lo=n(Me);M(te.$$.fragment,lo),lo.forEach(o),io.forEach(o),Mt=u(Ie),$e=a(Ie,"SPAN",{});var co=n($e);$t=i(co,"TrajectoryTransformerModel"),co.forEach(o),Ie.forEach(o),Fe=u(e),b=a(e,"DIV",{class:!0});var Q=n(b);M(oe.$$.fragment,Q),Ct=u(Q),re=a(Q,"P",{});var Qe=n(re);kt=i(Qe,`The bare TrajectoryTransformer Model transformer outputting raw hidden-states without any specific head on top.
This model is a PyTorch `),ae=a(Qe,"A",{href:!0,rel:!0});var mo=n(ae);Ut=i(mo,"torch.nn.Module"),mo.forEach(o),Jt=i(Qe,` sub-class. Use
it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
behavior.`),Qe.forEach(o),Et=u(Q),Ce=a(Q,"P",{});var ho=n(Ce);Zt=i(ho,"the full GPT language model, with a context size of block_size"),ho.forEach(o),Rt=u(Q),w=a(Q,"DIV",{class:!0});var A=n(w);M(ne.$$.fragment,A),xt=u(A),z=a(A,"P",{});var _e=n(z);Wt=i(_e,"The "),pe=a(_e,"A",{href:!0});var fo=n(pe);zt=i(fo,"TrajectoryTransformerModel"),fo.forEach(o),Nt=i(_e," forward method, overrides the "),ke=a(_e,"CODE",{});var po=n(ke);St=i(po,"__call__"),po.forEach(o),Gt=i(_e," special method."),_e.forEach(o),qt=u(A),M(L.$$.fragment,A),Ft=u(A),M(P.$$.fragment,A),A.forEach(o),Q.forEach(o),this.h()},h(){l(d,"name","hf:doc:metadata"),l(d,"content",JSON.stringify(Uo)),l(g,"id","trajectory-transformer"),l(g,"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(g,"href","#trajectory-transformer"),l(m,"class","relative group"),l(G,"id","overview"),l(G,"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(G,"href","#overview"),l(E,"class","relative group"),l(X,"href","https://arxiv.org/abs/2106.02039"),l(X,"rel","nofollow"),l(H,"href","https://huggingface.co/CarlCochet"),l(H,"rel","nofollow"),l(D,"href","https://github.com/jannerm/trajectory-transformer"),l(D,"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(Z,"class","relative group"),l(me,"href","/docs/transformers/v4.30.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(he,"href","/docs/transformers/v4.30.0/en/main_classes/configuration#transformers.PretrainedConfig"),l(fe,"href","/docs/transformers/v4.30.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(Y,"id","transformers.TrajectoryTransformerModel"),l(Y,"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(Y,"href","#transformers.TrajectoryTransformerModel"),l(W,"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.30.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(b,"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){t(document.head,d),f(e,y,c),f(e,m,c),t(m,g),t(g,T),$(h,T,null),t(m,_),t(m,S),t(S,Be),f(e,Ee,c),f(e,E,c),t(E,G),t(G,Te),$(B,Te,null),t(E,Xe),t(E,ve),t(ve,He),f(e,Ze,c),f(e,q,c),t(q,De),t(q,X),t(X,Oe),t(q,Ke),f(e,Re,c),f(e,ie,c),t(ie,et),f(e,xe,c),f(e,le,c),t(le,be),t(be,tt),f(e,We,c),f(e,ce,c),t(ce,ot),f(e,ze,c),f(e,de,c),t(de,rt),f(e,Ne,c),f(e,J,c),t(J,at),t(J,H),t(H,nt),t(J,st),t(J,D),t(D,it),t(J,lt),f(e,Se,c),f(e,Z,c),t(Z,F),t(F,we),$(O,we,null),t(Z,ct),t(Z,je),t(je,dt),f(e,Ge,c),f(e,v,c),$(K,v,null),t(v,mt),t(v,R),t(R,ht),t(R,me),t(me,ft),t(R,pt),t(R,ee),t(ee,ut),t(R,gt),t(v,yt),t(v,x),t(x,_t),t(x,he),t(he,Tt),t(x,vt),t(x,fe),t(fe,bt),t(x,wt),t(v,jt),$(V,v,null),f(e,qe,c),f(e,W,c),t(W,Y),t(Y,Me),$(te,Me,null),t(W,Mt),t(W,$e),t($e,$t),f(e,Fe,c),f(e,b,c),$(oe,b,null),t(b,Ct),t(b,re),t(re,kt),t(re,ae),t(ae,Ut),t(re,Jt),t(b,Et),t(b,Ce),t(Ce,Zt),t(b,Rt),t(b,w),$(ne,w,null),t(w,xt),t(w,z),t(z,Wt),t(z,pe),t(pe,zt),t(z,Nt),t(z,ke),t(ke,St),t(z,Gt),t(w,qt),$(L,w,null),t(w,Ft),$(P,w,null),Ve=!0},p(e,[c]){const se={};c&2&&(se.$$scope={dirty:c,ctx:e}),V.$set(se);const Ue={};c&2&&(Ue.$$scope={dirty:c,ctx:e}),L.$set(Ue);const Je={};c&2&&(Je.$$scope={dirty:c,ctx:e}),P.$set(Je)},i(e){Ve||(C(h.$$.fragment,e),C(B.$$.fragment,e),C(O.$$.fragment,e),C(K.$$.fragment,e),C(V.$$.fragment,e),C(te.$$.fragment,e),C(oe.$$.fragment,e),C(ne.$$.fragment,e),C(L.$$.fragment,e),C(P.$$.fragment,e),Ve=!0)},o(e){k(h.$$.fragment,e),k(B.$$.fragment,e),k(O.$$.fragment,e),k(K.$$.fragment,e),k(V.$$.fragment,e),k(te.$$.fragment,e),k(oe.$$.fragment,e),k(ne.$$.fragment,e),k(L.$$.fragment,e),k(P.$$.fragment,e),Ve=!1},d(e){o(d),e&&o(y),e&&o(m),U(h),e&&o(Ee),e&&o(E),U(B),e&&o(Ze),e&&o(q),e&&o(Re),e&&o(ie),e&&o(xe),e&&o(le),e&&o(We),e&&o(ce),e&&o(ze),e&&o(de),e&&o(Ne),e&&o(J),e&&o(Se),e&&o(Z),U(O),e&&o(Ge),e&&o(v),U(K),U(V),e&&o(qe),e&&o(W),U(te),e&&o(Fe),e&&o(b),U(oe),U(ne),U(L),U(P)}}}const Uo={local:"trajectory-transformer",sections:[{local:"overview",title:"Overview"},{local:"transformers.TrajectoryTransformerConfig",title:"TrajectoryTransformerConfig"},{local:"transformers.TrajectoryTransformerModel",title:"TrajectoryTransformerModel"}],title:"Trajectory Transformer"};function Jo(N){return wo(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class No extends _o{constructor(d){super();To(this,d,Jo,ko,vo,{})}}export{No as default,Uo as metadata};
