DataFlow API List

DataFlow graphs can be constructed using DataFlow Python APIs for inference. Graph ProcessPoints and UDF ProcessPoints can be defined to describe the data flow relationship between ProcessPoints. IR files of TensorFlow, ONNX, and MindSpore can be imported to define the computation logic of graph ProcessPoints.

DataFlow Graph Construction APIs

Table 1 DataFlow graph construction APIs

API

Description

dataflow.FlowData

Indicates data nodes in a DataFlow graph. Each FlowData corresponds to an input.

FlowNode

Indicates compute nodes in a DataFlow graph.

add_process_point

Adds a mapping ProcessPoint (PP) to a FlowNode. Currently, only one PP can be added to a FlowNode. After a PP is added, the input and output of the FlowNode are mapped to those of the PP in sequence by default.

map_input

Maps inputs to FlowNode, indicating that the node_input_index input of FlowNode is sent to the pp_input_index input of ProcessPoint, all attributes in attr are set for the input of ProcessPoint, and the mapped FlowNode is returned. This function is optional. If it is not called, the inputs of FlowNode and ProcessPoint are mapped in sequence by default.

map_output

Maps outputs to FlowNode, indicating that the pp_output_index output of pp is sent to the node_output_index output of FlowNode and then the mapped FlowNode is returned.

set_attr

Sets the attributes of FlowNode.

__call__

Calls FlowNode for computation.

set_balance_scatter

Sets the balance scatter attribute. The UDF with the balance scatter attribute can use balance options to set the load balancing output.

set_balance_gather

Sets the balance gather attribute. The UDF with the balance gather attribute can use balance options to set the load balancing and affinity output.

set_alias

Sets the node alias. When option:ge.experiment.data_flow_deploy_info_path is used to specify the node deployment location, the flow_node_list field can be specified using the alias.

dataflow.FlowFlag

Sets flags in the FlowMsg message header.

FlowGraph

Defines a DataFlow graph, which consists of the input node FlowData and compute node FlowNode.

set_contains_n_mapping_node

Sets whether FlowGraph contains an n_mapping node.

set_inputs_align_attrs

Sets the attribute of input alignment in FlowGraph.

set_exception_catch

Enables or disables the user exception catch function.

dataflow.FlowOutput

Describes the output of FlowNode.

dataflow.Framework

Sets the framework of the original network model.

FuncProcessPoint

Defines the FuncProcessPoint constructor, which returns a FuncProcessPoint object.

set_init_param

Sets the initialization parameters of FuncProcessPoint.

add_invoked_closure

Adds GraphProcessPoint or FlowGraphProcessPoint to be called by FuncProcessPoint, and returns FuncProcessPoint.

GraphProcessPoint

Defines the GraphProcessPoint constructor, which returns a GraphProcessPoint object.

fnode

Generates a FlowNode based on the current GraphProcessPoint and returns a FlowNode object.

dataflow.FlowGraphProcessPoint

Defines the GraphProcessPoint constructor, which returns a GraphProcessPoint object.

Tensor

Defines the Tensor constructor.

numpy

Converts a tensor into an ndarray of NumPy.

dataflow.TensorDesc

Describes a tensor.

dataflow.alloc_tensor

Allocates a dataflow tensor based on the shape, data type, and alignment size.

dataflow.utils.generate_deploy_template

Generates a template of files required by the "ge.experiment.data_flow_deploy_info_path" option in a specified deployment location based on FlowGraph.

register

Registers the serialization, deserialization, and size calculation functions corresponding to the user-defined type. This function can be used together with the feed and fetch APIs to feed or fetch any Python type.

registered

Checks whether the message type ID has been registered.

get_msg_type

Obtains the registered message type based on the type definition.

get_serialize_func

Obtains the registered serialization function based on the message type ID.

get_deserialize_func

Obtains the registered deserialization function based on the message type ID.

get_size_func

Obtains the registered function for calculating the size of the serialized memory based on the message type ID.

deserialize_from_file

Deserializes the serialized pickle file to restore Python objects.

pyflow

Enables functions to be run locally or remotely as pipeline tasks.

method

