Optimizing Latent Diffusion Model Training
Optimizing Latent Diffusion Model Training
Model Training
Bradley Aldous Ahmed M. Abdelmoniem
Queen Mary University of London Queen Mary University of London
London, United Kingdom London, United Kingdom
[Link]@[Link] [Link]@[Link]
Abstract 1 Introduction
Generative AI models are at the forefront of advancing cre- The advent of generative artificial intelligence (AI) has ush-
ative and analytical tasks, pushing the boundaries of what ered in a new era of innovation, enabling the creation of
machines can generate and comprehend. Among these, la- content that blurs the line between human and machine-
tent diffusion models represent significant advancements in generated output. At the forefront of this revolution are
generating high-fidelity audio and images. This study intro- latent diffusion models (LDMs), a class of generative models
duces a systematic approach to study GPU utilisation during that have demonstrated remarkable capability in producing
the training of these models by leveraging Weights & Biases high-fidelity audio and images. Among these, AudioLDM
and the PyTorch Profiler for detailed monitoring and profil- [15] and Stable Diffusion [21] represent significant advance-
ing. Our methodology is designed to uncover inefficiencies ments, leveraging the power of deep learning to synthesise
in GPU resource allocation, pinpointing bottlenecks in the content that is not only diverse and detailed but also respon-
training pipeline. The insights gained aim to guide the de- sive to nuanced prompts and inputs.
velopment of strategies for enhancing training efficiency, However, the computational demands of training such
potentially reducing computational costs and accelerating sophisticated models are substantial, necessitating efficient
the development cycle of generative AI models. This con- utilisation of hardware resources, particularly Graphics Pro-
tribution not only highlights the critical role of resource cessing Units (GPUs). GPUs have become the linchpin of
optimisation in scaling AI technologies but also opens new deep learning research and application, offering the parallel
avenues for research in efficient model training. processing capabilities required to manage the immense com-
putational load of these models. Despite their capabilities,
CCS Concepts: • Computing methodologies → Distributed optimising GPU usage to accommodate the intensive re-
artificial intelligence; • General and reference → Mea- quirements of generative AI remains a challenge. Inefficient
surement; Performance. resource utilisation not only prolongs training times but also
escalates costs and environmental impact, highlighting the
Keywords: deep learning, diffusion model, profiling need for focused research using profiling and monitoring
tools that can guide the optimisation of GPU usage. In the
ACM Reference Format: development of generative AI, identifying where and why
Bradley Aldous and Ahmed M. Abdelmoniem. 2024. Comparative bottlenecks occur in training processes is crucial for making
Profiling: Insights Into Latent Diffusion Model Training. In 4th them more efficient. Finding these bottlenecks can help in
Workshop on Machine Learning and Systems (EuroMLSys ’24), Apr improving the overall performance and efficiency of model
22, 2024, Athens, Greece. ACM, New York, NY, USA, 8 pages. https: training.
//[Link]/10.1145/3642970.3655847
This paper aims to identify bottlenecks and inefficiencies
in the training process, proposing optimisation strategies to
enhance computational efficiency. The key contributions of
Permission to make digital or hard copies of all or part of this work for this work are:
personal or classroom use is granted without fee provided that copies
are not made or distributed for profit or commercial advantage and that
copies bear this notice and the full citation on the first page. Copyrights • It introduces a systematic approach to studying GPU
for components of this work owned by others than the author(s) must utilisation during the training of LDMs, using popular
be honored. Abstracting with credit is permitted. To copy otherwise, or profiling and monitoring tools;
republish, to post on servers or to redistribute to lists, requires prior specific • It identifies specific areas of computational inefficiency
permission and/or a fee. Request permissions from permissions@[Link]. across two advanced machine learning models, high-
EuroMLSys ’24, Apr 22, 2024, Athens, Greece
lighting CPU-bound overhead and memory manage-
© 2024 Copyright held by the owner/author(s). Publication rights licensed
to ACM. ment in AudioLDM, and emphasising the computa-
ACM ISBN 979-8-4007-0541-0/24/04 tional load of convolution operations and matrix mul-
[Link] tiplications in Stable Diffusion;
176
EuroMLSys ’24, Apr 22, 2024, Athens, Greece Bradley Aldous and Ahmed M. Abdelmoniem
177
Comparative Profiling: Insights Into Latent Diffusion Model Training EuroMLSys ’24, Apr 22, 2024, Athens, Greece
[6]. GPUs, with their highly parallel structure, are exception- 2.4 Motivation
ally well-suited to handle the matrix and vector operations Despite the availability and potential of these profiling tools,
that are ubiquitous in deep learning algorithms. This capabil- their application in the optimisation of LDMs, particularly
ity has enabled the training of larger, more complex models in the context of sophisticated generative tasks like those
than was previously possible, pushing the boundaries of ar- performed by AudioLDM and Stable Diffusion, remains an
tificial intelligence research and application. In the realm of underexplored area. The integration of detailed profiling and
generative models, such as LDMs, efficient GPU utilisation monitoring into the training workflow of such models is cru-
becomes not just advantageous but essential. Even though cial for advancing our understanding of their performance
they are computationally lighter than many other state-of- characteristics and for unlocking new efficiencies in their
the-art methods, these models require substantial computa- use of GPU resources. While existing profiling studies have
tional resources to iteratively refine noise into high-fidelity made significant strides in understanding and improving the
outputs, a process that involves millions of parameters and performance of deep learning models, they predominantly
operations. Optimising GPU usage can lead to significant focus on standard benchmarks, such as ResNet and other
improvements in training speed, model performance, and image-based architectures [11, 28]. This approach neglects
energy efficiency, which is crucial in a time when compu- the unique challenges and computational demands posed
tational costs and environmental impacts are of increasing by LDMs, and more generally audio models, which differ
concern. markedly in architecture and data processing requirements.
Despite the critical role of GPUs in deep learning, achiev- Moreover, the scarcity of detailed profiling and optimisa-
ing optimal utilisation poses considerable challenges. These tion studies on LDMs for audio highlights a critical oversight
challenges stem from a variety of factors, including memory in the development of efficient and accessible generative
management, data transfer bottlenecks, and the efficient allo- models. By dedicating research efforts to the specific profil-
cation of computational tasks across GPU cores. Addressing ing of audio LDMs, this study represents a first effort towards
these issues requires a good understanding of both the model illuminating the computational bottlenecks and inefficiencies
architecture and the underlying hardware. The pursuit of inherent in these models and their training configurations.
efficient GPU utilisation thus stands at the crossroads of Uncovering these insights is crucial for driving future op-
technological innovation and responsible computing, high- timisations, enabling LDMs to be more efficiently trained
lighting the need for continuous improvement in the tools on a wider range of hardware, and democratising access to
and techniques that support deep learning workflows. cutting-edge generative technologies.
178
EuroMLSys ’24, Apr 22, 2024, Athens, Greece Bradley Aldous and Ahmed M. Abdelmoniem
Profiler
3.2.1 Metrics. Concurrently, Weights & Biases [5] is utilised
to track and visualise the metrics discussed below through-
Begin Training
out training runs, facilitating a thorough understanding of
training performance.
Initialise Weights
• GPU Utilisation measures the percentage of time the
& Biases
GPU is actively processing data over a certain period.
High utilisation indicates the GPU is being heavily
used.
• GPU Memory Allocated refers to the amount of GPU
Load memory (VRAM) assigned to a process. It’s crucial for
Model + Data (+) Text managing large datasets or complex computations that
require significant memory.
• GPU Power Usage shows the amount of power the
Figure 2. A high-level system diagram showing the experi- GPU is consuming in real-time. It’s important for man-
mental setup and the relation between the tools and models. aging the energy efficiency of the system and ensuring
Text data was only used with AudioLDM. the power supply can meet the GPU’s demands.
179
Comparative Profiling: Insights Into Latent Diffusion Model Training EuroMLSys ’24, Apr 22, 2024, Athens, Greece
180
EuroMLSys ’24, Apr 22, 2024, Athens, Greece Bradley Aldous and Ahmed M. Abdelmoniem
GPU Memory Allocated (%) GPU Memory Allocated (%) Training Loss GPU Utilisation (%)
181
Comparative Profiling: Insights Into Latent Diffusion Model Training EuroMLSys ’24, Apr 22, 2024, Athens, Greece
tools impose minimal overhead, enabling real-time decision- investigation would offer more nuanced insights into how
making, profiling tools, though resource-intensive, offer valu- different hardware configurations impact the efficiency of
able insights for optimising performance [28]. Furthermore, generative diffusion model training.
the development of SASSI, a precise, customisable profiling Lastly, future investigations into the trade-offs between
tool for GPUs, represents a significant advancement in ap- computational efficiency, model performance, and resource
plication characterisation and architectural exploration [27]. utilisation are crucial for designing models that not only
Efforts to optimise GPU memory usage in large dataset ap- achieve high accuracy but also operate efficiently in resource-
plications have also shown substantial reductions in data constrained environments.
transfer volumes, enhancing efficiency [22].
In the realm of distributed machine learning, innovations
like DC2 [3] and SIDCo [17] demonstrate significant advance- Acknowledgments
ments in minimising communication delays and speeding This work was supported by the UKRI and EPSRC under
up training processes through delay-aware compression con- grant EP/S022694/1.
trol and statistical-based gradient compression techniques,
respectively. Evaluations of distributed deep learning frame- References
works such as Horovod [24], DeepSpeed [20], and PyTorch
[1] Marcel Aach, Eray Inanc, Rakesh Sarma, Morris Riedel, and Andreas
Distributed Data Parallel [14] have highlighted their scala- Lintermann. 2023. Large scale performance analysis of distributed
bility and efficiency, showcasing their ability to effectively deep learning frameworks for convolutional neural networks. Journal
leverage cloud resources and improve training scalability of Big Data 10 (6 2023), 96. Issue 1. [Link]
across various GPU configurations [1, 9]. Additionally, a 00765-w
comparative study of frameworks like Caffe-MPI [12], CNTK [2] Martín Abadi, Ashish Agarwal, Paul Barham, Eugene Brevdo, Zhifeng
Chen, Craig Citro, Greg S. Corrado, Andy Davis, Jeffrey Dean, Matthieu
[23], MXNet [7], and TensorFlow [2] has identified key per- Devin, Sanjay Ghemawat, Ian Goodfellow, Andrew Harp, Geoffrey
formance bottlenecks and optimisation opportunities for Irving, Michael Isard, Yangqing Jia, Rafal Jozefowicz, Lukasz Kaiser,
training convolutional neural networks with synchronous Manjunath Kudlur, Josh Levenberg, Dandelion Mané, Rajat Monga,
SGD [25]. Sherry Moore, Derek Murray, Chris Olah, Mike Schuster, Jonathon
Shlens, Benoit Steiner, Ilya Sutskever, Kunal Talwar, Paul Tucker, Vin-
cent Vanhoucke, Vijay Vasudevan, Fernanda Viégas, Oriol Vinyals,
Pete Warden, Martin Wattenberg, Martin Wicke, Yuan Yu, and Xi-
6 Conclusion & Future Work aoqiang Zheng. 2015. TensorFlow: Large-Scale Machine Learning
This study provides an in-depth analysis of the computa- on Heterogeneous Systems. [Link] Software
tional efficiency and performance characteristics of Audi- available from [Link].
oLDM and Stable Diffusion, two advanced machine learning [3] Ahmed M. Abdelmoniem and Marco Canini. 2021. DC2: Delay-aware
Compression Control for Distributed Machine Learning. In IEEE IN-
models. The findings underscore the importance of tailored FOCOM 2021 - IEEE Conference on Computer Communications. 1–10.
optimisation strategies for different model architectures. [Link]
Future work should aim to further optimise the identi- [4] Lucas Bellaiche, Rohin Shahi, Martin Harry Turpin, Anya Ragnhild-
fied areas of computational inefficiency. For AudioLDM, this stveit, Shawn Sprockett, Nathaniel Barr, Alexander Christensen, and
Paul Seli. 2023. Humans versus AI: whether and why we prefer human-
could include efforts to reduce CPU-bound overhead and en-
created compared to AI-created artwork. Cognitive Research: Principles
hance memory management efficiency. For Stable Diffusion, and Implications 8 (7 2023), 42. Issue 1. [Link]
the focus could be on optimising convolution operations, 023-00499-6
possibly through the use of more efficient algorithms or [5] Lukas Biewald. 2020. Experiment Tracking with Weights and Biases.
hardware acceleration techniques. Additionally, exploring [Link] Software available from [Link].
the effects of different profiling tools and methodologies [6] Ebubekir BUBER and Banu DIRI. 2018. Performance Analysis and
CPU vs GPU Comparison for Deep Learning. In 2018 6th International
could provide valuable insights into the accuracy and over- Conference on Control Engineering Information Technology (CEIT). 1–6.
head of performance measurements, including the impact of [Link]
external system activities on training processes. [7] Tianqi Chen, Mu Li, Yutian Li, Min Lin, Naiyan Wang, Minjie Wang,
The study also highlights the potential of distributed train- Tianjun Xiao, Bing Xu, Chiyuan Zhang, and Zheng Zhang. 2015.
ing to significantly reduce training times, suggesting that MXNet: A Flexible and Efficient Machine Learning Library for Het-
erogeneous Distributed Systems. (12 2015). [Link]
further research into these strategies is warranted. Certainly, 01274
here’s a paragraph you could use for the future work section: [8] William Falcon and The PyTorch Lightning team. 2019. PyTorch Light-
In future work, a comprehensive exploration into the scala- ning. [Link]
bility of distributed training across a broader spectrum and [9] Attila Farkas, Krisztián Póra, Sándor Szénási, Gábor Kertész, and
larger quantity of GPU models is essential to validate the Róbert Lovas. 2022. Evaluation of a distributed deep learning frame-
work as a reference architecture for a cloud environment. In 2022
observed superlinear speedup phenomena in greater depth. IEEE 10th Jubilee International Conference on Computational Cyber-
By extending the range of GPU architectures tested, from netics and Cyber-Medical Systems (ICCC). 000083–000088. https:
consumer-grade cards to high-end data center GPUs, this //[Link]/10.1109/ICCC202255925.2022.9922765
182
EuroMLSys ’24, Apr 22, 2024, Athens, Greece Bradley Aldous and Ahmed M. Abdelmoniem
[10] Cong Fu, Keqiang Yan, Limei Wang, Wing Yee Au, Michael McThrow, Francisco, California, USA) (KDD ’16). Association for Computing Ma-
Tao Komikado, Koji Maruhashi, Kanji Uchino, Xiaoning Qian, and chinery, New York, NY, USA, 2135. [Link]
Shuiwang Ji. 2023. A Latent Diffusion Model for Protein Structure 2945397
Generation. arXiv:2305.04120 [[Link]] [24] Alexander Sergeev and Mike Del Balso. 2018. Horovod: fast and easy
[11] Dipesh Gyawali. 2023. Comparative Analysis of CPU and GPU Pro- distributed deep learning in TensorFlow. (2 2018). [Link]
filing for Deep Learning Models. (9 2023). [Link] abs/1802.05799
02521 [25] Shaohuai Shi, Qiang Wang, and Xiaowen Chu. 2017. Performance
[12] Yangqing Jia, Evan Shelhamer, Jeff Donahue, Sergey Karayev, Jonathan Modeling and Evaluation of Distributed Deep Learning Frameworks
Long, Ross Girshick, Sergio Guadarrama, and Trevor Darrell. 2014. on GPUs. (11 2017). [Link]
Caffe: Convolutional Architecture for Fast Feature Embedding. In Pro- [26] Jascha Sohl-Dickstein, Eric Weiss, Niru Maheswaranathan, and Surya
ceedings of the 22nd ACM International Conference on Multimedia (Or- Ganguli. 2015. Deep Unsupervised Learning using Nonequilibrium
lando, Florida, USA) (MM ’14). Association for Computing Machinery, Thermodynamics. Proceedings of the 32nd International Conference on
New York, NY, USA, 675–678. [Link] Machine Learning, 2256–2265.
[13] Chris Dongjoo Kim, Byeongchang Kim, Hyunmin Lee, and Gunhee [27] Mark Stephenson, Siva Kumar Sastry Hari, Yunsup Lee, Eiman
Kim. 2019. AudioCaps: Generating Captions for Audios in The Wild. In Ebrahimi, Daniel R. Johnson, David Nellans, Mike O’Connor, and
Proceedings of the 2019 Conference of the North American Chapter of the Stephen W. Keckler. 2015. Flexible software profiling of GPU archi-
Association for Computational Linguistics: Human Language Technolo- tectures. SIGARCH Comput. Archit. News 43, 3S (jun 2015), 185–197.
gies, Volume 1 (Long and Short Papers), Jill Burstein, Christy Doran, and [Link]
Thamar Solorio (Eds.). Association for Computational Linguistics, Min- [28] Ehsan Yousefzadeh-Asl-Miandoab, Ties Robroek, and Pinar Tozun.
neapolis, Minnesota, 119–132. [Link] 2023. Profiling and Monitoring Deep Learning Training Tasks. In
[14] Shen Li, Yanli Zhao, Rohan Varma, Omkar Salpekar, Pieter Noordhuis, Proceedings of the 3rd Workshop on Machine Learning and Systems
Teng Li, Adam Paszke, Jeff Smith, Brian Vaughan, Pritam Damania, (Rome, Italy) (EuroMLSys ’23). Association for Computing Machinery,
and Soumith Chintala. 2020. PyTorch Distributed: Experiences on New York, NY, USA, 18–25. [Link]
Accelerating Data Parallel Training. (6 2020). [Link]
2006.15704
[15] Haohe Liu, Zehua Chen, Yi Yuan, Xinhao Mei, Xubo Liu, Danilo
Mandic, Wenwu Wang, and Mark D. Plumbley. 2023. AudioLDM:
Text-to-Audio Generation with Latent Diffusion Models. (1 2023).
[Link]
[16] Haohe Liu, Qiao Tian, Yi Yuan, Xubo Liu, Xinhao Mei, Qiuqiang Kong,
Yuping Wang, Wenwu Wang, Yuxuan Wang, and Mark D. Plumbley.
2023. AudioLDM 2: Learning Holistic Audio Generation with Self-
supervised Pretraining. (8 2023). [Link]
[17] Ahmed M. Abdelmoniem, Ahmed Elzanaty, Mohamed-Slim Alouini,
and Marco Canini. 2021. An Efficient Statistical-based Gradient Com-
pression Technique for Distributed Training Systems. In Proceedings
of Machine Learning and Systems, A. Smola, A. Dimakis, and I. Sto-
ica (Eds.), Vol. 3. 297–322. [Link]
paper/2021/file/[Link]
[18] Sophie J Nightingale and Hany Farid. 2022. AI-synthesized faces are
indistinguishable from real faces and more trustworthy. Proceedings
of the National Academy of Sciences of the United States of America 119
(2 2022). Issue 8. [Link]
[19] PyTorch. 2021. Introducing PyTorch Profiler - the new and improved
performance tool. [Link] Soft-
ware available from [Link]
[20] Jeff Rasley, Samyam Rajbhandari, Olatunji Ruwase, and Yuxiong
He. 2020. DeepSpeed: System Optimizations Enable Training Deep
Learning Models with Over 100 Billion Parameters. In Proceedings of
the 26th ACM SIGKDD International Conference on Knowledge Dis-
covery & Data Mining (Virtual Event, CA, USA) (KDD ’20). Asso-
ciation for Computing Machinery, New York, NY, USA, 3505–3506.
[Link]
[21] Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser,
and Björn Ommer. 2021. High-Resolution Image Synthesis with Latent
Diffusion Models. (12 2021). [Link]
[22] Nadathur Satish, Narayanan Sundaram, and Kurt Keutzer. 2009. Op-
timizing the use of GPU memory in applications with large data
sets. 16th International Conference on High Performance Computing,
HiPC 2009 - Proceedings, 408–418. [Link]
5433185
[23] Frank Seide and Amit Agarwal. 2016. CNTK: Microsoft’s Open-Source
Deep-Learning Toolkit. In Proceedings of the 22nd ACM SIGKDD In-
ternational Conference on Knowledge Discovery and Data Mining (San
183