class_docstr: Define how to apply SVD algorithm.
  
  This periodic update and scheduling base SVD algorithm update the original
  weights to make lower rank by SVD for each update_freq steps. During the
  warmup steps, It adjust the rank from the original to target rank gradually.
class_docstr_tok: ["Define","how","to","apply","SVD","algorithm",".","This","periodic","update","and","scheduling","base","SVD","algorithm","update","the","original","weights","to","make","lower","rank","by","SVD","for","each","update_freq","steps",".","During","the","warmup","steps",",","It","adjust","the","rank","from","the","original","to","target","rank","gradually","."]
code: def project_training_weights(
      self, weight: tf.Tensor, step: tf.Tensor
  ) -> tf.Tensor:
      weight_rank = tf.math.minimum(weight.shape[-1], weight.shape[-2])
      self.update_training_weight(step, step + 1)
      if step % self.update_freq == 0:
          rank = self.rank
          if step < self.warmup_step:
              rank = tf.cast(
                  tf.math.round(
                      weight_rank * (self.warmup_step - step)
                      + self.rank * step
                  )
                  / self.warmup_step,
                  tf.int32,
              )
          rank = tf.math.minimum(rank, weight_rank)
  
          s, u, v = tf.linalg.svd(weight)
  
          if len(weight.shape) == 2:
              # FC Layer
              s = s[:rank]
              u = u[:, :rank]
              v = v[:, :rank]
          elif len(weight.shape) == 4:
              # Conv2D Layer
              s = s[:, :, :rank]
              u = u[:, :, :, :rank]
              v = v[:, :, :, :rank]
          else:
              raise NotImplementedError(
                  "Only for dimension=2 or 4 is supported."
              )
  
          sv = tf.matmul(tf.linalg.diag(s), v, adjoint_b=True)
  
          new_weight = tf.matmul(u, sv)
          self.update_training_weight(weight, new_weight)
  
      return weight
  
file_path: model-optimization/tensorflow_model_optimization/python/core/common/keras/compression/algorithms/periodical_update_and_scheduling.py
imports: from typing import List
  import tensorflow
  from tensorflow_model_optimization.python.core.common.keras.compression import algorithm
label_desc: Use image node_id 4 for calling the SVD obj's underlying member method code with example usage: obj.project_training_weights(weight, step) and returns: weight