feat!: complete embedding PyTorch Python API#821
Draft
voltjia wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
embeddingparameter list while keepinginput, weightas the leading tensors.[[deprecated]]compatibility overload.max_norm/norm_typerenormalization for shared CUDA backends and Ascend, and extend the existing test function.Motivation
#808 restored the two leading tensors but intentionally omitted
max_normandnorm_type. InfiniOps should expose the complete public Python contract even though it is a C++ library. This PR adds the missing behavior without multiplying every Python default into another overload.This is a follow-up to #808; no standalone issue is associated with it.
Type of Change
feat- new feature / new operator / new platformfix- bug fixperf- performance improvement (no behavioral change)refactor- code restructuring without behavior changetest- adding or fixing tests onlydocs- documentation onlybuild/ci- build system or CI configurationchore- tooling, formatting, or other non-code changesPlatforms Affected
WITH_CPU)WITH_NVIDIA)WITH_ILUVATAR)WITH_METAX)WITH_CAMBRICON)WITH_MOORE)WITH_ASCEND)WITH_TORCH)Smoke Test Result
Test Results on Supported Platforms
max_normpathsaclnnEmbeddingRenormbeforeaclnnEmbeddingBenchmark / Performance Impact
The default and no-
max_normpaths retain the existing lookup kernel. Supplyingmax_normadds selected-row norm reduction and in-place weight renormalization, matching PyTorch semantics.Notes for Reviewers
API alignment
embedding(input, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq, sparse, out)outremains last perCONTRIBUTING.md.embedding(input, weight, out)F.embedding(input, weight, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False, sparse=False)embedding(input, weight, padding_idx, scale_grad_by_freq, sparse, out)max_normmutates selected weight rows in place before lookup, following PyTorch native renorm and its CUDA implementation.aclnnEmbeddingRenormbefore lookup.padding_idx,scale_grad_by_freq, andsparseaffect backward semantics; InfiniOps has no embedding autograd/backward path, so the forward implementation accepts and stores them without changing lookup values.max_normandnorm_type, which is why the PR is markedfeat!; the previous user-facing full call remains available with[[deprecated]].