Skip to content

Instantly share code, notes, and snippets.

@ailzhang
Created March 4, 2022 11:56
Show Gist options
  • Save ailzhang/a24aee39213667291c7f9601cb6253cb to your computer and use it in GitHub Desktop.
Save ailzhang/a24aee39213667291c7f9601cb6253cb to your computer and use it in GitHub Desktop.
import paddle
Python 3.8.11 (default, Aug 3 2021, 15:09:35)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.26.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import paddle
In [2]: import numpy as np
In [4]: x = paddle.to_tensor(2 * np.ones((4, ), dtype=np.flo
...: at32))
In [5]: x.value().get_tensor()
Out[5]: <paddle.fluid.core_avx.LoDTensor at 0x7fa90bb30e70>
In [6]: x.value().get_tensor()._ptr()
------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-6-b2334bf130aa> in <module>
----> 1 x.value().get_tensor()._ptr()
AttributeError: 'paddle.fluid.core_avx.LoDTensor' object has no attribute '_ptr'
In [7]: dir(x.value().get_tensor())
Out[7]:
['__array__',
'__class__',
'__delattr__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__', [25/8858]
'__getattribute__',
'__getitem__',
'__getstate__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__le__',
'__lt__',
'__module__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__setstate__',
'__sizeof__',
'__str__',
'__subclasshook__',
'_alloc_double',
'_alloc_float',
'_alloc_int',
'_clear',
'_copy',
'_copy_from',
'_dtype',
'_get_dims',
'_get_double_element',
'_get_float_element',
'_is_initialized',
'_layout',
'_mutable_data',
'_place',
'_set_dims',
'_set_double_element',
'_set_float_element',
'_set_layout',
'_share_data_with',
'_to_dlpack',
'has_valid_recursive_sequence_lengths',
'lod',
'recursive_sequence_lengths',
'set',
'set_lod',
'set_recursive_sequence_lengths',
'shape']
In [8]: paddle.__version__
Out[8]: '2.2.2'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment