Advertisement
Midhilesh

1.58bit_LLM

Mar 5th, 2024
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. def absmean_quantization_activation(A):
  2.     # Find the maximum absolute value in the activation array
  3.     max_val = np.max(np.abs(A))
  4.    
  5.     # Avoid scaling factor that would make zero a quantized value
  6.     scaling_factor = 1 / max_val if max_val != 0 else 1
  7.    
  8.     # Scale the activation matrix to the range [-1, 1]
  9.     scaled_A = A * scaling_factor
  10.    
  11.     # Apply RoundClip function to each element of the scaled matrix
  12.     quantized_A = np.vectorize(lambda x: round_clip(x, -1, 1))(scaled_A)
  13.  
  14.     return quantized_A
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement