LogoLogo
API ReferenceGitHubSlackService StatusLogin
v3.4.0
v3.4.0
  • Deep Lake Docs
  • List of ML Datasets
  • Quickstart
  • Dataset Visualization
  • Storage & Credentials
    • Storage Options
    • User Authentication
    • Managed Credentials
      • Enabling CORS
      • Provisioning Role-Based Access
  • API Reference
  • Enterprise Features
    • Querying Datasets
      • Sampling Datasets
    • Performant Dataloader
  • EXAMPLE CODE
  • Getting Started
    • Step 1: Hello World
    • Step 2: Creating Deep Lake Datasets
    • Step 3: Understanding Compression
    • Step 4: Accessing and Updating Data
    • Step 5: Visualizing Datasets
    • Step 6: Using Activeloop Storage
    • Step 7: Connecting Deep Lake Datasets to ML Frameworks
    • Step 8: Parallel Computing
    • Step 9: Dataset Version Control
    • Step 10: Dataset Filtering
  • Tutorials (w Colab)
    • Deep Lake Vector Store in LangChain
    • Creating Datasets
      • Creating Complex Datasets
      • Creating Object Detection Datasets
      • Creating Time-Series Datasets
      • Creating Datasets with Sequences
      • Creating Video Datasets
    • Training Models
      • Training an Image Classification Model in PyTorch
      • Training Models Using MMDetection
      • Training Models Using PyTorch Lightning
      • Training on AWS SageMaker
      • Training an Object Detection and Segmentation Model in PyTorch
    • Updating Datasets
    • Data Processing Using Parallel Computing
  • Playbooks
    • Querying, Training and Editing Datasets with Data Lineage
    • Evaluating Model Performance
    • Training Reproducibility Using Deep Lake and Weights & Biases
    • Working with Videos
  • API Summary
  • Technical Details
    • Best Practices
      • Creating Datasets at Scale
      • Training Models at Scale
      • Storage Synchronization and "with" Context
      • Restoring Corrupted Datasets
    • Data Layout
    • Version Control and Querying
    • Tensor Relationships
    • Visualizer Integration
    • Shuffling in dataloaders
    • How to Contribute
Powered by GitBook
On this page
  • How to optimize Deep Lake for training models at scale
  • Choosing the optimal dataloader
  • Setting num_workers
  • Choosing the optimal decode_method for images

Was this helpful?

  1. Technical Details
  2. Best Practices

Training Models at Scale

Train models at scale using Deep Lake

PreviousCreating Datasets at ScaleNextStorage Synchronization and "with" Context

Last updated 2 years ago

Was this helpful?

How to optimize Deep Lake for training models at scale

There are several Deep Lake related tuning parameters that affect the speed of Deep Lake OSS and Enterprise dataloaders. The plot below shows performance of the Deep Lake dataloaders under different scenarios, and it is discussed in detail below.

Choosing the optimal dataloader

The Deep Lake Enterprise dataloader streams data faster compared to the OSS dataloaer, due to its C++ implementation that optimizes asynchronous data fetching and decompression.

  • The Enterprise dataloader is ~1.5-3X faster compared to the OSS version, depending on the complexity of the transform and the number of workers available for parallelization.

  • Distributed training is only available in the Enterprise dataloader.

Setting num_workers

Both the OSS and Enterprise dataloaders in Deep Lake have a num_workers parameter that parallelizes the data fetching, decompression, and transformation.

  • Increasing num_workers will not improve performance in GPU-bottlenecked scenarios. Therefore, we recommend starting with 2-4 workers, and increasing num_workers it if the GPU utilization is low.

  • Increasing num_workers beyond the number of CPUs on a machine does not improve performance.

    • It is common for GPU machines to have 8x CPUs per GPU

  • Increasing num_workers linearly improves streaming speed, with diminishing returns beyond 8+ workers.

  • Increasing num_workers beyond 16 is generally unnecessary, unless you are running complex transformations.

Choosing the optimal decode_method for images

Faster dataloading is achieved by minimizing the amount of operations that take place before data is delivered to the GPU. It is important to the decode_method parameter in the OSS and Enterprise dataloaders based on the following guidelines:

  • When transforming images using tools the require numpy arrays as inputs, such as Albumentations, decode_method should be to numpy, which is the default (No parameters changes are needed)

  • When transforming images using tools the require PIL images as inputs, such as torchvision transforms, decode_method should be to {'image_tensor_name': 'pil'}. torchvision.transforms.ToPIL() should be removed from the top of the transforms stack.

    • Leaving the decode_method as numpy may decrease dataloading speed by up to 2X, because the image is decoded to a numpy array and then re-encoded as a PIL image, instead of being directly decoded to a PIL image.

APPENDIX TO THE PLOT ABOVE

The torchvision transforms used to create the comparison in the plot above are:

tform_simple = transforms.Compose(
    [
        transforms.Resize((128, 128)),
        transforms.RandomAffine(20),
        transforms.RandomHorizontalFlip(p=0.5),
        transforms.ToTensor(),
        transforms.Lambda(lambda x: x.repeat(int(3 / x.shape[0]), 1, 1)),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
    ]
)


tform_complex = transforms.Compose(
    [
        transforms.Resize((256, 256)),
        transforms.RandomAffine(20),
        transforms.RandomHorizontalFlip(p=0.5),
        transforms.RandomVerticalFlip(p=0.5),
        transforms.RandomPerspective(distortion_scale=0.5, p=0.5),
        transforms.ColorJitter(brightness=0.2, contrast=0.2, saturation=0.2, hue=0.2),
        transforms.ToTensor(),
        transforms.Lambda(lambda x: x.repeat(int(3 / x.shape[0]), 1, 1)),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
    ]
)

ImageNet data streaming speeds from S3 to a p3.8xlarge EC2 instance. The average image size is 0.114 MB. Details on the simple and complex transform are available in the appending at the end of this page.