aten/src/ATen/native/EmbeddingBag.cpp
// Assumes all input tensors are contiguous.
// See NOTE [ embedding_bag Native Functions ] in native_functions.yaml for details
Assumes all input tensors are contiguous.
See NOTE [ embedding_bag Native Functions ] in native_functions.yaml for details
Assumes all input tensors are contiguous . See NOTE [ embedding_bag Native Functions ] in native_functions . yaml for details
Tensor _embedding_bag_backward(const Tensor &grad, const Tensor &indices,
                              const Tensor &offsets,
                              const Tensor &offset2bag,
                              const Tensor &bag_size_,
                              const Tensor &max_indices_,
                              int64_t num_weights,
                              bool scale_grad_by_freq, int64_t mode,
                              bool sparse) {
  auto indices_arg = TensorArg(indices, "indices", 1);
  checkScalarType("embedding_bag", indices_arg, kLong);
  checkContiguous("embedding_bag", indices_arg);
  auto offsets_arg = TensorArg(offsets, "offsets", 1);
  checkScalarType("embedding_bag", offsets_arg, kLong);
  checkContiguous("embedding_bag", offsets_arg);
  auto offset2bag_arg = TensorArg(offset2bag, "offset2bag", 1);
  checkScalarType("embedding_bag", offset2bag_arg, kLong);
  checkContiguous("embedding_bag", offset2bag_arg);
  if (sparse) {
    return at::_embedding_bag_sparse_backward(
        grad, indices, offsets, offset2bag, bag_size_, num_weights,
        scale_grad_by_freq, mode);
  } else {
    return at::_embedding_bag_dense_backward(
        grad, indices, offsets, offset2bag, bag_size_, max_indices_, num_weights,
        scale_grad_by_freq, mode);
  }
}
Tensor _embedding_bag_backward ( const Tensor & grad , const Tensor & indices , const Tensor & offsets , const Tensor & offset2bag , const Tensor & bag_size_ , const Tensor & max_indices_ , int64_t num_weights , bool scale_grad_by_freq , int64_t mode , bool sparse ) { auto indices_arg = TensorArg ( indices , " " , 1 ) ; checkScalarType ( " " , indices_arg , kLong ) ; checkContiguous ( " " , indices_arg ) ; auto offsets_arg = TensorArg ( offsets , " " , 1 ) ; checkScalarType ( " " , offsets_arg , kLong ) ; checkContiguous ( " " , offsets_arg ) ; auto offset2bag_arg = TensorArg ( offset2bag , " " , 1 ) ; checkScalarType ( " " , offset2bag_arg , kLong ) ; checkContiguous ( " " , offset2bag_arg ) ; if ( sparse ) { return at :: _embedding_bag_sparse_backward ( grad , indices , offsets , offset2bag , bag_size_ , num_weights , scale_grad_by_freq , mode ) ; } else { return at :: _embedding_bag_dense_backward ( grad , indices , offsets , offset2bag , bag_size_ , max_indices_ , num_weights , scale_grad_by_freq , mode ) ; } }
Assumes all input tensors are contiguous.
Assumes all input tensors are contiguous .