You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

EmbeddingLookUpLink.py 739 B

5 years ago
123456789101112131415161718192021
  1. from __future__ import absolute_import
  2. import ctypes
  3. from .._base import _LIB
  4. from .. import ndarray as _nd
  5. def embedding_lookup(in_mat, ids, out_mat, stream=None):
  6. assert isinstance(in_mat, _nd.NDArray)
  7. assert isinstance(ids, _nd.NDArray)
  8. assert isinstance(out_mat, _nd.NDArray)
  9. _LIB.DLGpuEmbeddingLookUp(
  10. in_mat.handle, ids.handle, out_mat.handle, stream.handle if stream else None)
  11. def embedding_lookup_gradient(grad_out, ids, grad_in, stream=None):
  12. assert isinstance(grad_out, _nd.NDArray)
  13. assert isinstance(ids, _nd.NDArray)
  14. assert isinstance(grad_in, _nd.NDArray)
  15. _LIB.DLGpuEmbeddingLookUp_Gradient(
  16. grad_out.handle, ids.handle, grad_in.handle, stream.handle if stream else None)