@@ -103,6 +103,53 @@ One method to achieve model parallelism is called *pipelining*, where the
103103model layers are assigned to *pipeline stages *. Each pipeline stage can be
104104assigned to a different device and different devices can execute in parallel.
105105
106+ By default, these pipeline stages will be executed using the grouped schedule
107+ (:numref: `fig-grouped-pipeline `), where the forward and backward stages are grouped
108+ together on each IPU. All IPUs alternate between executing a forward pass and then a
109+ backward pass.
110+
111+ .. figure :: figures/grouped_pipeline.png
112+ :width: 95%
113+ :alt: Grouped pipeline schedule illustration
114+ :align: center
115+ :name: fig-grouped-pipeline
116+
117+ Grouped schedule
118+
119+ Two other schedules are available and can be configured as shown in
120+ :numref: `pipelining-options `. When using the interleaved schedule
121+ (:numref: `fig-interleaved-pipeline `) the forward and backward passes are
122+ interleaved (which requires less memory but is likely to be slower). The
123+ sequential schedule (:numref: `fig-sequential-pipeline `) executes one stage at a
124+ time and may be useful when debugging your model.
125+
126+ .. figure :: figures/interleaved_pipeline.png
127+ :width: 95%
128+ :alt: Interleaved pipeline schedule illustration
129+ :align: center
130+ :name: fig-interleaved-pipeline
131+
132+ Interleaved schedule
133+
134+ .. figure :: figures/sequential_pipeline.png
135+ :width: 95%
136+ :alt: Sequential pipeline schedule illustration
137+ :align: center
138+ :name: fig-sequential-pipeline
139+
140+ Sequential schedule
141+
142+ .. note ::
143+
144+ In :numref: `fig-grouped-pipeline `, :numref: `fig-interleaved-pipeline `
145+ and :numref: `fig-sequential-pipeline `, `T ` refers to the number of gradient accumulation
146+ steps per replica. See :numref: `pipelining-options ` for how to
147+ specify this value.
148+
149+
150+ A detailed explanation of pipelining can be found in the technical note on `Model parallelism with
151+ TensorFlow: sharding and pipelining <https://docs.graphcore.ai/projects/tf-model-parallelism/en/latest/pipelining.html> `_.
152+
106153The method to pipeline your model depends on whether your model is a
107154``Sequential `` model, a ``Functional `` model, or is subclassed from the ``Model ``
108155class.
@@ -196,6 +243,8 @@ everything else to the second stage, as follows:
196243 :py:class: `~tensorflow.python.ipu.keras.extensions.ModelExtension `
197244 equivalents.
198245
246+ .. _model-subclass :
247+
199248Model subclass
200249______________
201250
@@ -278,6 +327,37 @@ to four different pipeline stages as follows:
278327 equivalents.
279328
280329
330+ .. _pipelining-options :
331+
332+ Pipelining options
333+ __________________
334+
335+ Pipelining options can be set with
336+ :py:meth: `~tensorflow.python.ipu.keras.extensions.SequentialExtension.set_pipelining_options ` for a Sequential model,
337+ :py:meth: `~tensorflow.python.ipu.keras.extensions.FunctionalExtension.set_pipelining_options ` for a Functional model, and
338+ :py:meth: `~tensorflow.python.ipu.keras.extensions.ModelExtension.set_pipelining_options ` for models which subclass `tf.keras.model `.
339+
340+ Gradient accumulation is always used when training a pipelined model (unless using the ``Sequential `` schedule). This means
341+ that you must set the option ``gradient_accumulation_steps_per_replica `` using this API when using the ``Grouped `` or
342+ ``Interleaved `` schedule. It is optional when using the ``Sequential `` schedule.
343+
344+
345+ The API documentation for :py:meth: `~tensorflow.python.ipu.keras.extensions.SequentialExtension.set_pipelining_options ` (Sequential model),
346+ :py:meth: `~tensorflow.python.ipu.keras.extensions.FunctionalExtension.set_pipelining_options ` (Functional model)
347+ and :py:meth: `~tensorflow.python.ipu.keras.extensions.ModelExtension.set_pipelining_options ` (Model subclass) explains that the
348+ additional keyword arguments (``pipelining_kwargs ``)
349+ will be forwarded to the :py:func: `tensorflow.python.ipu.pipelining_ops.pipeline ` operator (which is used internally -
350+ see :numref: `implementation-details `). Refer to the API documentation for :py:func: `~tensorflow.python.ipu.pipelining_ops.pipeline `
351+ for details about these arguments.
352+
353+ The code sample below illustrates how options can be set with the `set_pipelining_options ` API.
354+
355+ .. literalinclude :: keras_tf2_example7.py
356+ :language: python
357+ :linenos:
358+ :start-at: model.set_pipelining_options(
359+ :end-at: pipeline_schedule=ipu.ops.pipelining_ops.PipelineSchedule.Interleaved)
360+
281361.. _automatic-data-parallelism :
282362
283363Automatic data parallelism
@@ -358,6 +438,8 @@ order to save/load IPU-specific information.
358438 again.
359439
360440
441+ .. _implementation-details :
442+
361443Implementation details
362444~~~~~~~~~~~~~~~~~~~~~~
363445
0 commit comments