embeddingLookupGPU function
GPUTensor<Matrix>
embeddingLookupGPU(
- GPUTensor<
Vector> indices, - GPUTensor<
Matrix> weights, - CommandBuffer tape
Implementation
GPUTensor<Matrix> embeddingLookupGPU(GPUTensor<Vector> indices, GPUTensor<Matrix> weights, CommandBuffer tape) {
int numIndices = indices.shape[0];
int embeddingDim = weights.shape[1];
GPUTensor<Matrix> out = GPUTensor<Matrix>.empty([numIndices, embeddingDim]);
tape.putInt(OP_EMBEDDING_FORWARD);
tape.putString(indices.id);
tape.putString(weights.id);
tape.putString(out.id);
out.creator = GPUNode(
[weights],
(CommandBuffer bTape) {
bTape.putInt(OP_EMBEDDING_BACKWARD);
bTape.putString('${out.id}_grad');
bTape.putString(indices.id);
bTape.putString('${weights.id}_grad');
},
opName: 'embedding_lookup_gpu',
cost: numIndices * embeddingDim,
);
return out;
}