程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在 pytorch 中从 jit 创建检查点时,如何修复 RuntimeError: builtin cannot be used as a value (with a dict)?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决在 pytorch 中从 jit 创建检查点时,如何修复 RuntimeError: builTin cAnnot be used as a value (with a Dict)??

开发过程中遇到在 pytorch 中从 jit 创建检查点时,如何修复 RuntimeError: builTin cAnnot be used as a value (with a Dict)?的问题如何解决?下面主要结合日常开发的经验,给出你关于在 pytorch 中从 jit 创建检查点时,如何修复 RuntimeError: builTin cAnnot be used as a value (with a Dict)?的解决方法建议,希望对你解决在 pytorch 中从 jit 创建检查点时,如何修复 RuntimeError: builTin cAnnot be used as a value (with a Dict)?有所启发或帮助;

我想使用 jit 编译任意 nn 模块。

在我的代码中,我将我的值与字典进行比较,但它会引发错误

        """
        if type(Json_data) is Dict:
                              ~~~~ <--- HERE

复制

简单,任何与字典进行比较的代码:

class Node(object):
    def __init__(self):
        pass

    @classmethod
    def from_Json(cls,Json_data):
        if type(Json_data) is Dict:
            node_data = next(iter(Json_data))
            assert type(Json_data[node_data]) is List
            node_children = [cls.from_Json(child) for child in Json_data[node_data]]
            return Node(node_data,node_children)
        else:
            return Node(Json_data)

预期行为

Jit 成为我的检查点。

环境

  • PyTorch/torchvision 版本(例如 1.0/0.4.0):1.7.1
  • 操作系统(例如 linux):Mac OS X
  • 您如何安装 PyTorch/torchvision(condapip,来源):conda
  • 您使用的构建命令(如果从源代码编译):conda
  • Python 版本:3.8
  • CUDA/cuDNN 版本:cpu
  • GPU 型号和配置:cpu
  • 任何其他相关信息:cpu

附加上下文

将任意自定义 nn 模块编译为 jit

错误:

/Users/brando/anaconda3/envs/coq_gym/bin/python /Applications/PyCharm.app/Contents/plugins/python/Helpers/pydev/pydevd.py --cmd-line --multiproc --qt-support=auto --clIEnt 127.0.0.1 --port 59213 --file /Users/brando/ML4Coq/playground/running_pytorch_ocaml/treenn2jit_ckpt.py
Connected to pydev deBUGger (build 203.7148.72)
1.7.1
TraceBACk (most recent call last):
  file "/Users/brando/anaconda3/envs/coq_gym/lib/python3.7/site-packages/torch/jit/_recursive.py",line 680,in compile_unbound_method
    create_methods_and_propertIEs_from_stubs(concrete_type,(stub,),())
  file "/Users/brando/anaconda3/envs/coq_gym/lib/python3.7/site-packages/torch/jit/_recursive.py",line 304,in create_methods_and_propertIEs_from_stubs
    concrete_type._create_methods_and_propertIEs(property_defs,property_rcbs,method_defs,method_rcbs,method_defaults)
  file "/Users/brando/anaconda3/envs/coq_gym/lib/python3.7/site-packages/torch/jit/Annotations.py",line 330,in try_Ann_to_type
    torch.jit._script._recursive_compile_class(Ann,loC)
  file "/Users/brando/anaconda3/envs/coq_gym/lib/python3.7/site-packages/torch/jit/_script.py",line 1056,in _recursive_compile_class
    _compile_and_register_class(obj,rcb,_qual_Name)
  file "/Users/brando/anaconda3/envs/coq_gym/lib/python3.7/site-packages/torch/jit/_script.py",line 64,in _compile_and_register_class
    torch._C._jit_script_class_compile(qualifIEd_name,ast,defaults,rcb)
RuntimeError: 
builTin cAnnot be used as a value:
  file "/Users/brando/ML4Coq/ml4coq-proj/embeddings_zoo/extract_tactic_from_lasse_data.py",line 56
            term = String
        """
        if type(Json_data) is Dict:
                              ~~~~ <--- HERE
            node_data = next(iter(Json_data))
            assert type(Json_data[node_data]) is List
'Node.from_Json' is being compiled since it was called from '__torch__.embeddings_zoo.extract_tactic_from_lasse_data.Node'

相关:

  • https://github.com/pytorch/vision/issues/3392
  • https://github.com/pytorch/vision/issues/1675

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

@H_674_73@

大佬总结

以上是大佬教程为你收集整理的在 pytorch 中从 jit 创建检查点时,如何修复 RuntimeError: builtin cannot be used as a value (with a dict)?全部内容,希望文章能够帮你解决在 pytorch 中从 jit 创建检查点时,如何修复 RuntimeError: builtin cannot be used as a value (with a dict)?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。