cli99 / llm-analysis Goto Github PK
View Code? Open in Web Editor NEWLatency and Memory Analysis of Transformer Models for Training and Inference
License: Apache License 2.0
Latency and Memory Analysis of Transformer Models for Training and Inference
License: Apache License 2.0
The latency i am getting here and the actual time when i am inferencing are not same. And also there is a huge difference between these two. So could be the problem?
Describe the bugMistral and Mixtral models not able to infer
When i give the name of the model as i do for other models in case of mistral there is a key error from the configuration_auto.py file in llm_analysis module. This is because there is no key with mistral in the config_map.
So could you also add all the models from hugging face which are not yet defined!!
Describe the bug
I tried with two unused hbm_memory_efficiency, 1 and 0.6 but ended up with the same value for (weight+op_state+grad+act)_memory_per_gpu. Is it possible that hbm_memory_efficiency is not working in the code?
To Reproduce
Steps to reproduce the behavior:
python -m llm_analysis.analysis train --model_name /hdd/echozhou/llm-analysis/examples/llama --gpu_name a100-pcie-40gb --activation_recomputation 1 --tp_size 1 --pp_size 3 --sp_size 1 --dp_size 1 --gradient_accumulation_steps 4 -b 16 --seq_len 1400 --total_num_gpus 3 --total_num_tokens 1e12 --activation_recomputation 2 --flops_efficiency 1 --hbm_memory_efficiency 0.6 --output_dir /hdd/echozhou/llm-analysis/examples/llama/test
python -m llm_analysis.analysis train --model_name /hdd/echozhou/llm-analysis/examples/llama --gpu_name a100-pcie-40gb --activation_recomputation 1 --tp_size 1 --pp_size 3 --sp_size 1 --dp_size 1 --gradient_accumulation_steps 4 -b 16 --seq_len 1400 --total_num_gpus 3 --total_num_tokens 1e12 --activation_recomputation 2 --flops_efficiency 1 --hbm_memory_efficiency 1 --output_dir /hdd/echozhou/llm-analysis/examples/llama/test
Expected behavior
The final memory consumption you get is all (weight+op_state+grad+act)_memory_per_gpu: 20.14 GB
Hi,
The function get_memory_activation_per_layer_layernorm() will return a value of seq_len * batch_size * hidden_dim / sp_size * dtype_bytes, which in fp16 will be 2sbh/s.
However, I find the paper Reducing Activation Recomputation in Large Transformer Models mentions that the activation memory of LayerNorm is 4sbh.
Unfortunately, I'm not so familiar with LLM memory consumption. Since other activation memory result fits the paper, I wonder if there exists a mistake inside the paper or there is a bug in this function?
Thanks,
Esar
Hello @cli99, Thank you very much for open-sourcing your library for analyzing large language models. This is very helpful for us to understand various optimization algorithms and parallel configuration strategies. After going through the code, I have encountered a few questions.
In the paper "Reducing Activation Recomputation in Large Transformer Models", there are two LayerNorms in one transformer layer. But in the code:
weight_memory_per_layer = (
weight_memory_attn_per_layer
+ weight_memory_mlp_per_layer
+ weight_memory_layernorm_per_layer
)
only one "weight_memory_layernorm_per_layer" is added.
Also in this paper, the blocks which can be parallelized using tensor parallelism are attention and mlp. But in the code below, LayerNorm can also be parallelized when tensor parallelism is applied.
weight_memory_layernorm_per_layer = (
self.get_num_params_per_layer_layernorm()
* self.dtype_config.weight_bits
/ BITS_PER_BYTE
/ self.parallelism_config.tp_size
/ sharded_dp_size
)
When I print the summary_dict in the provied python script in llama2 folder, it given me the following result:
{'batch_size_per_gpu': 1, 'seq_len': 512, 'tp_size': 2, 'ep_size': 1, 'pp_size': 1, 'num_tokens_to_generate': 32, 'flops_efficiency': 0.6, 'hbm_memory_efficiency': 0.6, 'layernorm_dtype_bytes': 2, 'use_kv_cache': True, 'kv_cache_latency': 0.00014570698054601933, 'kv_cache_memory_per_gpu': 89128960.0, 'weight_memory_per_gpu': 55292731392.0, 'weight_memory_embedding_per_gpu': 262144000.0, 'prefill_activation_memory_per_gpu': 16777216.0, 'prefill_max_batch_size_per_gpu': 1824, 'prefill_num_flops_fwd_total': 57305601146880.0, 'decode_activation_memory_per_gpu': 32768.0, 'decode_max_batch_size_per_gpu': 343, 'decode_num_flops_fwd_total': 110585446400.0, 'prefill_latency': 0.15908735621271564, 'prefill_latency_fwd_attn': 0.03487366607863248, 'prefill_latency_fwd_mlp': 0.11746919100170941, 'prefill_latency_fwd_layernorm': 0.001097087853522969, 'prefill_latency_fwd_tp_comm': 0.004473924266666667, 'prefill_latency_fwd_sharded_dp_comm': 0.0, 'prefill_latency_fwd_input_embedding': 0.00045651196944907646, 'prefill_latency_fwd_output_embedding_loss': 0.0007169750427350427, 'decode_latency': 0.04685015182136376, 'decode_latency_fwd_attn': 0.009875397743992155, 'decode_latency_fwd_mlp': 0.03510895406244892, 'decode_latency_fwd_layernorm': 2.1427497139120487e-06, 'decode_latency_fwd_tp_comm': 0.0012799999999999999, 'decode_latency_fwd_sharded_dp_comm': 0.0, 'decode_latency_fwd_input_embedding': 0.00043654994278240976, 'decode_latency_fwd_output_embedding_loss': 1.4003418803418803e-06, 'total_decode_latency': 1.4992048582836404, 'total_latency': 1.658292214496356, 'total_per_token_latency': 0.05182163170301113, 'prefill_tokens_per_sec': 3218.3575878613824, 'decode_tokens_per_sec': 21.344648013370964, 'total_tokens_per_sec': 19.296960885581193, 'prefill_cost_per_1k_tokens': 0.00038149203258474565, 'decode_cost_per_1k_tokens': 0.057521575291785504, 'total_cost_per_1k_tokens': 0.06362544781314144}
weight_memory_per_gpu is 55292731392.0, which is less 70B * 2 / 2 = 70B
So can you provide more information about this? Look forward to your response, thank you once again.
model_config.ffn_embed_dim is not used. Instead it used 4x hidden_dim
Is your feature request related to a problem? Please describe.
I recently wanted to test on T4, but I don't know how to measure intra_node information.
Describe the solution you'd like
The following is the T4 information I checked, including intra_node_bandwidth_in_GB_per_sec
intra_node_min_message_latency
inter_node_bandwidth_in_GB_per_sec
. I don’t know how to obtain it.
{
"name": "T4-pcie-16gb",
"mem_per_GPU_in_GB": 16,
"hbm_bandwidth_in_GB_per_sec": 320,
"intra_node_bandwidth_in_GB_per_sec": XXX,
"intra_node_min_message_latency": XXX,
"peak_fp16_TFLOPS": 65,
"peak_i8_TFLOPS": 130,
"peak_i4_TFLOPS": 260,
"inter_node_bandwidth_in_GB_per_sec": XXX
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.