
# 训练结果输出
#### 日志及权重
训练过程中，MindSpeed-LLM框架训练loss、性能信息日志会在最后的Rank节点打印，Llama-Factory框架loss、性能信息日志会在第一个Rank节点打印。训练结果结构说明如下：
- MindSpeed-LLM
  ```
  |──{af_output_dir} #{af_output_dir}参数设置值，如yaml文件中参数配置
      # 自动生成数据目录结构
      |──preprocess_data                        # 数据预处理目录
      |──converted_weight_TP${TP}PP${PP}        # 原始HF转MG格式权重目录
      |──ckpt_converted_mg2hf                   # 训练完成权重MG转HF格式权重
      |──saved_checkpoints                      # 训练完成MG格式权重
      |──training_loss.png                      # loss曲线图
      |──exp-config.yaml                        # 训练脚本（ascendfactory-cli config工具生成）
      |──logs                                   # 训练日志
        |──xx-xx-<时间戳>-npu_info-R${RankID}.txt          # 训练显存监控日志
        |──xx-xx-<时间戳>-run_log-${Nodes}-${RankID}.txt   # 训练过程运行日志
      |──......
  ```
  
- Llama-Factory
  ```
  |──{output_dir} #{output_dir}参数设置值，如yaml文件中参数配置
    # 自动生成数据目录结构
    |──model-000xx-of-000xx.safetensors      # 权重文件
    |──trainer_log.jsonl                     # 训练jsonl文件loss打印
    |──training_loss.png                     # loss曲线图
    |──lora_merged                           # lora微调默认合并后的权重路径
    |──logs                                  # 训练日志
      |──xx-xx-<时间戳>-npu_info-R${RankID}_WS${world_size}.txt # 显存监控日志
      |──xx-xx-<时间戳>-run_log-R${RankID}_WS${world_size}.txt  # 过程运行日志
    |──......
  ```
  
- VeRL
  ```
  |──{af_output_dir}                                   # {af_output_dir}日志输出目录
      # 自动生成数据目录结构
      |──exp-config.yaml                               # 训练配置文件
      |──training_loss.png                             # reward、response曲线图片
      |──plog                                          # 模型算子日志
        |──rank*
      |──logs                                          # 训练日志目录
        |──verl_grpo-{af_model_name}-<序列长度-设备类型-时间戳>-run_log-N1-WS8.txt # loss等文件
      |──saved_checkpoints                             # 训练日志目录
        |──global_step_{number_1}
          |──actor                                     # 权重文件路径，权重合并时入参指定该目录
            |──huggingface                             # 权重合并的输出路径
        |──global_step_{number_N}
        |──latest_checkpointed_iteration.txt           # 最新的保存点迭代次数
  ```
  
- MindSpeed-RL
  ```
  |──{af_output_dir} #{af_output_dir}参数设置值，如yaml文件中参数配置
      # 自动生成数据目录结构
      |──preprocessed_data                      # 数据预处理目录
      |──converted_hf2mg_weight_TP${TP}PP${PP}  # 原始HF转MG格式权重目录
      |──converted_mg2hf_weight                 # 训练完成权重MG转HF格式权重
      |──saved_checkpoints                      # 训练完成MG格式权重
      |──logs                                   # 训练日志
        |──grpo_metrics-<时间>.log                         # 训练性能指标日志
        |──xx-xx-<时间戳>-npu_info-R${RankID}.txt          # 训练显存监控日志
        |──xx-xx-<时间戳>-run_log-${Nodes}-${RankID}.txt   # 训练过程运行日志
  ```
  
 
- MindSpeed-MM
  ```
  |──{af_output_dir} #{af_output_dir}参数设置值，如yaml文件中参数配置
      # 自动生成数据目录结构
      |──converted_weight_TP${TP}PP${PP}        # 原始HF转MG格式权重目录
      |──ckpt_converted_mg2hf                   # 训练完成权重MG转HF格式权重
      |──saved_checkpoints                      # 训练完成MG格式权重
      |──exp-config.yaml                        # 训练脚本（ascendfactory-cli config工具生成）
      |──logs                                   # 训练日志
        |──xx-xx-<时间戳>-npu_info-R${RankID}.txt          # 训练显存监控日志
        |──xx-xx-<时间戳>-run_log-${Nodes}-${RankID}.txt   # 训练过程运行日志
      |──......
  ```
  
