code: def timestep_embedding(timesteps, dim, max_period=10000):
      """
      Create sinusoidal timestep embeddings.
  
      :param timesteps: a 1-D Tensor of N indices, one per batch element.
                        These may be fractional.
      :param dim: the dimension of the output.
      :param max_period: controls the minimum frequency of the embeddings.
      :return: an [N x dim] Tensor of positional embeddings.
      """
      half = dim // 2
      freqs = paddle.exp(
          -math.log(max_period)
          * paddle.arange(start=0, end=half, dtype=paddle.float32)
          / half
      )
      args = paddle.cast(timesteps[:, None], "float32") * freqs[None]
      embedding = paddle.concat(
          [paddle.cos(args), paddle.sin(args)], axis=-1
      )
      if dim % 2:
          embedding = paddle.concat(
              [embedding, paddle.zeros_like(embedding[:, :1])], axis=-1
          )
      return embedding
  
file_path: PaddleHub/modules/image/text_to_image/disco_diffusion_cnclip_vitb16/reverse_diffusion/model/nn.py
imports: import math
  import paddle
  import paddle.nn
label_desc: Use image node_id 9 for calling a global function with example usage: timestep_embedding(timesteps, dim, max_period) and returns: embedding