liveBook · Manning

LayoutMap

As explained in Deep Learning with Python, Third Edition

A Keras API for assigning variable sharding or replication layouts across a device mesh.

LayoutMap tells Keras how to shard or replicate model variables across a device mesh. It maps each variable path to a tuple with one layout entry per variable dimension, letting computation follow the variable placement. section 18.2.2

Assigning a dense layer layout

Create a LayoutMap for a mesh with a named model axis, then assign layouts such as (None, "model") to a kernel and ("model",) to its bias. Here, the kernel's second dimension and the bias are split across the model axis, while None leaves the kernel's first dimension replicated. section 18.2.2

layout_map = keras.distribution.LayoutMap(device_mesh)
layout_map["sequential/dense/kernel"] = (None, "model")
layout_map["sequential/dense/bias"] = ("model",)
layout_map["sequential/dense_1/kernel"] = (None, "model")
layout_map["sequential/dense_1/bias"] = ("model",)

Use the concrete LayoutMap construction and variable-path assignments as a starting template for model parallelism. section 18.2.2

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains per-dimension layouts and shows assignments, while stopping short of broader compiler implementation details.
Examples
Uses a 32×64 variable, dense-layer kernels and biases, variable paths, and a 2×4 data/model device mesh.
What it assumes
Assumes a Keras model and device mesh, while defining variable paths and per-dimension sharding from the ground up.
What you can do after
Operate/configure Keras model parallelism by mapping variable paths to per-dimension sharding layouts.
How it connects
Connects device meshes, model parallelism, data parallelism, variable sharding, and variable replication.

Also explained in

Compare how 2 books explain LayoutMap →

Related concepts

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