Offline Parsing

When the profile data collected using the Ascend PyTorch Profiler APIs is large, using the on_trace_ready API in the current environment for automatic parsing may cause excessive resource consumption and result in lags. In this case, you can cancel the on_trace_ready API, use the ASCEND_WORK_PATH environment variable to set the flush directory (for example, export ASCEND_WORK_PATH=xx/xx), and use the following method to parse the collected profile data in offline mode:

  1. Create the {file_name}.py file ({file_name} is custom), and edit the following code:
    1
    2
    3
    4
    from torch_npu.profiler.profiler import analyse
    
    if __name__ == "__main__":
        analyse(profiler_path="./result_data", max_process_number=max_process_number, export_type=export_type)
    
    Table 1 Parameters

    Parameter

    Description

    Required/Optional

    profiler_path

    PyTorch profile data path. The path can contain only letters, digits, underscores (_), and hyphens (-). Soft links are not supported. This specified path stores the PyTorch profile data directory {worker_name}_{timestamp}_ascend_pt.

    Required

    max_process_number

    Maximum number of offline analysis processes. The value ranges from 1 to the number of CPU cores. The default value is half of the number of CPU cores. If the value of this parameter exceeds the number of available CPU cores in the environment, the system will automatically utilize all available CPU cores. If this parameter is set to an invalid value, half of the default number of CPU cores is used.

    Optional

    export_type

    Format of the exported profile data result file, list type. Possible values are:

    • text: parsed into timeline and summary files in .json and .csv formats and a .db file (ascend_pytorch_profiler_{Rank_ID}.db or analysis.db) that summarizes all profile data.
    • db: parsed into a .db file (ascend_pytorch_profiler_{Rank_ID}.db or analysis.db) that summarizes all profile data and is displayed by the MindStudio Insight tool. Only the on_trace_ready API and offline parsing can be used to export data. The CANN Toolkit and ops operator package that support the export of .db files must be installed.

    If this parameter is set to an invalid value or is not configured, the export_type field in the profiler_info.json file is read to determine the export format.

    For details about the parsing results, see MindSpore & PyTorch Profile Data File References.

    Optional

    • The offline parsing API supports parallel parsing of multiple profile data directories. In cases where the profile data volume is large and there are many data directories, parsing may fail due to insufficient memory in the environment. In these cases, you can customize the maximum number of processes (max_process_number) to control the resource usages.
    • The parsing process logs are stored in the {worker_name}_{timestamp}_ascend_pt/logs directory.
  2. Save the file and run the following command to parse the profile data:
    python3 {file_name}.py
  3. View and analyze the profile data result files.

    For details about the profile data result files, see MindSpore & PyTorch Profile Data File References.

    For details about how to visualize and analyze the parsed profile data files, see MindStudio Insight User Guide.

    You can use the msprof-analyze to analyze the profile data.