news 2026/7/4 7:10:45

CANN/GE Python张量API

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
CANN/GE Python张量API

Tensor

【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge

Product Support

ProductSupport
Atlas A3 Training Products/Atlas A3 Inference Products
Atlas A2 Training Products/Atlas A2 Inference Products

Module Import

from ge.graph import Tensor

Functionality Description

Tensor class is tensor data class, supports creating tensors via memory data or files. Supports setting and getting tensor's Format, DataType, Shape, Data (TensorLike) and Placement. Tensors support migration between Host and Device.

Function Prototype

Constructor

Tensor(data=None, file_path=None, data_type=DataType.DT_FLOAT, format=Format.FORMAT_ND, shape=None, placement=Placement.PLACEMENT_HOST)

Properties

@property format -> Format
@property data_type -> DataType
@property shape -> Shape
@property data -> TensorLike
@property placement -> Placement

Methods

set_format(format: Format) -> Tensor
get_format() -> Format
set_data_type(data_type: DataType) -> Tensor
get_data_type() -> DataType
get_shape() -> Shape
get_data() -> TensorLike
get_tensor_desc() -> TensorDesc
get_placement() -> Placement
to_host() -> Tensor
to_device() -> Tensor

Parameter Description

Constructor Parameters

ParameterTypeRequiredDescription
dataUnion[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_typeDataTypeNoTensor's data type, use DataType enum value, default is DataType.DT_FLOAT.
formatFormatNoTensor's data format, use Format enum value, default is Format.FORMAT_ND.
shapeUnion[List[int], None]NoTensor's shape, represented as integer list for each dimension size. If None, indicates scalar.
placementPlacementNoTensor's placement location, use Placement enum value, default is Placement.PLACEMENT_HOST.

set_format Parameters

ParameterTypeRequiredDescription
formatFormatYesTarget data format, use Format enum value.

set_data_type Parameters

ParameterTypeRequiredDescription
data_typeDataTypeYesTarget data type, use DataType enum value.

Return Value Description

Constructor

Returns Tensor object instance.

Property Return Values

PropertyReturn TypeDescription
formatFormatTensor's data format.
data_typeDataTypeTensor's data type.
shapeShapeTensor's shape information.
dataTensorLikeTensor's data content. Scalar returns single value, non-scalar returns nested list structure.
placementPlacementTensor's placement location.

Method Return Values

MethodReturn TypeDescription
set_formatTensorReturns self, supports chained calls.
get_formatFormatReturns tensor's data format.
set_data_typeTensorReturns self, supports chained calls.
get_data_typeDataTypeReturns tensor's data type.
get_shapeShapeReturns tensor's shape information.
get_dataTensorLikeReturns tensor's data content. Scalar returns single value, non-scalar returns nested list structure.
get_tensor_descTensorDescReturns tensor's description info (TensorDesc object).
get_placementPlacementReturns tensor's placement location.
to_hostTensorReturns self, migrates tensor from Device to Host.
to_deviceTensorReturns self, migrates tensor from Host to Device.

Constraints

  • When 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.

【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/4 7:07:07

从deprecated到新方案:Grafonnet-lib迁移指南与最佳实践

从deprecated到新方案:Grafonnet-lib迁移指南与最佳实践 【免费下载链接】grafonnet-lib Jsonnet library for generating Grafana dashboard files. 项目地址: https://gitcode.com/gh_mirrors/gr/grafonnet-lib Grafonnet-lib是用于以代码方式编写Grafana仪…

作者头像 李华
网站建设 2026/7/4 7:05:22

Touch WX与Touch UI:两个框架的区别与联系详解

Touch WX与Touch UI:两个框架的区别与联系详解 【免费下载链接】touchwx 小程序组件化解决方案。官网:https://www.wetouch.net/wx.html 项目地址: https://gitcode.com/gh_mirrors/to/touchwx Touch WX和Touch UI是一对强大的移动端开发框架组合…

作者头像 李华
网站建设 2026/7/4 7:03:24

Leela Chess Zero vs 传统象棋引擎:为什么神经网络是未来的趋势

Leela Chess Zero vs 传统象棋引擎:为什么神经网络是未来的趋势 【免费下载链接】leela-chess **MOVED TO https://github.com/LeelaChessZero/leela-chess ** A chess adaption of GCPs Leela Zero 项目地址: https://gitcode.com/gh_mirrors/le/leela-chess …

作者头像 李华
网站建设 2026/7/4 7:02:09

CANN/ops-nn分组量化SwiGLU激活算子

SwigluGroupQuant 【免费下载链接】ops-nn 本项目是CANN提供的神经网络类计算算子库,实现网络在NPU上加速计算。 项目地址: https://gitcode.com/cann/ops-nn 产品支持情况 产品是否支持Ascend 950PR/Ascend 950DT√Atlas A3 训练系列产品/Atlas A3 推理系列…

作者头像 李华
网站建设 2026/7/4 7:02:05

Statsig Status Page最佳实践:企业级状态监控配置

Statsig Status Page最佳实践:企业级状态监控配置 【免费下载链接】statuspage A simple, zero-dependency, pure js/html status page based on GitHub Pages and Actions. 项目地址: https://gitcode.com/gh_mirrors/sta/statuspage Statsig Status Page是…

作者头像 李华
网站建设 2026/7/4 7:01:50

终极指南:如何使用Gradle Docker插件实现与Kubernetes的无缝集成

终极指南:如何使用Gradle Docker插件实现与Kubernetes的无缝集成 【免费下载链接】gradle-docker a Gradle plugin for orchestrating docker builds and pushes. 项目地址: https://gitcode.com/gh_mirrors/gr/gradle-docker Gradle Docker插件是一个强大的…

作者头像 李华