下载
中文
注册

DataFlow离线编译

功能介绍

DataFlow离线编译是指在开发环境编译,在运行环境上加载和部署,从而实现编译和建链解耦。

使用方法

  1. 开启图编译缓存。示例如下。
    1
    2
    3
    4
    5
    6
    std::map<ge::AscendString, ge::AscendString> session_options = {{"ge.graph_compiler_cache_dir", "./build_cache_dir"}};
    std::shared_ptr<ge::Session> session = std::make_shared<ge::Session>(session_options);
    const auto graph = CreateFlowGraph();
    std::map<ge::AscendString, ge::AscendString> graph_options = {{"ge.graph_key", "test_graph_001"}};
    auto = session->AddGraph(0, graph, graph_options);
    ...
    
  2. 配置开发环境。
    如果目标执行环境为Atlas A2训练系列产品/Atlas 800I A2推理产品,需要配置目标执行环境的numa_config.json文件,使用环境变量RESOURCE_CONFIG_PATH进行设置。示例如下:
     export RESOURCE_CONFIG_PATH=numa_config.json

    numa_config.json请参考numa_config.json配置。ipaddr字段可以使用任意IP。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    {
                        "host":{
                             "resourceType": "X86",
                        .........
                        "devList":[
                          {
                          "ipaddr":"XX.XX.XX.XX",     
                          "port":2509,
                          "deviceIdList":[0,1],
                          "resourceType":"Ascend",
                          "token":"OKIJBNHYGFVT7RGH",
                          "chip_count":2,
                          }
                       ],
    }
    
    表1 参数解释

    参数名

    含义

    resourceType

    可选,资源类型,可以取值为Ascend。需要与实际部署的运行环境中的resourceType保持一致。

    chip_count

    必选,加速卡的数量。需要与实际部署的运行环境数量保持一致。如果不一致,系统做如下处理。

    • chip_count>实际部署的运行环境数量时,部署阶段报错。
    • chip_count<实际部署的运行环境数量且负载均衡未指定部署位置,则模型按照编译阶段负载均衡方案部署,运行环境多出的设备不进行部署。

    不配置时离线功能不生效。

  3. 图生成。
    1. 调用AddGraph接口时设置option "ge.runFlag"="0"。
    2. 调用BuildGraph接口进行图编译,生成缓存文件。
      示例如下。
      1
      2
      3
      4
      5
      6
      7
      8
      map<AscendString, AscendString> options = {{"ge.graph_compiler_cache_dir", "./build_cache_dir"}, {"ge.runFlag", "0"}};
      Session session(options);
      map<AscendString, AscendString> graph_options = {{"ge.graph_key", "graph_key1"}}
      session.AddGraph(1, g1, graph_options);
      std::vector<InputTensorInfo> inputs;
      auto ret = session.BuildGraph(1, inputs);
      // build 接口可以替换成FeedDataFlowGraph接口
      auto ret = session.FeedDataFlowGraph(1, inputs, dataInfo);
      
    3. 离线部署。

      将开发环境中graph_compiler_cache_dir路径下的模型缓存文件、索引文件和变量格式文件拷贝到运行环境的graph_compiler_cache_dir路径。具体文件请参考缓存文件生成规则

      Atlas A2训练系列产品/Atlas 800I A2推理产品下的约束条件如下:

      执行环境的numa_config需要和编译时候保持一致,ipaddr字段除外。