defto_lodtensor(data,place):"""convert tensor to lodtensor """seq_lens=[len(seq)forseqindata]cur_len=0lod=[cur_len]forlinseq_lens:cur_len+=llod.append(cur_len)flattened_data=numpy.concatenate(data,axis=0).astype("int64")flattened_data=flattened_data.reshape([len(flattened_data),1])res=fluid.LoDTensor()res.set(flattened_data,place)res.set_lod([lod])returnresdeflodtensor_to_ndarray(lod_tensor):"""conver lodtensor to ndarray """dims=lod_tensor.get_dims()ret=np.zeros(shape=dims).astype('float32')foriinxrange(np.product(dims)):ret.ravel()[i]=lod_tensor.get_float_element(i)returnret,lod_tensor.lod()