liveBook · Manning

Dataset split

As explained in Deep Learning with R, Third Edition

Sharding is the partitioning of a variable or data object into distinct chunks assigned to different devices.

Sharding splits a variable or data object into distinct chunks. In multi-device training, each device receives a different chunk instead of a full copy. This matters when a model is too large to fit on one device. section 18.2.2 section 18.2.1

Split a variable across four devices

Suppose a variable has shape (32, 64). Split its last dimension into four chunks of shape (32, 16), and assign one chunk to each device along a device mesh’s "model" axis. The first dimension remains replicated. A LayoutMap expresses this choice with tuple(NULL, "model") for a Dense layer’s kernel; its bias uses tuple("model"). Set the ModelParallel distribution configuration before creating and fitting the model. section 18.2.2

layout_map <- keras$distribution$LayoutMap(device_mesh)
layout_map["sequential/dense/kernel"]   <- tuple(NULL, "model")
layout_map["sequential/dense/bias"]     <- tuple("model")
layout_map["sequential/dense_1/kernel"] <- tuple(NULL, "model")
layout_map["sequential/dense_1/bias"]   <- tuple("model")

These LayoutMap entries show how kernel and bias variable paths receive different layouts: the kernel’s last dimension and the bias’s only dimension follow the "model" mesh axis. section 18.2.2

A split can apply at different levels:

  • Data parallelism divides a batch into sub-batches for parallel processing. Model parallelism instead divides one model among devices when a full copy will not fit. section 18.2.1
  • Horizontal model partitioning assigns different layers to different devices. Passing a large layer output between devices can create a communication bottleneck. section 18.2.1
  • Vertical model partitioning divides a layer’s variables across devices, computes each device’s part, and merges the outputs. It is the suggested fit for large models here. section 18.2.1

A file shard is a different, storage-level use of the term: a text dataset may arrive as separate files. For example, a pretraining dataset has 50 text shards of about 75 MB each. File shards do not, by themselves, specify how model variables are placed on devices. section 16.2 section 18.2.2

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains per-dimension replication and sharding, then configures variable layouts; stops short of implementing a distribution system.
Examples
Uses a four-way split of a (32, 64) variable, Dense-layer layouts, and 50 text-data file shards.
What it assumes
Assumes basic models and devices while explaining variable paths as identifiers for model variables.
What you can do after
Operate/configure it with Keras DeviceMesh, LayoutMap, and ModelParallel to assign model-variable chunks to devices.
How it connects
Connects sharding to data parallelism, model parallelism, device meshes, and variable replication.

Also explained in

Compare how 21 books explain dataset split →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.