MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / __init__

Method __init__

python/paddle/base/framework.py:1774–1890  ·  view source on GitHub ↗
(
        self,
        block,
        type=core.VarDesc.VarType.DENSE_TENSOR,
        name=None,
        shape=None,
        dtype=None,
        lod_level=None,
        capacity=None,
        persistable=None,
        error_clip=None,
        stop_gradient=False,
        is_data=False,
        need_check_feed=False,
        belong_to_optimizer=False,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

1772 """
1773
1774 def __init__(
1775 self,
1776 block,
1777 type=core.VarDesc.VarType.DENSE_TENSOR,
1778 name=None,
1779 shape=None,
1780 dtype=None,
1781 lod_level=None,
1782 capacity=None,
1783 persistable=None,
1784 error_clip=None,
1785 stop_gradient=False,
1786 is_data=False,
1787 need_check_feed=False,
1788 belong_to_optimizer=False,
1789 **kwargs,
1790 ):
1791 self.block = block
1792 if name is None:
1793 name = self.block.program._name_generator("_generated_var")
1794
1795 while self.block._find_var_recursive(name) is not None:
1796 name = self.block.program._name_generator("_generated_var")
1797
1798 if dtype is not None:
1799 dtype = convert_to_proto_type(dtype)
1800
1801 if dtype == core.VarDesc.VarType.STRINGS:
1802 type = core.VarDesc.VarType.STRINGS
1803 lod_level = None
1804
1805 if type == core.VarDesc.VarType.SPARSE_COO:
1806 lod_level = None
1807
1808 self.belong_to_optimizer = belong_to_optimizer
1809
1810 self.error_clip = error_clip
1811
1812 is_new_var = False
1813 self.desc = self.block.desc.find_var(name.encode())
1814
1815 if self.desc is None:
1816 self.desc = self.block.desc.var(name.encode())
1817 is_new_var = True
1818
1819 if is_new_var:
1820 self.desc.set_type(type)
1821 elif self.desc.type() != type:
1822 raise ValueError(
1823 f"Variable '{self.name}' has been created before. The "
1824 f"previous type is {self.desc.type()}, the new type is {type}. They"
1825 " are not matched"
1826 )
1827
1828 if shape is not None:
1829 if is_new_var:
1830 self.desc.set_shape(shape)
1831 else:

Callers

nothing calls this directly

Calls 9

convert_to_proto_typeFunction · 0.85
ValueErrorClass · 0.85
_find_var_recursiveMethod · 0.80
encodeMethod · 0.80
varMethod · 0.45
set_typeMethod · 0.45
typeMethod · 0.45
set_shapeMethod · 0.45
set_dtypeMethod · 0.45

Tested by

no test coverage detected