-
Notifications
You must be signed in to change notification settings - Fork 2k
[WASM] Add OneHot op #3409
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
[WASM] Add OneHot op #3409
Conversation
annxingyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pvaneck ! Just a few minor things.
| } | ||
|
|
||
| registerKernel({ | ||
| kernelName: 'OneHot', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import OneHot from core as well and use here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
tfjs-core/src/ops/one_hot.ts
Outdated
| const res = ENGINE.runKernelFunc( | ||
| forward, inputs as unknown as NamedTensorMap, null /* grad */, OneHot, | ||
| attrs as unknown as NamedAttrMap); | ||
| return reshape(res, outShape); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would like things like reshape to happen within the kernel as well. Could you add logic to reshape in the WASM OneHot typescript implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified the one hot op in core a bit so that flatten is moved into the forward function. To get the correct output shape in the WASM op, I need to pass in the original indices tensor (i.e. not flattened). I hope this is fine.
|
@annxingyuan Thanks for the review! Please take another look when you have a chance. |
annxingyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Thanks @pvaneck !
This adds the OneHot operation to the WebAssembly backend.
Closes: #3114
This change is