【问题标题】:I'm getting this error while trying to convert my torch model to torchscript尝试将我的火炬模型转换为火炬脚本时出现此错误
【发布时间】:2022-08-04 10:55:30
【问题描述】:

我对 torchscript 和 JIT 比较陌生,并且收到此错误:

    raise NotSupportedError(ctx_range, _vararg_kwarg_err)
torch.jit.frontend.NotSupportedError: Compiled functions can\'t take variable number of arguments or use keyword-only arguments with defaults:
  File \"/home/anushka/airborne-detection-starter-kit/seg_tracker/models_transformation.py\", line 60
    def updated_forward(*args, **kwargs):
                                ~~~~~~~ <--- HERE
        a = (tsm(args[0], duration=duration, dilation=dilation), ) + args[1:]
        return orig_forward(*a, **kwargs)

这是我的转发函数,它采用 args 和 kwargs 参数。任何人都可以帮助我在没有错误的情况下传递这些论点

def add_tsm_to_module(obj, duration, dilation=1):
    orig_forward = obj.forward

    def updated_forward(*args, **kwargs):
        a = (tsm(args[0], duration=duration, dilation=dilation), ) + args[1:]
        return orig_forward(*a, **kwargs)

    obj.forward = updated_forward

    return obj

    标签: python pytorch jit mlops torchscript


    【解决方案1】:

    嘿@anushka agarwal 你能解决这个问题吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      • 2023-04-01
      • 2021-02-08
      • 1970-01-01
      • 2017-02-23
      • 1970-01-01
      • 2020-01-23
      相关资源
      最近更新 更多