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