Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lobster.transforms.Lambda doesn't work properly #26

Open
karinazad opened this issue Jan 30, 2025 · 0 comments
Open

lobster.transforms.Lambda doesn't work properly #26

karinazad opened this issue Jan 30, 2025 · 0 comments

Comments

@karinazad
Copy link
Collaborator

lobster.transforms.Lambda seems broken

  1. needs to implement _check_inputs
  2. even with that implemented, it doesn't work properly on tuples. In the example below it gives an explicit error but in other cases, fails silently. I think the issue is with the implementation of Transform itself

Example:

Compare torchvision.transforms.Lambda which gives the expected output

from torchvision.transforms import Lambda

transform = Lambda(lambda item: (item[0] + 1, item[1]))

transform((1, 1))

>>> (2, 1)

and lobster.transforms.Lambda

from lobster.transforms import Lambda

transform = Lambda(lambda item: (item[0] + 1, item[1]))

transform((1, 1))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[31], line 5
      1 from lobster.transforms import Lambda
      3 transform = Lambda(lambda item: (item[0] + 1, item[1]))
----> 5 transform((1, 1))

File ~/Desktop/code/lobster/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py:1736, in Module._wrapped_call_impl(self, *args, **kwargs)
   1734     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]
   1735 else:
-> 1736     return self._call_impl(*args, **kwargs)

File ~/Desktop/code/lobster/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py:1747, in Module._call_impl(self, *args, **kwargs)
   1742 # If we don't have any hooks, we want to skip the rest of the logic in
   1743 # this function, and just call forward.
   1744 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
   1745         or _global_backward_pre_hooks or _global_backward_hooks
   1746         or _global_forward_hooks or _global_forward_pre_hooks):
-> 1747     return forward_call(*args, **kwargs)
   1749 result = None
   1750 called_always_called_hooks = set()

File ~/Desktop/code/lobster/src/lobster/transforms/_transform.py:105, in Transform.forward(self, *inputs)
    103 for x, transformable in zip(flattened, transformables):
    104     if transformable:
--> 105         y = self._transform(x, inputs)
    106     else:
    107         y = x

File ~/Desktop/code/lobster/src/lobster/transforms/_lambda.py:46, in Lambda._transform(self, input, parameters)
     29 """
     30 Parameters
     31 ----------
   (...)
     43 
     44 """
     45 if isinstance(input, self._types):
---> 46     return self._fn(input)
     47 else:
     48     return input

Cell In[31], line 3
      1 from lobster.transforms import Lambda
----> 3 transform = Lambda(lambda item: (item[0] + 1, item[1]))
      5 transform((1, 1))

TypeError: 'int' object is not subscriptable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant