lf1-io / padl

Functional deep learning
Apache License 2.0
106 stars 4 forks source link

Sheen import/ save bug with `value` #372

Closed blythed closed 2 years ago

blythed commented 2 years ago

🐞 Bug

Symfinder seems not able to find the serializer.

In branch padl

from models.padl_test.config import *

Error:

---------------------------------------------------------------------------
NameNotFound                              Traceback (most recent call last)
<ipython-input-1-471d2d396f8e> in <module>
     11 
     12 import importlib
---> 13 cf = importlib.import_module(f'models.{EXPERIMENT}.config')
     14 
     15 GENERATOR_PIPELINE = cf.GENERATOR_PIPELINE

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/_bootstrap.py in _gcd_import(name, package, level)

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/_bootstrap.py in _find_and_load(name, import_)

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/_bootstrap.py in _load_unlocked(spec)

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/_bootstrap_external.py in exec_module(self, module)

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

~/lf1-io/sheen/models/padl_test/config.py in <module>
     46 )
     47 
---> 48 ICA = value(
     49     val=ICA_SKLEARN,
     50     serializer=SERIALIZER,

~/lf1-io/padl/padl/dumptools/serialize.py in value(val, serializer)
    132     source = sourceget.get_source(caller_frameinfo.filename)
    133     sourceget.put_into_cache(caller_frameinfo.filename, sourceget.original(source),
--> 134                              _serialize(val, serializer=serializer), *locs)
    135     return val

~/lf1-io/padl/padl/dumptools/serialize.py in _serialize(val, serializer)
    120 def _serialize(val, serializer=None):
    121     if serializer is not None:
--> 122         return Serializer(val, *serializer).varname
    123     if hasattr(val, '__len__') and len(val) > 10:
    124         return json_serializer(val).varname

~/lf1-io/padl/padl/dumptools/serialize.py in __init__(self, val, save_function, load_function, file_suffix, module)
     42         self.scope = symfinder.Scope.toplevel(module)
     43         self.load_codegraph = (
---> 44             var2mod.CodeGraph.build(ScopedName(load_function.__name__, self.scope))
     45         )
     46         self.load_name = load_function.__name__

~/lf1-io/padl/padl/dumptools/var2mod.py in build(cls, scoped_name)
    875 
    876             # find how next_var came into being
--> 877             next_codenode = find_codenode(next_name)
    878             graph[next_name] = next_codenode
    879 

~/lf1-io/padl/padl/dumptools/var2mod.py in find_codenode(name, full_dump_module_names)
    619 def find_codenode(name: ScopedName, full_dump_module_names=None):
    620     """Find the :class:`CodeNode` corresponding to a :class:`ScopedName` *name*. """
--> 621     (source, node), scope_of_next_var, found_name = find_in_scope(name)
    622 
    623     module_name = None

~/lf1-io/padl/padl/dumptools/symfinder.py in find_in_scope(name)
    664     if scope.module is None:
    665         raise NameNotFound(f'{name.name} not found in function hierarchy.')
--> 666     source, node, name = find(name.name, scope.module, i)
    667     if getattr(node, '_globalscope', False):
    668         scope = Scope.empty()

~/lf1-io/padl/padl/dumptools/symfinder.py in find(var_name, module, i)
    798         module = sys.modules['__main__']
    799     try:
--> 800         return find_in_module(var_name, module, i)
    801     except TypeError as exc:
    802         if module is not sys.modules['__main__']:

~/lf1-io/padl/padl/dumptools/symfinder.py in find_in_module(var_name, module, i)
    730     """
    731     source = sourceget.get_module_source(module)
--> 732     return find_in_source(var_name, source, i=i)
    733 
    734 

~/lf1-io/padl/padl/dumptools/symfinder.py in find_in_source(var_name, source, tree, i, return_partial)
    718     if return_partial:
    719         return i
--> 720     raise NameNotFound(f'{var_name} not found.')
    721 
    722 

NameNotFound: load_sklearn not found.