Building ML Models for Large Datasets
Big Data Analytics with Python, AIMS 2023
Dunstan Matekenya, PhD
Contents
Machine Learning Pipeline
Data processing/preprocessing
Model building
Model serving/inference
Feature engineering
Hyparameter tuning
Model evaluation
“ML model building, evaluation and inference with large datasets is a much bigger problem than any other task in data science when large datasets are involved”
Group (pairs) Activity (10 minutes)
How Data can be Big for ML
Both large number of features (p) and number of observations (n) can present problems in ML
| | | |
| | | |
| | | |
| | | |
features (p)
features (n)
How Data can be Big for ML cont’d
Audio Data
Just 2 hours of speech data for Kinyarwanda ~ 57GB. How do you train a model on all that data?
What are the main challenges of big data in ML?
Strategies for Dealing with Big Data in ML
Data reduction
Speed up processing
Exploit parallelization/distributed processing
Exploit specialized hardware
Model reduction
Data Reduction to Deal with Big Data in ML
Downsample
Feature Engineering and/or feature selection
Often the first thing you wanna try before you invest in expensive and/or sophisticated resources/approaches
Dimensionality Reduction, lower dimension embedding
The obvious disadvantage to these approaches is that they lead to loss of data which can lead to overfitting and poor model performance.
Speeding up Model Training with Faster Algorithms
In Deep Learning Models, ‘batch_size’ is one of the key hyperparameters
In addition to affecting how fast your training will go (or not go at all), batch_size also affect model performance
Speeding Up Model Training with Better Data Structures
Speeding up Model Training Specialized Hardware: CPU vs. GPU
Group (pairs) Activity: Explore performance benchmarks between GPU vs. CPU
Distributed ML model training
In distributed training the workload to train a model is split up and shared among worker nodes. There are several design decisions to be tackled
Data vs. Model Parallelism
Data Parallelism
Model Parallelism
In both data and model parallelism, communication across nodes during training can be centralized or decentralized. Secondly, parameter update strategy can be synchronous or asynchronous
You can also have a combination of both implemented
Data Parallelism: View with Multiple Workers
Data Parallelism View with Linear Regression Computation
Model Parallelism View with Linear Regression Computation
Model and Data Parallelism View with Linear Regression Computation
More on Model Parallelism
Decentralized vs. Centralized Communication in Distributed Training
Decentralized vs. Centralized Training
Centralized training with a parameter server
Decentralized training
Synchronous and Asynchronous Parameter Updates
Synchronous Parameter Updates in a Data Parallelism Setup
Compute gradients on worker nodes, once finished, average them and then update model params
Synchronous Parameter Updates in a Data Parallelism Setup
The process of combing (adding gradients) before averaging (during averaging phase) is a non-trivial reduce operation, like the one we looked at in the map, reduce computation strategies with distributed processing.
Synchronous Parameter Updates Cont’d
Asynchronous vs. Synchronous Parameter Updates Cont’d
Asynchronous Parameter Updates in a Data Parallelism Setup
What about model inference? Any challenges with large datasets/models?
Data processing/preprocessing
Model building
Model serving/inference
Feature engineering
Hyperparameter tuning
Model evaluation
When models can reach 800GB in size, we need solutions for model inference too
This mostly an issue for deep learning/NN models and where you are doing inference matters
Model compression techniques
• Quantization (low-precision inference)
• Pruning
• Knowledge distillation
• Efficient architectures (+ architecture search)
Main solution for this is Model compression whose goal is to find a smaller, cheaper model with the same (or similar) accuracy
Model Compression: Quantization (Low precision training/inference)
Model Compression: Quantization (Low precision training/inference)
Again, for the mathematically inclined, this is another good area of research: if you can find low precision training/inference and still maintain good accuracy, you are the king
In deep learning software such as Pytorch, this often termed mixed precision training. It's one of the parameters you have to deal with when training with GPUs and/or CPUs. See this blog post and this one
Other Model Compression Techniques
Here is a paper on knowledge distillation which I find amusing
Contents
Tooling/resources for big data in ML
Tooling/resources for big data in ML cont’d
Overview of ML in Spark
Introducing Spark MLlib
You can use DataFrame API or RDD
Available Functions and Utilities in Spark MLlib
Main Components of Spark MLlib API
Further Resources