Skip to content

feat: Allow for more flexible shapes #396

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

Merged
merged 13 commits into from
Apr 25, 2025
Merged

feat: Allow for more flexible shapes #396

merged 13 commits into from
Apr 25, 2025

Conversation

sebffischer
Copy link
Member

@sebffischer sebffischer commented Apr 25, 2025

Previously, only the batch dimension was allowed to be NA.
However, this assumption is too restrictive, as it does not allow for transformer-based architectures where the sequence dimension is unknown.
This PR changes this and NAs can now be at every position of the shape.
However, many nn() operators expect only the batch dimension to be unknown.
Therefore, the only_batch_unknown argument was added to PipeOpTorch that is TRUE by default and needs to be overwritten.
E.g. PipeOpTorchLinear can handle NAs, as long as they are now in the last dimension.
Other operators that can handle it are, e.g., activation functions or in the future the multihead-attention module.

This PR also improved the shape inference and fixed some other small bugs.

TODOs:

  • the infer_shapes() method must be adjusted. Now, we replace all NAs dimensions with an arbitrary dimension.
    we should also do this twice to check whether the results are compatible
  • check all occurences of assert_shape() and verify that we no longer make the assumption that only the batch dimension is NA
  • check the PipeOpTorch object implementations that they err gracefully --> PipeOpTorch now need to indicate whether they can handle NAs that are not in the batch dimension.
  • Update the documentation on the shape

NEWS.md Outdated
@@ -16,6 +16,7 @@
* feat: TabResNet learner now supports lazy tensors.
* feat: The `LearnerTorch` base class now supports the private method `$.ingress_tokens(task, param_vals)`
for generating the `torch::dataset`.
* feat: Shapes can now have multiple `NA`s and not only the batch dimension can be missing. However, most `nn()` operators still expect only one missing values and will throw an error if multiple dimensions are missing.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* feat: Shapes can now have multiple `NA`s and not only the batch dimension can be missing. However, most `nn()` operators still expect only one missing values and will throw an error if multiple dimensions are missing.
* feat: Shapes can now have multiple `NA`s and not only the batch dimension can be missing. However, most `nn()` operators still expect only one missing values and will throw an error if multiple dimensions are missing.
* feat: better inferring of output shapes via function `infer_shapes()`.

@sebffischer sebffischer merged commit f70fc60 into main Apr 25, 2025
6 checks passed
@sebffischer sebffischer deleted the flex-shape branch April 25, 2025 11:04
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

Successfully merging this pull request may close these issues.

1 participant