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

What does that mean?
This are the commands I ran
torch_1

Heres the full error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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 <listcomp>
    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 <listcomp>
    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 <listcomp>
    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
            >>> for name, module in model.named_children():
            >>>     if name in ['conv4', 'conv5']:
            >>>         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
                ~ <--- 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)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- 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

torchvision was recently made 100% TorchScript compatible, but only in the most recent version. Can you check that your torchvision and PyTorch version?

import torch
print(torch.__version__)

import torchvision
print(torchvision.__version__)
2 Likes

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 - (Prototype) Introduce lite interpreter workflow in Android and iOS — PyTorch Tutorials 1.9.0+cu102 documentation

here is my code -

import torch

model = torch.hub.load(‘ultralytics/yolov5’, ‘custom’,path=’/content/drive/MyDrive/yolov5/runs/train/exp51/weights/last.pt’)

model.eval()

scripted_module = torch.jit.script(model)

scripted_module.save("/content/drive/MyDrive/yolov5/runs/train/exp51/weights/last.pt")

scripted_module._save_for_lite_interpreter("/content/drive/MyDrive/yolov5/runs/train/exp51/weights/last.ptl")

Error screenshot