lf1-io / padl

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

Binding signature parameters in lambda functions doesn't work #386

Closed blythed closed 2 years ago

blythed commented 2 years ago

🐞 Bug

Code:

from padl import transform

def mytrans(x, y):
    return x

def get_transform(the_parameter):
    return (
        transform(lambda x: mytrans(x, the_parameter))
        >> transform(lambda x: mytrans(x, the_parameter))
    )

Error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-3-a5adce428530> in <module>
----> 1 pl = get_transform(2)

~/lf1-io/sheen/test.py in get_transform(the_parameter)
      6 def get_transform(the_parameter):
      7     return (
----> 8         transform(lambda x: mytrans(x, the_parameter))
      9         >> transform(lambda x: mytrans(x, the_parameter))
     10     )

~/lf1-io/padl/padl/wrap.py in transform(wrappee, ignore_scope)
    291             return _wrap_class_instance(wrappee, ignore_scope)
    292         if wrappee.__name__ == '<lambda>':
--> 293             return _wrap_lambda(wrappee, ignore_scope)
    294         return _wrap_function(wrappee, ignore_scope)
    295     raise ValueError('Can only wrap classes or callables.')

~/lf1-io/padl/padl/wrap.py in _wrap_lambda(fun, ignore_scope)
    213
    214     if call is None or not found:
--> 215         raise RuntimeError('Lambda not found.')
    216
    217     locs = (

RuntimeError: Lambda not found.

System:

Further Info:

Bug goes away if the parameters which are bound into the lambda function are not in the signature, i.e.:

from padl import transform

def mytrans(x, y):
    return x

def get_transform():
    return (
        transform(lambda x: mytrans(x, 2))
        >> transform(lambda x: mytrans(x, 2))
    )