#### 查看日志
查看启动作业日志信息，可通过以下命令打印正在启动的日志信息。其中${pod_name}为pod信息中的NAME，例如vcjob-main-0。
```
kubectl logs -f ${pod_name}
```
图1打印训练日志   
![](https://support.huaweicloud.com/bestpractice-modelarts/figure/zh-cn_image_0000002470740680.png "点击放大")
![](https://support.huaweicloud.com/bestpractice-modelarts/public_sys-resources/note_3.0-zh-cn.png)
对于轻量算力集群场景也支持[通过云原生日志采集插件采集容器日志](https://support.huaweicloud.com/usermanual-cce/cce_10_0555.html)并转储到LTS。
#### 查看性能
训练性能主要通过训练日志中的2个指标查看：吞吐量和收敛情况。
- MindSpeed-LLM
  1. 吞吐量（tokens/s/p）：global batch size\*seq_length/(总卡数\*elapsed time per iteration)\*1000，其中global batch size（GBS）、seq_length（SEQ_LEN）为训练时设置的参数，日志中有打印。
  
  2. loss收敛情况：日志里存在lm loss参数，lm loss参数随着训练迭代周期持续性减小，并逐渐趋于稳定平缓。也可以使用可视化工具[TrainingLogParser](https://curryrice233.github.io/TrainingLogParser/)查看loss收敛情况。
   
- Llama-Factory
  1. 吞吐量（tokens/s/p）：通过**${output_dir}** 参数值路径下的**trainer_log.jsonl** 文件计算性能。取中间过程多steps平均值吞吐计算，一般**训练日志** 中**已** 计算打印出**吞吐值** 。公式为：
     delta_tokens = end_total_tokens-start_total_tokens
     delta_time = end_elapsed_time - start_elapsed_time
     吞吐值(tps) = delta_tokens / delta_time / 训练卡数
     如图所示：
     ![](https://support.huaweicloud.com/bestpractice-modelarts/figure/zh-cn_image_0000002503660553.png "点击放大")
     
  
  2. loss收敛情况：loss收敛图存放在**${output_dir}** 参数值路径下的**training_loss.png** 中，也可以使用可视化工具[TrainingLogParser](https://curryrice233.github.io/TrainingLogParser/)查看loss收敛情况，将**trainer_log.jsonl**文件上传至可视化工具页面即可。
   

- VeRL
  1. 吞吐量（tokens/s/p）：通过**${output_dir}** 参数值路径下的verl_grpo-{af_model_name}-\<序列长度-设备类型-时间戳\>-run_log-N1-WS8.txt文件计算性能。训练日志文件中perf/throughput字段代表单步计算的吞吐值，可以使用可视化工具[TrainingLogParser](https://curryrice233.github.io/TrainingLogParser/)查看perf/throughput整体训练平均吞吐量。
  
  2. score收敛情况：日志里存在critic/score/mean参数 ，critic/score/mean参数随着训练迭代周期越来越大，期望逐渐趋于1并收敛。也可以使用可视化工具[TrainingLogParser](https://curryrice233.github.io/TrainingLogParser/)查看critic/score/mean收敛情况。
   

- MindSpeed-RL
  1. 吞吐量（tokens/s/p）：**${output_dir}** 参数值路径下的**grpo_metrics-\<时间\>.log** 计算性能。训练日志文件中的最后三个指标，e2e_tps、update_tps、vllm_tps分别代表这个step迭代一次端到端的吞吐值，训练的吞吐以及推理的吞吐，可以使用可视化工具[TrainingLogParser](https://curryrice233.github.io/TrainingLogParser/)查看e2e_tps、update_tps、vllm_tps整体平均吞吐量。
  
  2. reward acc收敛情况
     - qwen2.5-7b、32B默认用的DeepScaleR数据集，verify_function用的是base_acc，因此日志里存在grpo/base_acc_rewards/mean参数，随着训练迭代周期持续性增大，并逐渐趋于稳定平缓。也可以使用可视化工具[TrainingLogParser](https://curryrice233.github.io/TrainingLogParser/)查看grpo/base_acc_rewards/mean收敛情况。
       ![](https://support.huaweicloud.com/bestpractice-modelarts/figure/zh-cn_image_0000002503500637.png "点击放大")
       
     
     
     
     - qwen2.5-1.5B模型因为模型太弱，默认换成math-17k数据集，verify_function用的是math_17k_acc，因此日志里存在grpo/math_17k_acc_rewards/mean，随着训练迭代周期持续性增大，并逐渐趋于稳定平缓。也可以使用可视化工具[TrainingLogParser](https://curryrice233.github.io/TrainingLogParser/)查看grpo/math_17k_acc_rewards/mean收敛情况。
       ![](https://support.huaweicloud.com/bestpractice-modelarts/figure/zh-cn_image_0000002470580686.png "点击放大")
       
      
   
- MindSpeed-MM
  1. 吞吐量（samples/s）：global batch size/elapsed time per iteration\*1000，其中global batch size （GBS）为训练时设置的参数，日志中有打印。
  
  2. loss收敛情况：日志里会打印 loss 值，loss 随着训练迭代周期持续减小，并逐渐趋于稳定平缓。也可以使用可视化工具 [TrainingLogParser](https://curryrice233.github.io/TrainingLogParser/)查看loss收敛情况。
   
 
