Before using ascendebug, you must prepare input data and golden data of the operator.
Input data: input data when the static-shape operator is running, in binary format.
Golden data: truth data computed based on the input, used for accuracy comparison with the output data, in binary format.
This section provides multiple methods for preparing data. You can select a method based on your requirements.
Method 1: Use input data and golden data that are provided externally.
You can use external data sources to debug operators. This applies to the scenario where you debug operators for the first time.
In the operator JSON configuration file, set gen_data to false and data_file to the absolute path of input data and golden data. The following is an example:
{
"gen_data": false,
"inputs": [
{
"data_file": "/path/to/input_data_q.bin"
}
],
"outputs": [
{
"data_file": "/path/to/golden_data_out.bin"
}
]
} If the external data source is a .pt file, convert it to a .bin file. The following uses PyTorch as an example:
import torch
model = torch.load('model.pt') # Load the .pt file.
torch.save(model, 'model.bin') # Save model parameters as a .bin file. Method 2: Use input data and golden data that have been generated.
To re-execute the operator for multiple times, you are advised to use the historical data. This helps to avoid repeated generation and long debugging time.
In the operator JSON configuration file, set gen_data to false and data_file to the name of the .bin file corresponding to the input data and golden data (excluding the path information, and the data file is searched in the current path by default). The following is an example:
{
"gen_data": false,
"inputs": [
{
"data_file": "input_data_q.bin"
}
],
"outputs": [
{
"data_file": "golden_data_out.bin"
}
]
} Method 3: Use input data that is randomly generated.
If you have not prepared any data, you can use the input data that is randomly generated by the tool. The generated .bin data file is stored in the data folder of the corresponding operator in the current path by default. In this scenario, there is no golden data. Therefore, accuracy comparison is not supported.
In the operator information JSON configuration file, set gen_data to true, data_script to an empty string or null, and data_file to the name of the .bin file corresponding to the input data and golden data (excluding the path information. By default, the data file is searched for in the current path). The following is an example:
"data_script": "", "gen_data": true, "shape": [1, 16384], "data_file": "sample.bin",
Method 4: Use a script to generate input/golden data.
You need to prepare the data generation script (usually a .py file) and configure the operator JSON configuration file.
Set gen_data to true, data_script to the path of the data generation script (with the FlashAttentionScore operator as an example), and data_file to the name of the .bin file corresponding to the input data and golden data (excluding the path information, and the data file is searched in the current path by default). The following is an example:
"data_script": "${fa_case_dir}/flash_attention_score_golden.py",
"gen_data": true,
"data_file": "sample.bin", When data is generated, this script is called and the following parameters are fixedly passed into it:
sys.argv[1]: input JSON configuration file of the operator.
sys.argv[2]: path of the output .bin file (data folder in the working path, for example, debug_workspace/FlashAttentionScore/data/).