DataFlow Offline Compilation
Function Description
DataFlow offline compilation refers to compilation in the development environment and loading and deployment in the operating environment. In this way, the compilation and link setup are decoupled.
Constraints
None
How to Use
- Enable graph compilation caching. The following is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# Perform initialization. SOC_VERSION = os.getenv('SOC_VERSION', 'AscendXXX') options = { "ge.exec.deviceId":"0", "ge.exec.logicalDeviceClusterDeployMode":"SINGLE", "ge.exec.logicalDeviceId":"[0:0]", "ge.graph_compiler_cache_dir":"./build_cache_dir", "ge.runFlag":"0" } df.init(options) flow_node0 = df.FlowNode(input_num=1, output_num=2) flow_node0_out = flow_node0(data0) # Construct a FlowGraph. Here focuses on the option usage. For details about how to construct a DataFlow graph, see other sections. options = { "ge.graph_key":"test_graph_00" } dag = df.FlowGraph([out for out in flow_node0_out], options)
- Configure the development environment.Use the environment variable RESOURCE_CONFIG_PATH to configure the numa_config.json file in the target execution environment. The following is an example:
export RESOURCE_CONFIG_PATH=numa_config.json // Specify the path for storing the heterogeneous resource description file.
For details about numa_config.json, see numa_config.json Configuration. The ipaddr field can be set to any IP address.
- Generate the graph.
- Call the feed_data API to compile the graph and generate a cache file.The following is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
graph_options = {"ge.graph_key" : "key"} # Construct a FlowGraph. dag = df.FlowGraph([flow_node2_out], graph_options) # Feed data. feed_data0 = np.ones([1,2], dtype=np.int32) feed_data1 = np.array([[1,2]], dtype=np.int32) flow_info = df.FlowInfo() flow_info.start_time = 0 flow_info.end_time = 5 dag.feed_data({data0:feed_data0, data1:feed_data1}, flow_info) # Feed data asynchronously. # The feed_data API involves graph compilation and loading. If ge.runFlag is set to 0, only graph compilation is performed. graph_options = {"ge.graph_key" : "key", "ge.runFlag": "0"}
- Perform offline deployment.
Copy the model cache file, index file, and variable format file from graph_compiler_cache_dir in the development environment to graph_compiler_cache_dir in the operating environment. For details about the files, see Cache File Generation Rules.
Constraints for the
Atlas A2 training product /Atlas A2 inference product :The numa_config.json file in the operating environment must be the same as that in the compilation environment, except for the ipaddr field.
- Call the feed_data API to compile the graph and generate a cache file.