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

feat: support embedding_bag converter (1D input) #2395

Merged
merged 3 commits into from
Oct 25, 2023

Conversation

zewenli98
Copy link
Collaborator

@zewenli98 zewenli98 commented Oct 12, 2023

Description

Support embedding_bag converter. Currently, only 1D input is supported.
schema: https://github.com/pytorch/pytorch/blob/bdecdfd202df3fa25fd9998070fd19fee4b14971/aten/src/ATen/native/native_functions.yaml#L2251
pytorch doc: https://pytorch.org/docs/stable/generated/torch.nn.functional.embedding_bag.html#torch-nn-functional-embedding-bag

Note:

  1. We currently only support 1D input because, in PyTorch, offsets is only used when input is 1D. If input is 2D of shape (B, N), it will be treated as B bags (sequences) each of fixed length N, and this will return B values aggregated in a way depending on the mode. offsets is ignored and required to be None in this case. However, according to the schema, offsets is required for input with any dimensions. There's no place describing how it works. There's a discussion in pytorch repo
  2. Currently, we expect the arg offsets to be ndarray or torch tensor because we need to access data in it, but offsets could be ITensor in some cases, which cannot be accessed.

Fixes #2345

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@zewenli98 zewenli98 self-assigned this Oct 12, 2023
@github-actions github-actions bot added component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests labels Oct 12, 2023
@github-actions github-actions bot requested a review from apbose October 12, 2023 20:25
Copy link
Collaborator

@gs-olive gs-olive left a comment

Choose a reason for hiding this comment

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

See comments for suggestions on improved type enforcement. It seems for this specific case, some operators have args[2] as a proper input, so it might be challenging to convert more generally with this numpy restriction.

@zewenli98
Copy link
Collaborator Author

Thanks for the review. The issues above have been addressed!

Copy link
Collaborator

@gs-olive gs-olive left a comment

Choose a reason for hiding this comment

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

Looks good to me, pending CI!

@zewenli98 zewenli98 merged commit cb20f90 into pytorch:main Oct 25, 2023
15 of 19 checks passed
@zewenli98 zewenli98 mentioned this pull request Oct 27, 2023
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement embedding bag convertor
3 participants