A 1.3TB Model That Wouldn't Fit
I recently came across a post by Zack Omollo, where he attempted to fit a 1.3 terabyte (TB) model into a gigabyte (GB) of storage space. The results were predictable, but still surprising: the measurements showed that the model exceeded the storage capacity by a staggering 1.3 million times.
To put this in perspective, a 1.3 TB model is roughly equivalent to 1.3 million times the size of the average smartphone's storage capacity. For those who are not familiar, a gigabyte is equivalent to 1 billion bytes, or 1,073,741,824 bytes to be precise.
Zack's experiment was simple: he took a pre-trained model and tried to compress it to fit within a gigabyte of storage space. The model in question was a 1.3 TB transformer model with 512 embedding dimensions and 8 attention heads, which is commonly used in natural language processing tasks.
The results were not encouraging. Even after applying various compression techniques, the model still exceeded the storage capacity by a significant margin. In fact, the measurements indicated that the model would require 1.3 million times more storage space than initially thought, which is equivalent to 1.3 TB of storage.
This experiment highlights the need for more efficient model design in the context of large-scale language models, which are becoming increasingly common in industries such as healthcare and finance. As someone who works with large-scale language models, I've seen firsthand the challenges of storing and processing them.
pythonimport torch import torch.nn as nn # Define a simple transformer model class TransformerModel(nn.Module): def __init__(self): super(TransformerModel, self).__init__() self.encoder = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, dropout=0.1) self.decoder = nn.TransformerDecoderLayer(d_model=512, nhead=8, dim_feedforward=2048, dropout=0.1) def forward(self, input): return self.encoder(input) # Create a 1.3 TB model model = TransformerModel() model.weight.data.normal_(0, 0.01) model.bias.data.zero_() # Calculate the model's storage requirements storage_requirements = model.weight.data.nbytes + model.bias.data.nbytes print(f"Storage requirements: {storage_requirements / (1024 * 1024 * 1024):.2f} GB")
Model Storage RequirementsData from the sources listed below.
Try this
- Try compressing a pre-trained model using the
torch.nn.utils.prunemodule. - Estimate the storage requirements for a large model using the
torch.nn.utils.checkpointmodule. - Compare the performance of a compressed model to the original model on a specific task.
