torch.jit.frontend.UnsupportedNodeError: Yield aren't supported:

martinoywa: <p>What does that mean?<br>
This are the commands I ran<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/5/a/5a513953a1ca15ec16136b21591784dd86f63b84.png" alt="torch_1" data-base62-sha1="cSYZCds01baJRZJzd6af36ZWtmY" width="560" height="129"></p>
<p>Heres the full error:</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/__init__.py", line 1203, in script
    return torch.jit.torch.jit._recursive.recursive_script(obj)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/_recursive.py", line 173, in recursive_script
    return copy_to_script_module(mod, overload_stubs + stubs)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/_recursive.py", line 95, in copy_to_script_module
    torch.jit._create_methods_from_stubs(script_module, stubs)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/__init__.py", line 1423, in _create_methods_from_stubs
    self._c._create_methods(self, defs, rcbs, defaults)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/_recursive.py", line 195, in make_strong_submodule
    new_strong_submodule = recursive_script(module)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/_recursive.py", line 116, in recursive_script
    return create_constant_iterable_module(mod)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/_recursive.py", line 233, in create_constant_iterable_module
    modules[key] = recursive_script(submodule)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/_recursive.py", line 173, in recursive_script
    return copy_to_script_module(mod, overload_stubs + stubs)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/_recursive.py", line 95, in copy_to_script_module
    torch.jit._create_methods_from_stubs(script_module, stubs)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/__init__.py", line 1423, in _create_methods_from_stubs
    self._c._create_methods(self, defs, rcbs, defaults)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/_recursive.py", line 181, in create_method_from_fn
    stub = torch.jit.script_method(fn, _jit_internal.createResolutionCallbackFromClosure(fn))
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/__init__.py", line 1280, in script_method
    ast = get_jit_def(fn, self_name="ScriptModule")
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 169, in get_jit_def
    return build_def(ctx, py_ast.body[0], type_line, self_name)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 209, in build_def
    build_stmts(ctx, body))
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 127, in build_stmts
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 127, in &lt;listcomp&gt;
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 185, in __call__
    return method(ctx, node)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 346, in build_For
    [build_expr(ctx, stmt.iter)], build_stmts(ctx, stmt.body))
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 127, in build_stmts
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 127, in &lt;listcomp&gt;
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 185, in __call__
    return method(ctx, node)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 352, in build_If
    build_stmts(ctx, stmt.body),
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 127, in build_stmts
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 127, in &lt;listcomp&gt;
    stmts = [build_stmt(ctx, s) for s in stmts]
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 185, in __call__
    return method(ctx, node)
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 279, in build_Expr
    return ExprStmt(build_expr(ctx, value))
  File "/home/oywa/.local/lib/python3.6/site-packages/torch/jit/frontend.py", line 184, in __call__
    raise UnsupportedNodeError(ctx, node)
torch.jit.frontend.UnsupportedNodeError: Yield aren't supported:
at /home/oywa/.local/lib/python3.6/site-packages/torch/nn/modules/module.py:980:16
            &gt;&gt;&gt; for name, module in model.named_children():
            &gt;&gt;&gt;     if name in ['conv4', 'conv5']:
            &gt;&gt;&gt;         print(module)

        """
        memo = set()
        for name, module in self._modules.items():
            if module is not None and module not in memo:
                memo.add(module)
                yield name, module
                ~ &lt;--- HERE
'__torch__.torchvision.models.densenet.___torch_mangle_79._DenseBlock.forward' is being compiled since it was called from '__torch__.torchvision.models.densenet.___torch_mangle_67.DenseNet.forward'
at /home/oywa/.local/lib/python3.6/site-packages/torchvision/models/densenet.py:155:8
    def forward(self, x):
        features = self.features(x)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~ &lt;--- HERE
        out = F.relu(features, inplace=True)
        out = F.adaptive_avg_pool2d(out, (1, 1))
        out = torch.flatten(out, 1)
        out = self.classifier(out)
        return out

</code></pre>

driazati: <p>torchvision was recently made 100% TorchScript compatible, but only in the most recent version. Can you check that your torchvision and PyTorch version?</p>
<pre><code class="lang-python">import torch
print(torch.__version__)

import torchvision
print(torchvision.__version__)
</code></pre>

Mansi_Sathawane: <p>I am referring below link for converting .pt to .ptl(PyTorch lite) but I am facing some issue to execute this, please check my code and let me know if I am doing anything wrong - <a href="https://pytorch.org/tutorials/prototype/lite_interpreter.html" class="inline-onebox" rel="noopener nofollow ugc">(Prototype) Introduce lite interpreter workflow in Android and iOS — PyTorch Tutorials 1.9.0+cu102 documentation</a></p>
<p><strong>here is my code -</strong></p>
<p>import torch</p>
<p>model = torch.hub.load(‘ultralytics/yolov5’, ‘custom’,path=‘/content/drive/MyDrive/yolov5/runs/train/exp51/weights/last.pt’)</p>
<p>model.eval()</p>
<p>scripted_module = torch.jit.script(model)</p>
<p>scripted_module.save(“/content/drive/MyDrive/yolov5/runs/train/exp51/weights/last.pt”)</p>
<p>scripted_module._save_for_lite_interpreter(“/content/drive/MyDrive/yolov5/runs/train/exp51/weights/last.ptl”)</p>
<p>Error screenshot<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/0/7/07c810567ceeeb31356433c5cd708765517ab6bf.png" data-download-href="https://discuss.pytorch.org/uploads/default/07c810567ceeeb31356433c5cd708765517ab6bf" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/0/7/07c810567ceeeb31356433c5cd708765517ab6bf_2_690x338.png" alt="image" data-base62-sha1="16PYzMnhYzU0BYs5eQXOHEwBNuv" width="690" height="338" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/0/7/07c810567ceeeb31356433c5cd708765517ab6bf_2_690x338.png, https://discuss.pytorch.org/uploads/default/optimized/3X/0/7/07c810567ceeeb31356433c5cd708765517ab6bf_2_1035x507.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/0/7/07c810567ceeeb31356433c5cd708765517ab6bf_2_1380x676.png 2x" data-dominant-color="F7F7F8"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1570×770 186 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>