diff --git a/python/paddle/fluid/framework.py b/python/paddle/fluid/framework.py index e365a584e085456b114dac0e361386fe4bf303b3..907ac3209c131d8ce5bfbd926d83189e9f0a077b 100644 --- a/python/paddle/fluid/framework.py +++ b/python/paddle/fluid/framework.py @@ -1090,6 +1090,7 @@ class Variable(object): import paddle.fluid as fluid import numpy as np + # example1: return ndarray x = np.ones([2, 2], np.float32) with fluid.dygraph.guard(): inputs2 = [] @@ -1104,6 +1105,19 @@ class Variable(object): loss2.backward(backward_strategy) print(loss2.gradient()) + # example2: return tuple of ndarray + with fluid.dygraph.guard(): + embedding = fluid.dygraph.Embedding( + size=[20, 32], + param_attr='emb.w', + is_sparse=True) + x_data = np.arange(12).reshape(4, 3).astype('int64') + x_data = x_data.reshape((-1, 3, 1)) + x = fluid.dygraph.base.to_variable(x_data) + out = embedding(x) + out.backward() + print(embedding.weight.gradient()) + """ pass