Exir.capture fails - missing get_random_input

username: adonnini
cooked: <p><a class="mention" href="/u/kimishpatel">@kimishpatel</a> This is in response to your message:</p>
<pre><code class="lang-auto">What is tf_model in your example? If you are following pattern of https://github.com/pytorch/executorch/blob/main/examples/models/inception_v3/model.py#L28, then the TFModel needs to defined get_random_inputs method.
</code></pre>
<p>I am not sure I understand. Sorry.</p>
<p>It sounds like I need to define <code>get_random_input</code> method in my model. Right?</p>
<p>The link in your message points to <code>get_example_inputs</code> method. I this an example of  <code>get_random_input</code> method? In my model, input datasets are stored offline. They are not random tensors. Can I just supply to exir.capture an input dataset?</p>
<p>Thanks</p>

username: ptrblck
cooked: <p>Please send a message to a user instead of creating a topic in case you are communicating directly.</p>

username: adonnini
cooked: <p><a class="mention" href="/u/kimishpatel">@kimishpatel</a> asked me to post to this section of the pytorch forums</p>

username: adonnini
cooked: <p>The user in question, <a class="mention" href="/u/kimishpatel">@kimishpatel</a>, asked me to post to the executorch<br>
section of the pytorch forums</p>

username: ptrblck
cooked: <p>I assume Kimish asked you to create a topic explaining your question here instead of directly responding to a conversation nobody else has access to.</p>

username: adonnini
cooked: <p>I am sorry. Didn’t I do that?</p>
<aside class="quote quote-modified" data-post="1" data-topic="191011">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/adonnini/48/65046_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/exir-capture-fails-missing-get-random-input/191011">Exir.capture fails - missing get_random_input</a> <a class="badge-category__wrapper " href="/c/executorch/42"><span data-category-id="42" data-drop-close="true" class="badge-category " title="A category of posts relating to ExecuTorch."><span class="badge-category__name">ExecuTorch</span></span></a>
  </div>
  <blockquote>
    <a class="mention" href="/u/kimishpatel">@kimishpatel</a> This is in response to your message: 
What is tf_model in your example? If you are following pattern of https://github.com/pytorch/executorch/blob/main/examples/models/inception_v3/model.py#L28, then the TFModel needs to defined get_random_inputs method.

I am not sure I understand. Sorry. 
It sounds like I need to define get_random_input method in my model. Right? 
The link in your message points to get_example_inputs method. I this an example of  get_random_input method? In my mod…
  </blockquote>
</aside>


username: ptrblck
cooked: <p>At least for me it’s unclear what the question is and where you are stuck.</p>

username: kimishpatel
cooked: <aside class="quote no-group" data-username="ptrblck" data-post="5" data-topic="191011" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>I assume Kimish asked you to create a topic explaining your question here instead of directly responding to a conversation nobody else has access to.</p>
</blockquote>
</aside>
<p>thats right <a class="mention" href="/u/ptrblck">@ptrblck</a></p>

username: kimishpatel
cooked: <aside class="quote no-group" data-username="Exir.capture fails - missing get_random_input" data-post="1" data-topic="191011">
<div class="title">
<div class="quote-controls"></div>
 Exir.capture fails - missing get_random_input:</div>
<blockquote>
<p>It sounds like I need to define get_random_input method in my model. Right?</p>
</blockquote>
</aside>
<p>yes that is correct. In the code that tried, the expectation was that the model has “get_random_inputs” method specified on it. You can also just create a tuple of inputs (which is what the example code, I pointed you to, does) and supply that with exir.capture.</p>
<p>And no, <code>capture</code> cannot just take input dataset. It needs the tuple of example input to “trace” the model with.</p>

username: adonnini
cooked: <p>I was able to have <code>exir.capture</code> run the trace of my model (I think). However, now the code fails with the error listed below. Could yo please take a look and let me know what you think I am ding wrong and what I should do next?<br>
Thanks</p>
<pre><code class="lang-auto">&lt;executorch.exir.program._program.ExirExportedProgram object at 0x7f59c4f14f40&gt;
  0%|                                                                                                       | 0/25 [00:48&lt;?, ?it/s]
Traceback (most recent call last):
  File "/home/adonnini1/anaconda3/lib/python3.9/site-packages/torch/fx/passes/infra/pass_manager.py", line 270, in __call__
    res = fn(module)
  File "/home/adonnini1/anaconda3/lib/python3.9/site-packages/torch/fx/passes/infra/pass_base.py", line 41, in __call__
    self.ensures(graph_module)
  File "/home/adonnini1/Development/ContextQSourceCode/NeuralNetworks/trajectory-prediction-transformers-master/executorch/exir/passes/__init__.py", line 311, in ensures
    raise RuntimeError(f"Missing out variants: {self.missing_out_vars}")
RuntimeError: Missing out variants: {'aten::alias'}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/adonnini1/Development/ContextQSourceCode/NeuralNetworks/trajectory-prediction-transformers-master/train.py", line 318, in &lt;module&gt;
    open("tfmodel.pte", "wb").write(exir.capture(m, (enc_input, dec_input, dec_source_mask, dec_target_mask))
  File "/home/adonnini1/Development/ContextQSourceCode/NeuralNetworks/trajectory-prediction-transformers-master/executorch/exir/program/_program.py", line 181, in to_executorch
    new_prog = ep._transform(*edge_to_executorch_passes(config))
  File "/home/adonnini1/anaconda3/lib/python3.9/site-packages/torch/export/exported_program.py", line 569, in _transform
    res = pm(self.graph_module)
  File "/home/adonnini1/anaconda3/lib/python3.9/site-packages/torch/fx/passes/infra/pass_manager.py", line 296, in __call__
    raise Exception(msg) from e
Exception: An error occurred when running the 'ToOutVarPass' pass after the following passes: ['SpecPropPass', 'EdgeToBackendOpsPass', 'RemoveAssertAsyncPass', 'HintBasedSymShapeEvalPass']
</code></pre>

username: adonnini
cooked: <p>These are the executorch lines in my code:</p>
<pre><code class="lang-auto">        print(exir.capture(m, (enc_input, dec_input, dec_source_mask, dec_target_mask)).to_edge())
        open("tfmodel.pte", "wb").write(exir.capture(m, (enc_input, dec_input, dec_source_mask, dec_target_mask))
                                        .to_edge().to_executorch().buffer)
</code></pre>
<p>The failure occurs when trying to execute the <code>open</code> statement<br>
I don’t think <code>capture</code> is the problem as the print statement works as expected</p>