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

ONNX support for scalar unsqueeze #1690

Merged
merged 6 commits into from
Apr 25, 2024
Merged

Conversation

antimora
Copy link
Collaborator

There is case when we need to unsqueeze scalar. This came about in #1560. See ONNX graph screenshot down below.

Pull Request Template

Checklist

  • Confirmed that run-checks all script has been executed.
  • Made sure the book is up to date with changes in this PR.

Related Issues/PRs

  1. Support for 0-Dimensional Tensors in Burn #1689
  2. Convert ONNX graph inputs of 0-dim tensors to scalars #1688
  3. ONNX conversion: Only tensor input is valid Argument #1560

Changes

  1. Added Ignored new-type to ignore types in the module.
  2. Updated Model module to store device
  3. Updated unsqueeze to deal with scalar input type.
  4. Updated tests

Testing

  1. New unit tests
  2. Tested user onnx file
  3. run-checks.sh

telegram-cloud-photo-size-1-5557782741991401409-y

Copy link
Member

@laggui laggui left a comment

Choose a reason for hiding this comment

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

I'm somewhat ambivalent about these changes. Obviously, to support unsqueeze for scalars right now we have to do something like this.

But at the same time I feel like this is gonna come back to haunt us for other reasons 😅

This is just very isolated, and with the state of other ops that have different behavior for scalars (e.g., some just capture the value in a 1D tensor with a single element).

As an isolated change to support unsqueeze for scalars, this is fine. I'll leave my review as a comment for now, interested in hearing feedback from others (@nathanielsimard and yourself included)

crates/burn-import/src/burn/node/unsqueeze.rs Outdated Show resolved Hide resolved
@antimora antimora requested a review from laggui April 25, 2024 18:27
Copy link
Member

@nathanielsimard nathanielsimard left a comment

Choose a reason for hiding this comment

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

Same comment as @laggui, I think this is fine in the short term, but supporting scalar tensors from onnx without having to sync the device is very valuable, we'll have to think about how we can do it easily.

@antimora antimora merged commit 67ec06d into tracel-ai:main Apr 25, 2024
12 checks passed
syl20bnr pushed a commit that referenced this pull request Apr 26, 2024
* Revert 1c639c8

1c639c8?diff=unified&w=0

* Refactor by @laggui

* Refactor unsqueeze

* Add support for scalar unsqueeze

* Removed dead comment
@antimora antimora deleted the scalar-unsqueeze branch April 29, 2024 21:46
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.

None yet

3 participants