当前位置: 首页 > news >正文

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),仅供参考

http://www.cnnetsun.cn/news/3130823.html

相关文章:

  • 从deprecated到新方案:Grafonnet-lib迁移指南与最佳实践
  • Touch WX与Touch UI:两个框架的区别与联系详解
  • Leela Chess Zero vs 传统象棋引擎:为什么神经网络是未来的趋势
  • CANN/ops-nn分组量化SwiGLU激活算子
  • Statsig Status Page最佳实践:企业级状态监控配置
  • 终极指南:如何使用Gradle Docker插件实现与Kubernetes的无缝集成
  • SENet-Tensorflow实战教程:在CIFAR-10数据集上训练ResNeXt模型
  • CTF-NetA 2.9.3:自动化网络流量分析利器,一键解密USB与Webshell流量
  • CANN/asc-devkit GlobalTensor GetValue API
  • IGBT结温估算技术:原理、优化与实践
  • Packtpub-crawler通知系统详解:邮件、IFTTT、Pushover多平台提醒设置指南
  • 提高代码质量系列之三:我是怎么设计函数的?
  • Typical架构解析:从Schema到代码生成的完整工作流
  • nwpu-cram之量子通信:原理与协议终极指南
  • CANN白盒设计网络搜索
  • CANN/asc-devkit GlobalTensor GetSize函数
  • autopprof实战教程:10个技巧快速定位Go性能瓶颈
  • CANN / cannbot-skills:分册5性能评估与精度对比
  • jinjava与HubSpot CMS集成:大规模应用的实际案例分析
  • ContEx高级技巧:自定义CSS样式和图表主题定制指南
  • 3分钟掌握gInk:Windows上最高效的免费屏幕标注工具完全指南
  • 解密Vue3DraggableResizable实现原理:拖拽与缩放的底层逻辑
  • PCB金手指故障预判与延寿技术解析
  • kube-prod-runtime核心组件解析:日志、监控与Ingress三大支柱
  • Juggl工作空间模式深度解析:如何高效管理你的知识网络
  • Frozen API深度解析:json_scanf和json_printf的10个实用技巧
  • 如何通过GTA5线上小助手实现游戏参数深度定制:完整技术指南
  • BlueHound:终极网络安全防御工具 - 如何快速发现攻击路径并保护企业网络
  • 自动驾驶笔记:端到端自动驾驶系统的架构设计与实现指南
  • 如何快速上手Windmill React UI?新手必备的完整指南