Enables classes to be run locally or remotely as pipeline tasks in complex scenarios.

npu_model

If the UDF is deployed on the host, data needs to be copied from the device to the local host for computation. In PyTorch scenarios, when all computations, inputs, and outputs reside on the device, data still has to be copied from the device to the host during execution, followed by PyTorch transferring the data back to the device, which degrades performance. The npu_model API optimizes this process by eliminating data transfer overhead, allowing computations to be directly offloaded to the device for execution.

dataflow.CountBatch

CountBatch is used to combine multiple data records into batches based on batchSize, by using UDFs as compute ProcessPoints. This function applies to asynchronous DataFlow scenarios.

dataflow.TimeBatch

The TimeBatch function is based on the UDF.

In normal scenarios, a model processes a piece of data each time. To process multiple pieces of data at a time, you need to combine the data into a batch. A basic way is to directly combine the data (N pieces), and add N before the shape. In some scenarios, data of one or more time segments needs to be combined into a batch based on specific dimensions. In this case, you can use TimeBatch.

DataFlow Execution APIs

Table 2 DataFlow execution APIs

API

Description

dataflow.init

Initializes options in DataFlow.

FlowInfo

Indicates the flow information of DataFlow.

set_user_data

Sets user information.

get_user_data

Obtains user information.

user_data

Obtains user information.

data_size

Obtains the length of user_data.

start_time

Reads and sets the start time of FlowInfo in attribute mode.

end_time

Reads and sets the end time of FlowInfo in attribute mode.

flow_flags

Reads and sets flow_flags of FlowInfo in attribute mode.

transaction_id

Reads and writes transaction IDs in attribute mode.

feed_data

Inputs data to a graph.

feed

Inputs data to a graph. A serializable input is supported.

fetch_data

Obtains the graph output data.

fetch

Obtains the graph output data. A serializable output is supported.

dataflow.finalize

Frees the DataFlow initialization resources.

dataflow.get_running_device_id

Obtains the ID of the device where the current UDF runs during execution. This information is sourced from the UDF deployment location configuration.

dataflow.get_running_instance_id

Obtains IDs of running instances of the current UDF during execution. This information is sourced from the logic_device_list configuration in the data_flow_deploy_info.json file.

dataflow.get_running_instance_num

Obtains the number of running instances of the current UDF during execution. The information is sourced from the logic_device_list configuration in data_flow_deploy_info.json.

Module

dataflow module: namespace of common APIs

Class

  • CountBatch: class of the CountBatch attribute
  • FlowData: input node class
  • FlowFlag: data mark class
  • FlowGraph: DataFlow graph class
  • FlowInfo: information class carried in the input and output data
  • FlowNode: compute node class
  • FlowOutput: output class of the compute node
  • Framework: enumeration class of the IR file framework type
  • FuncProcessPoint: class of the UDF processing point
  • GraphProcessPoint: class of the graph processing point
  • Tensor: tensor data class
  • TensorDesc: tensor description class
  • TimeBatch: class of the TimeBatch attribute

Function

  • init(...): DataFlow resource initialization method
  • finalize(...): DataFlow resource release method

Other Members

Table 3 Other members

Name

Description

DT_FLOAT

Object of df.data_type.DType

32-bit single-precision floating point number

DT_FLOAT16

Object of df.data_type.DType

16-bit half-precision floating point number

DT_INT8

Object of df.data_type.DType

8-bit signed integer

DT_INT16

Object of df.data_type.DType

16-bit signed integer

DT_UINT16

Object of df.data_type.DType

16-bit unsigned integer

DT_UINT8

Object of df.data_type.DType

8-bit unsigned integer

DT_INT32

Object of df.data_type.DType

32-bit signed integer

DT_INT64

Object of df.data_type.DType

64-bit signed integer

DT_UINT32

Object of df.data_type.DType

32-bit unsigned integer

DT_UINT64

Object of df.data_type.DType

64-bit unsigned integer

DT_BOOL

Object of df.data_type.DType

Boolean

DT_DOUBLE

Object of df.data_type.DType

64-bit double-precision floating point number

DT_STRING

Object of df.data_type.DType

String