Package ai.djl.translate
Interface Batchifier
-
- All Superinterfaces:
java.io.Serializable
- All Known Implementing Classes:
PaddingStackBatchifier,SimplePaddingStackBatchifier,StackBatchifier
public interface Batchifier extends java.io.SerializableAn interface for different strategies to convert betweenRecordNDLists andBatchNDList.Different implementations of
Batchifierrepresent different ways of creating batches. The most common would be theStackBatchifierthat batchifies by creating a new batch axis as axis 0. Another implementation could be a concatenated batchifier for sequence elements that will concatenate the data elements along the time axis.
-
-
Field Summary
Fields Modifier and Type Field Description static BatchifierSTACK
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description NDListbatchify(NDList[] inputs)static BatchifierfromString(java.lang.String name)Returns a batchifier from a batchifier name.default NDList[]split(NDList list, int numOfSlices, boolean evenSplit)NDList[]unbatchify(NDList inputs)
-
-
-
Field Detail
-
STACK
static final Batchifier STACK
-
-
Method Detail
-
fromString
static Batchifier fromString(java.lang.String name)
Returns a batchifier from a batchifier name.- Parameters:
name- the batchifier name- Returns:
- the batchifier with the given name
- Throws:
java.lang.IllegalArgumentException- if an invalid name is given
-
unbatchify
NDList[] unbatchify(NDList inputs)
Splits a combinedBatchNDListinto it's constituentRecordNDLists.This reverses the
batchifyoperation.- Parameters:
inputs- theNDListthat needs to be 'unbatchified'- Returns:
- an array of NDLists, of size equal to batch size, where each NDList is one element from the batch of inputs
-
split
default NDList[] split(NDList list, int numOfSlices, boolean evenSplit)
Partitions the givenBatchNDListinto multipleBatchlists with smaller batch size.As an example, this function might be used for multi-GPU training where it takes the main batch and splits it into sub-batches that can be run on each GPU.
This function unbatchifies the input
NDList, redistributes them into the given number of slices, and then batchify each of the slices to form an array ofNDList.
-
-