Skip to content

[Question]How do I check whether kv cache int8 is effective? #394

Closed

Description

@wjj19950828

Currently I want to test the specific benchmark of weight only int8 + kvcache int8

The build command is as follows

python build.py --model_dir $model-path \
                --dtype float16 \
                --remove_input_padding \
                --use_gpt_attention_plugin float16 \
                --enable_context_fmha \
                --use_gemm_plugin float16 \
                --output_dir $output_path \
                --use_inflight_batching \
                --paged_kv_cache \
                --world_size 2 \
                --tp_size 2 \
                --max_batch_size 128 \
                --max_input_len 2048 \
                --max_output_len 2048 \
                --int8_kv_cache \
                --use_weight_only

How should I check that kv cache int8 has taken effect?

In addition, I would also like to ask if I want to use my own data set for kv cache quantification, how should I do this? Is there any guidance document? Thanks~

Activity

  1. wjj19950828 commented on Nov 16, 2023

    @wjj19950828
    Author

    @juney-nvidia

    Do you have any suggestions? Thanks~

  2. wm2012011492 commented on Nov 16, 2023

    @wm2012011492
    Collaborator

    @wjj19950828 please check the verbose building log which shows whether kv-cache (past_key_value_0 and present_key_value_0) is quantized.
    Layer(PluginV2): PLUGIN_V2_GPTAttention_1, Tactic: 0x0000000000000000, BloomForCausalLM/layers/0/attention/qkv/PLUGIN_V2_WeightOnlyQuantMatmul_0_output_0 (Half[-1,-1,6144]), Reformatted sequence_length (Int32[-1]), Reformatted host_past_key_value_lengths (Int32[-1]), Reformatted context_lengths (Int32[-1]), Reformatted cache_indirection (Int32[-1,1,-1]), Reformatted host_request_types (Int32[-1]), past_key_value_0 (Int8[-1,2,16,-1,128]), BloomForCausalLM/layers/0/attention/CONSTANT_1_output_0 (Float[1]), BloomForCausalLM/layers/0/attention/CONSTANT_2_output_0 (Float[1]), BloomForCausalLM/layers/0/attention/CONSTANT_0_output_0 (Half[1,16,1,1]), BloomForCausalLM/layers/0/attention/qkv/SHUFFLE_0_output_0 (Half[1,1,6144]) -> BloomForCausalLM/layers/0/attention/PLUGIN_V2_GPTAttention_1_output_0 (Half[-1,-1,2048]), present_key_value_0 (Int8[-1,2,16,-1,128])

  3. wjj19950828 commented on Nov 16, 2023

    @wjj19950828
    Author

    @wm2012011492

    Thank you for your reply~

    If I want to use my own data set for calibration and collect the corresponding scale, how should I do this?

  4. wjj19950828 commented on Nov 17, 2023

    @wjj19950828
    Author

    @byshiue @wm2012011492

    Hello, I currently measured some benchmark data of weight only int8 + kv cache int8 VS fp16 at 70b tp=4, as follows:

    bs tp input_len output_len latency(s) INT+KVQuant latency(s) FP16
    32 4 1536 512 34.08 31.39
    32 4 1024 1024 52.05 50.42
    32 4 512 1536 67.81 67.79
    64 4 1536 512 54.67 48.59
    64 4 1024 1024 77.27 72.24
    64 4 512 1526 95.64 92.60

    The build command is as above, modified to tp4

    The environment is A100, CUDA 11.8

    The test command is as follows:

    mpirun --allow-run-as-root -n 4 ./benchmarks/gptSessionBenchmark \
        --model llama \
        --engine_dir $MODEL_PATH \
        --batch_size "32;64" \
        --input_output_len "1536,512;1024,1024;512,1536"

    The current fp16 data converted from latency to generation throughput is almost in line with the official data.

    However, the performance of INT+KVQuant obviously does not meet expectations and is worse than FP16. Is this reasonable?

  5. wm2012011492 commented on Nov 17, 2023

    @wm2012011492
    Collaborator

    The weight-only solution is more suitable for smaller batchsize*beamwidth. You're recommended to use INT8 SmoothQuant + INT8 kv-cache for large batch size as for your case.

  6. wjj19950828 commented on Nov 17, 2023

    @wjj19950828
    Author

    @wm2012011492

    Thank you for your reply~

    But why is A16W8 slower than A16W16 under large bs?

    By the way, If i use SQ, how to use our own dataset?

  7. wm2012011492 commented on Nov 18, 2023

    @wm2012011492
    Collaborator

    Because A16W8 also uses FP16 tensor core and has the overhead of W8->W16. When batch size is small, the GEMM kernel is memory-bounded and W8 helps save memory-loading time.

  8. wm2012011492 commented on Nov 18, 2023

    @wm2012011492
    Collaborator

    Just change your dataset and following datapoint usage

  9. jdemouth-nvidia commented on Nov 23, 2023

    @jdemouth-nvidia
    Collaborator

    I’m closing that issue as all the questions have been answered. Feel free to reopen if needed. Thanks.

  10. wang90063 commented on Dec 13, 2023

    @wang90063

    why is NT8 SmoothQuant + INT8 kv-cache is more suitable for large batch size

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

Metadata

Metadata

Assignees

Labels

triagedIssue has been triaged by maintainers

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions