code: def one_hot_multiply(inputs, scale):
      """Performs (inputs * scale) % vocab_size in the one-hot space.
      Args:
      inputs: Tensor of shape `[..., vocab_size]`. Typically a soft/hard one-hot
          Tensor.
      scale: Tensor of shape `[..., vocab_size]`. Typically a soft/hard one-hot
          Tensor specifying how much to scale the corresponding one-hot vector in
          inputs. Soft values perform a "weighted scale": for example,
          scale=[0.2, 0.3, 0.5] performs a linear combination of
          0.2 * scaling by zero; 0.3 * scaling by one; and 0.5 * scaling by two.
      Returns:
      Tensor of same shape and dtype as inputs.
      """
      # TODO: Implement with circular conv1d.
      # inputs = torch.tensor(inputs)
      scale = scale.type(inputs.dtype)
      batch_shape = list(inputs.shape[:-1])
      vocab_size = inputs.shape[-1]
      # Form a [..., vocab_size, vocab_size] tensor. The ith row of the
      # batched vocab_size x vocab_size matrix represents scaling inputs by i.
      to_perm = torch.arange(vocab_size).unsqueeze(1).repeat(
          1, vocab_size
      ) * torch.arange(vocab_size).unsqueeze(0)
      permutation_matrix = one_hot(torch.fmod(to_perm, vocab_size))
      # Scale the inputs according to the permutation matrix of all possible scales.
      scaled_inputs = torch.einsum(
          "...v,avu->...au", inputs, permutation_matrix
      )
      scaled_inputs = torch.cat(
          (
              torch.zeros(batch_shape + [1, vocab_size]),
              scaled_inputs[..., 1:, :],
          ),
          dim=-2,
      )
      # Reduce rows of the scaled inputs by the scale values. This forms a
      # weighted linear combination of scaling by zero, scaling by one, and so on.
      outputs = torch.einsum("...v,...vu->...u", scale, scaled_inputs)
      return outputs
  
file_path: DIG/dig/ggraph/method/GraphDF/model/df_utils.py
imports: import sys
  import warnings
  import torch
  import torch.nn.functional
  import numpy
label_desc: Use image node_id 7 for calling a global function with example usage: one_hot_multiply(inputs, scale) and returns: outputs