昇腾GE TensorHolder API文档
TensorHolder【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/geProduct SupportProductSupportAtlas A3 Training Products/Atlas A3 Inference Products√Atlas A2 Training Products/Atlas A2 Inference Products√Module Importfrom ge.es import TensorHolderFunctionality DescriptionTensorHolderis tensor holder class in Eager-Style graph building, created byGraphBuilderscreate_*methods (likecreate_input(),create_const_float()etc.). This class supports operator overloading (,-,*,/), can set data type, format and shape via chained calls.TensorHolderautomatically maintains strong reference to its owningGraphBuilder, ensuring underlying C resources are not released duringTensorHolderlifetime.ConstraintsDoes not support direct instantiation:TensorHolderobjects can only be created viaGraphBuilderscreate_*methods, directly calling constructor will throwRuntimeError.Cannot call setter methods afterbuild_and_reset(): AfterGraphBuilder.build_and_reset()executes, callingset_data_type(),set_format(),set_shape()etc. setter methods will cause errors.Operations require same GraphBuilder: When performing tensor operations (add,sub,mul,div), both participatingTensorHoldermust belong to sameGraphBuilder, otherwise will throwValueError.name PropertyGets producer node name.Function Prototypeproperty def name(self) - str: ...Parameter DescriptionNo parameters.Return Value DescriptionTypeDescriptionstrReturns producer nodes name.set_data_type MethodSets tensor data type.Function Prototypedef set_data_type(self, data_type: DataType) - TensorHolder: ...Parameter DescriptionParameterInput/OutputDescriptiondata_typeInputData type, type isge.graph.types.DataTypeenum.Return Value DescriptionTypeDescriptionTensorHolderReturns currentTensorHolderobject reference, supports chained calls.Constraintsdata_typemust beDataTypeenum type, otherwise will throwTypeError.set_format MethodSets tensor data format.Function Prototypedef set_format(self, format: Format) - TensorHolder: ...Parameter DescriptionParameterInput/OutputDescriptionformatInputData format, type isge.graph.types.Formatenum.Return Value DescriptionTypeDescriptionTensorHolderReturns currentTensorHolderobject reference, supports chained calls.Constraintsformatmust beFormatenum type, otherwise will throwTypeError.set_shape MethodSets tensor shape.Function Prototypedef set_shape(self, shape: List[int]) - TensorHolder: ...Parameter DescriptionParameterInput/OutputDescriptionshapeInputShape dimension list, type is integer listList[int].Return Value DescriptionTypeDescriptionTensorHolderReturns currentTensorHolderobject reference, supports chained calls.Constraintsshapemust be integer list, and all elements must beinttype, otherwise will throwTypeError.add MethodTensor addition operation.Function Prototypedef add(self, other: Union[TensorHolder, TensorLike]) - TensorHolder: ...Parameter DescriptionParameterInput/OutputDescriptionotherInputAnother tensor, type isTensorHolderorTensorLike(scalar/array etc. convertible types).Return Value DescriptionTypeDescriptionTensorHolderReturns newTensorHolderobject representing addition operation result.ConstraintsIfotherisTensorHolder, must belong to sameGraphBuilderas current tensor.Operation library (libes_math.soor default generated library) must be loadable, otherwise will throwRuntimeError.sub MethodTensor subtraction operation.Function Prototypedef sub(self, other: Union[TensorHolder, TensorLike]) - TensorHolder: ...Parameter DescriptionParameterInput/OutputDescriptionotherInputAnother tensor, type isTensorHolderorTensorLike(scalar/array etc. convertible types).Return Value DescriptionTypeDescriptionTensorHolderReturns newTensorHolderobject representing subtraction operation result.ConstraintsIfotherisTensorHolder, must belong to sameGraphBuilderas current tensor.Operation library (libes_math.soor default generated library) must be loadable, otherwise will throwRuntimeError.mul MethodTensor multiplication operation.Function Prototypedef mul(self, other: Union[TensorHolder, TensorLike]) - TensorHolder: ...Parameter DescriptionParameterInput/OutputDescriptionotherInputAnother tensor, type isTensorHolderorTensorLike(scalar/array etc. convertible types).Return Value DescriptionTypeDescriptionTensorHolderReturns newTensorHolderobject representing multiplication operation result.ConstraintsIfotherisTensorHolder, must belong to sameGraphBuilderas current tensor.Operation library (libes_math.soor default generated library) must be loadable, otherwise will throwRuntimeError.div MethodTensor division operation.Function Prototypedef div(self, other: Union[TensorHolder, TensorLike]) - TensorHolder: ...Parameter DescriptionParameterInput/OutputDescriptionotherInputAnother tensor, type isTensorHolderorTensorLike(scalar/array etc. convertible types).Return Value DescriptionTypeDescriptionTensorHolderReturns newTensorHolderobject representing division operation result.ConstraintsIfotherisTensorHolder, must belong to sameGraphBuilderas current tensor.Operation library (libes_math.soor default generated library) must be loadable, otherwise will throwRuntimeError.Operator OverloadingTensorHoldersupports the following Python operator overloading with corresponding relationships:OperatorCorresponding MethodDescriptiona ba.add(b)Tensor additiona - ba.sub(b)Tensor subtractiona * ba.mul(b)Tensor multiplicationa / ba.div(b)Tensor divisionAlso supports right operand operations (__radd__,__rsub__,__rmul__,__rtruediv__), for handling operations with non-TensorHoldertype on left side.get_owner_builder MethodGets owningGraphBuilder.Function Prototypedef get_owner_builder(self) - GraphBuilder: ...Parameter DescriptionNo parameters.Return Value DescriptionTypeDescriptionGraphBuilderReturnsGraphBuilderobject that created thisTensorHolder.【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考