lf1-io / padl

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

redo params #451

Closed wuhu closed 2 years ago

blythed commented 2 years ago

I'm testing this with this code:

from padl import params, transform

p = params('params', A=2, B=2)

def f(A=5, B=6):
    return (
        transform(lambda x: x + A)
        >> transform(lambda x: x + B)
    )

t = f(**p)

t.pd_save('test.padl', force_overwrite=True)

It works in IPython but not in python (when executing the module).

Error message from python <modulename>.py:

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    t = f(**p)
  File "test.py", line 7, in f
    transform(lambda x: x + A)
  File "/Users/dodo/lf1-io/padl/padl/wrap.py", line 277, in transform
    return _wrap_lambda(wrappee, ignore_scope)
  File "/Users/dodo/lf1-io/padl/padl/wrap.py", line 211, in _wrap_lambda
    caller = inspector.CallInfo(ignore_scope=ignore_scope)
  File "/Users/dodo/lf1-io/padl/padl/dumptools/inspector.py", line 50, in __init__
    self.scope = self._determine_scope(caller_frameinfo, drop_n, ignore_scope)
  File "/Users/dodo/lf1-io/padl/padl/dumptools/inspector.py", line 60, in _determine_scope
    return _get_scope_from_frame(caller_frameinfo.frame, drop_n)
  File "/Users/dodo/lf1-io/padl/padl/dumptools/inspector.py", line 94, in _get_scope_from_frame
    calling_scope = _get_scope_from_frame(frame.f_back, 0)
  File "/Users/dodo/lf1-io/padl/padl/dumptools/inspector.py", line 79, in _get_scope_from_frame
    if module.__name__ == '__main__' and _module(frame.f_back) != module:
  File "/Users/dodo/lf1-io/padl/padl/dumptools/inspector.py", line 191, in _module
    return frame.f_globals['_pd_module']
AttributeError: 'NoneType' object has no attribute 'f_globals'
wuhu commented 2 years ago

@blythed this should be fixed now.

codecov-commenter commented 2 years ago

Codecov Report

Merging #451 (95eec78) into main (46ad518) will decrease coverage by 0.76%. The diff coverage is 86.67%.

@@            Coverage Diff             @@
##             main     #451      +/-   ##
==========================================
- Coverage   89.06%   88.30%   -0.77%     
==========================================
  Files          15       16       +1     
  Lines        3008     3462     +454     
==========================================
+ Hits         2679     3057     +378     
- Misses        329      405      +76     
Impacted Files Coverage Δ
padl/wrap.py 94.36% <ø> (+3.76%) :arrow_up:
padl/dumptools/ast_utils.py 64.48% <68.33%> (+4.91%) :arrow_up:
padl/transforms.py 89.51% <79.26%> (-1.87%) :arrow_down:
padl/dumptools/config_tools.py 79.56% <79.56%> (ø)
padl/dumptools/symfinder.py 91.00% <89.52%> (+3.26%) :arrow_up:
padl/dumptools/inspector.py 92.59% <90.00%> (-0.31%) :arrow_down:
padl/dumptools/var2mod.py 94.06% <95.16%> (-0.73%) :arrow_down:
padl/__init__.py 100.00% <100.00%> (ø)
padl/dumptools/packagefinder.py 96.61% <100.00%> (+0.05%) :arrow_up:
padl/dumptools/serialize.py 88.88% <100.00%> (-2.32%) :arrow_down:
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 46ad518...95eec78. Read the comment docs.

jasonkhadka commented 2 years ago
from padl import *

@transform
class B:
    def __init__(self, x):
        ...
b = 1
b = B(b)
print(b._pd_dumps())

is still failing.

from padl import transform

b = 1

@transform
class B:
    def __init__(self, x):
        ...

b = B(b)
_pd_main = B(b)