Skip to content

llama smoothquant confusion #215

Closed
Closed

Description

@jackzhou121

llama smoothquant is quit different from https://github.com/mit-han-lab/smoothquant, and this code is make me confused:
apply_smoothing(scales, fc1_weights + gate_weights, layernorm_weights,
layernorm_bias, orig_dtype)

this smooth nothing, "fc1_weights + gate_weights" is a new tensor and why do this in code ?

Activity

  1. jdemouth-nvidia commented on Oct 31, 2023

    @jdemouth-nvidia
    Collaborator

    Hi @jackzhou121 ,

    I’m not sure to understand what you mean by it creates a new tensor and it smooths nothing.

    In fact, the MLP in Llama does:

    FC2(Silu(FC1(x)) * Gate(x))
    

    This code, unless I’m mistaken modifies the weights for both FC1 and Gate (those are lists so the + concatenates the two lists).

    The activations are smoothed in the RMSNorm that precedes the MLP. That’s what is recommended in the SmoothQuant paper as far as I know ;)

    Do you agree with that?

    Thanks,
    Julien

  2. added
    triaged
    on Oct 31, 2023
  3. jackzhou121 commented on Oct 31, 2023

    @jackzhou121
    Author

    Hi @jackzhou121 ,

    I’m not sure to understand what you mean by it creates a new tensor and it smooths nothing.

    In fact, the MLP in Llama does:

    FC2(Silu(FC1(x)) * Gate(x))
    

    This code, unless I’m mistaken modifies the weights for both FC1 and Gate (those are lists so the + concatenates the two lists).

    The activations are smoothed in the RMSNorm that precedes the MLP. That’s what is recommended in the SmoothQuant paper as far as I know ;)

    Do you agree with that?

    Thanks, Julien

    hi, thanks for your response and you are right. but there is another question, why do this:
    scales[layer_name_qkv]["x"] = scales[layer_name_q]["x"] / smoother

    smoothquant just smooth the weight, but here scales was divided by smoother? pls help to explain how scales used in int8 inference

  4. jdemouth-nvidia commented on Oct 31, 2023

    @jdemouth-nvidia
    Collaborator

    Those “scales” correspond to the magnitude of the activations (estimated over CNN DailyMail in the calibrate function).

    They are needed for SmoothQuant (to compute the smoothed scaling to apply to the activations) and for INT8 KV cache.

    If we apply SmoothQuant, we change the magnitude by scaling the activations. So, it’s needed to take that into account and update those tensors. That’s for this reason that the magnitude is divided by “smoother”.

    I hope it helps. Let me know if we can close that issue, please.

    Thanks,
    Julien

  5. elinx commented on Feb 5, 2024

    @elinx

    Those “scales” correspond to the magnitude of the activations (estimated over CNN DailyMail in the calibrate function).

    They are needed for SmoothQuant (to compute the smoothed scaling to apply to the activations) and for INT8 KV cache.

    If we apply SmoothQuant, we change the magnitude by scaling the activations. So, it’s needed to take that into account and update those tensors. That’s for this reason that the magnitude is divided by “smoother”.

    I hope it helps. Let me know if we can close that issue, please.

    Thanks, Julien

    Hi, I didn't quite get the point of dividing activations scales by the smoother again, as far as I know if you have already divided the LN weight by the smoother, you don't need to divided X(same to divide by scales) again and I see sq original code did not divide the scales again, something like the following:

    y=LN*(X/smoother) @ (W*smoother)
    y=(LN/smoother)*X@Wq
    

    did I miss something?

  6. goldberg2024 commented on Mar 6, 2024

    @goldberg2024

    Those “scales” correspond to the magnitude of the activations (estimated over CNN DailyMail in the calibrate function).
    They are needed for SmoothQuant (to compute the smoothed scaling to apply to the activations) and for INT8 KV cache.
    If we apply SmoothQuant, we change the magnitude by scaling the activations. So, it’s needed to take that into account and update those tensors. That’s for this reason that the magnitude is divided by “smoother”.
    I hope it helps. Let me know if we can close that issue, please.
    Thanks, Julien

    Hi, I didn't quite get the point of dividing activations scales by the smoother again, as far as I know if you have already divided the LN weight by the smoother, you don't need to divided X(same to divide by scales) again and I see sq original code did not divide the scales again, something like the following:

    y=LN*(X/smoother) @ (W*smoother)
    y=(LN/smoother)*X@Wq
    

    did I miss something?

    Same question!

  7. goldberg2024 commented on Mar 6, 2024

    @goldberg2024

    Those “scales” correspond to the magnitude of the activations (estimated over CNN DailyMail in the calibrate function).
    They are needed for SmoothQuant (to compute the smoothed scaling to apply to the activations) and for INT8 KV cache.
    If we apply SmoothQuant, we change the magnitude by scaling the activations. So, it’s needed to take that into account and update those tensors. That’s for this reason that the magnitude is divided by “smoother”.
    I hope it helps. Let me know if we can close that issue, please.
    Thanks, Julien

    Hi, I didn't quite get the point of dividing activations scales by the smoother again, as far as I know if you have already divided the LN weight by the smoother, you don't need to divided X(same to divide by scales) again and I see sq original code did not divide the scales again, something like the following:

    y=LN*(X/smoother) @ (W*smoother)
    y=(LN/smoother)*X@Wq
    

    did I miss something?

    Same question!

    I get it now.
    The values in scales[layer_name_q]["x"] were collected before smooth, so we need to adjust scales[layer_name_q]["x"] by dividing smoother.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions