CANN/GE Python张量API
Tensor【免费下载链接】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.graph import TensorFunctionality DescriptionTensor class is tensor data class, supports creating tensors via memory data or files. Supports setting and getting tensors Format, DataType, Shape, Data (TensorLike) and Placement. Tensors support migration between Host and Device.Function PrototypeConstructorTensor(dataNone, file_pathNone, data_typeDataType.DT_FLOAT, formatFormat.FORMAT_ND, shapeNone, placementPlacement.PLACEMENT_HOST)Propertiesproperty format - Formatproperty data_type - DataTypeproperty shape - Shapeproperty data - TensorLikeproperty placement - PlacementMethodsset_format(format: Format) - Tensorget_format() - Formatset_data_type(data_type: DataType) - Tensorget_data_type() - DataTypeget_shape() - Shapeget_data() - TensorLikeget_tensor_desc() - TensorDescget_placement() - Placementto_host() - Tensorto_device() - TensorParameter DescriptionConstructor ParametersParameterTypeRequiredDescriptiondataUnion[List[int], List[float], List[bool], None]NoMemory data, pass tensor data via list. Choose one between data and file_path, cannot specify both.file_pathUnion[str, None]NoFile path, read tensor data from file. Choose one between file_path and data, cannot specify both.data_typeDataTypeNoTensors data type, use DataType enum value, default is DataType.DT_FLOAT.formatFormatNoTensors data format, use Format enum value, default is Format.FORMAT_ND.shapeUnion[List[int], None]NoTensors shape, represented as integer list for each dimension size. If None, indicates scalar.placementPlacementNoTensors placement location, use Placement enum value, default is Placement.PLACEMENT_HOST.set_format ParametersParameterTypeRequiredDescriptionformatFormatYesTarget data format, use Format enum value.set_data_type ParametersParameterTypeRequiredDescriptiondata_typeDataTypeYesTarget data type, use DataType enum value.Return Value DescriptionConstructorReturns Tensor object instance.Property Return ValuesPropertyReturn TypeDescriptionformatFormatTensors data format.data_typeDataTypeTensors data type.shapeShapeTensors shape information.dataTensorLikeTensors data content. Scalar returns single value, non-scalar returns nested list structure.placementPlacementTensors placement location.Method Return ValuesMethodReturn TypeDescriptionset_formatTensorReturns self, supports chained calls.get_formatFormatReturns tensors data format.set_data_typeTensorReturns self, supports chained calls.get_data_typeDataTypeReturns tensors data type.get_shapeShapeReturns tensors shape information.get_dataTensorLikeReturns tensors data content. Scalar returns single value, non-scalar returns nested list structure.get_tensor_descTensorDescReturns tensors description info (TensorDesc object).get_placementPlacementReturns tensors placement location.to_hostTensorReturns self, migrates tensor from Device to Host.to_deviceTensorReturns self, migrates tensor from Host to Device.ConstraintsWhen constructing tensor, only one of data and file_path can be specified, cannot specify both, and cannot specify neither (when neither specified creates empty tensor).Supported data types include: DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT32, DT_UINT8, DT_INT16, DT_UINT16, DT_UINT32, DT_INT64, DT_UINT64, DT_BOOL. Does not support DT_DOUBLE.shape parameter must be integer list (list of int), if None indicates scalar.placement parameter must be Placement enum value.Tensor does not support copy and deepcopy.to_host() only applies to tensors currently on Device; to_device() only applies to tensors currently on Host.【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考