From 39a0ec48b15e8c7e8631bb70c788209e9db90177 Mon Sep 17 00:00:00 2001 From: carry <2641257231@qq.com> Date: Wed, 30 Apr 2025 15:21:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor(latex):=20=E6=9B=B4=E6=96=B0=E5=9B=BE?= =?UTF-8?q?=E8=A1=A8=E7=94=9F=E6=88=90=E6=96=B9=E5=BC=8F=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=96=87=E6=A1=A3=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将图表生成方式从外部Python脚本迁移到LaTeX内部使用pgfplots绘制,以提升文档的可维护性和一致性。同时,更新了caption包的配置,移除了不再使用的caption2包,并添加了subcaption包以支持子图功能。 --- paper/latex/chapters/verification.tex | 73 +++++++++++++++++-- .../figures}/training_data.csv | 0 paper/latex/main.tex | 7 +- paper/object/plot_training_data.py | 44 ----------- 4 files changed, 72 insertions(+), 52 deletions(-) rename paper/{object => latex/figures}/training_data.csv (100%) delete mode 100644 paper/object/plot_training_data.py diff --git a/paper/latex/chapters/verification.tex b/paper/latex/chapters/verification.tex index fd12912..e345321 100644 --- a/paper/latex/chapters/verification.tex +++ b/paper/latex/chapters/verification.tex @@ -117,21 +117,84 @@ \label{fig:tensorboard} \end{figure} -微调过程中,主要训练指标的变化趋势如图\ref{fig:training_metrics}所示。从图中可以观察到以下几个关键特征: +微调过程中,主要训练指标的变化趋势如图\ref{fig:training_metrics}所示,包括损失值(图\ref{fig:loss_metrics})、梯度范数(图\ref{fig:grad_norm_metrics})和学习率(图\ref{fig:learning_rate_metrics})三个关键指标。从这些图表中可以观察到以下几个关键特征: +\pgfplotsset{compat=1.18} \begin{figure}[htbp] \centering - \includegraphics[width=0.8\textwidth]{pic/training_metrics.png} + \begin{subfigure}[b]{0.8\textwidth} + \centering + \begin{tikzpicture} + \begin{axis}[ + width=\textwidth, + height=5cm, + xlabel={训练步数 (Step)}, + ylabel={损失值 (Loss)}, + xmin=0, xmax=7029, + ymin=0, ymax=2.5, + ymajorgrids=true, + grid style=dashed, + ] + \addplot[smooth, thick, blue] table[x=Step, y=loss, col sep=comma] {./figures/training_data.csv}; + + \end{axis} + \end{tikzpicture} + \caption{损失值变化趋势} + \label{fig:loss_metrics} + \end{subfigure} + + \begin{subfigure}[b]{0.8\textwidth} + \centering + \begin{tikzpicture} + \begin{axis}[ + width=\textwidth, + height=5cm, + xlabel={训练步数 (Step)}, + ylabel={梯度范数 (Grad Norm)}, + xmin=0, xmax=7029, + ymin=0, ymax=1.8, + ymajorgrids=true, + grid style=dashed, + ] + \addplot[smooth, thick, red] table[x=Step, y=grad_norm, col sep=comma] {./figures/training_data.csv}; + + \end{axis} + \end{tikzpicture} + \caption{梯度范数变化趋势} + \label{fig:grad_norm_metrics} + \end{subfigure} + + \begin{subfigure}[b]{0.8\textwidth} + \centering + \begin{tikzpicture} + \begin{axis}[ + width=\textwidth, + height=5cm, + xlabel={训练步数 (Step)}, + ylabel={学习率 (Learning Rate)}, + xmin=0, xmax=7029, + ymin=0, ymax=0.0002, + ymajorgrids=true, + grid style=dashed, + ] + \addplot[smooth, thick, green!60!black] table[x=Step, y=learning_rate, col sep=comma] {./figures/training_data.csv}; + + \end{axis} + \end{tikzpicture} + \caption{学习率变化趋势} + \label{fig:learning_rate_metrics} + \end{subfigure} + \caption{模型微调过程中的训练指标变化趋势} \label{fig:training_metrics} \end{figure} \begin{itemize} - \item \textbf{梯度范数(Gradient Norm)}:训练初期,梯度范数在0.5到1.5之间波动,表明参数更新幅度较大。随着训练步数的增加,梯度范数逐渐减小,并在约4000步后稳定在0.1到0.5之间,这与损失函数的下降趋势一致,表明模型正在趋于收敛,参数更新的步伐减缓。 + \item \textbf{损失函数(Loss)}:如图\ref{fig:loss_metrics}所示,训练初期,损失值从约2.4迅速下降。在约1000步时降至0.5以下,随后继续缓慢下降。在大约5000步后,损失值稳定在接近于零的水平,表明模型在训练集上已经取得了很好的性能,基本收敛。 - \item \textbf{损失函数(Loss)}:训练初期,损失值从约2.4迅速下降。在约1000步时降至0.5以下,随后继续缓慢下降。在大约5000步后,损失值稳定在接近于零的水平,表明模型在训练集上已经取得了很好的性能,基本收敛。 + \item \textbf{梯度范数(Gradient Norm)}:如图\ref{fig:grad_norm_metrics}所示,训练初期,梯度范数在0.5到1.5之间波动,表明参数更新幅度较大。随着训练步数的增加,梯度范数逐渐减小,并在约4000步后稳定在0.1到0.5之间,这与损失函数的下降趋势一致,表明模型正在趋于收敛,参数更新的步伐减缓。 - \item \textbf{学习率(Learning Rate)}:学习率采用线性衰减策略,从初始值约0.0002(或2e-4)随着训练步数的增加而稳定地线性降低,直至训练结束时接近于零。这种策略有助于在训练初期快速探索解空间,并在后期精细调整参数以促进模型稳定收敛。 + \item \textbf{学习率(Learning Rate)}:如图\ref{fig:learning_rate_metrics}所示,学习率采用线性衰减策略,从初始值约0.0002(或2e-4)随着训练步数的增加而稳定地线性降低,直至训练结束时接近于零。这种策略有助于在训练初期快速探索解空间,并在后期精细调整参数以促进模型稳定收敛。 \item \textbf{训练效率}:整个微调过程耗时约5.5小时,平均每步训练时间约3秒,展现了本框架在资源受限环境下的高效性。特别是在训练后期,尽管学习率降低,模型仍能持续优化,损失值稳步下降,表明LoRA微调方法的有效性。 \end{itemize} diff --git a/paper/object/training_data.csv b/paper/latex/figures/training_data.csv similarity index 100% rename from paper/object/training_data.csv rename to paper/latex/figures/training_data.csv diff --git a/paper/latex/main.tex b/paper/latex/main.tex index 223ca49..78ce8b4 100644 --- a/paper/latex/main.tex +++ b/paper/latex/main.tex @@ -3,12 +3,13 @@ \usepackage{graphicx} \usepackage{ctex} \usepackage{indentfirst} +\usepackage{subcaption} %\graphicspath{{chapter/}{figures/}} \usepackage{CJK} \usepackage{amsmath}%数学 \usepackage{amssymb}%数学符号 %\usepackage[colorlinks,linkcolor=red]{hyperref}%超链接 - +\usepackage{pgfplots} \usepackage{fancyhdr} %使用fancyhdr包自定义页眉页脚 %\pagestyle{empty} \pagestyle{fancy} @@ -21,8 +22,8 @@ \renewcommand{\figurename}{图}%将figure改为图 -\usepackage[]{caption2}%去掉图片编号后的":" -\renewcommand{\captionlabeldelim}{} +\usepackage{caption}%去掉图片编号后的":" +\captionsetup{labelformat=simple, labelsep=space} \renewcommand {\thefigure} {\thesection{}.\arabic{figure}}%图片索引该为按照章节 diff --git a/paper/object/plot_training_data.py b/paper/object/plot_training_data.py deleted file mode 100644 index e894c8a..0000000 --- a/paper/object/plot_training_data.py +++ /dev/null @@ -1,44 +0,0 @@ -import pandas as pd -import matplotlib.pyplot as plt - -# 设置全局字体大小 -plt.rcParams.update({ - 'font.size': 16, # 全局字体大小 - 'axes.titlesize': 20, # 标题字体大小 - 'axes.labelsize': 16, # 坐标轴标签字体大小 - 'xtick.labelsize': 14, # x轴刻度标签字体大小 - 'ytick.labelsize': 14, # y轴刻度标签字体大小 - 'legend.fontsize': 14, # 图例字体大小 -}) - -# 读取CSV文件 -data = pd.read_csv('training_data.csv') - -# 创建图表 -plt.figure(figsize=(12, 12)) - -# 绘制梯度范数变化曲线 -plt.subplot(3, 1, 1) # 修改为 3行1列的第1个 -plt.plot(data['Step'], data['grad_norm'], label='Gradient Norm') -plt.xlabel('Step') -plt.ylabel('Gradient Norm') -plt.legend() - -# 绘制损失值变化曲线 -plt.subplot(3, 1, 2) # 修改为 3行1列的第2个 -plt.plot(data['Step'], data['loss'], label='Loss', color='orange') -plt.xlabel('Step') -plt.ylabel('Loss') -plt.legend() - -# 绘制学习率变化曲线 -plt.subplot(3, 1, 3) # 修改为 3行1列的第3个 -plt.plot(data['Step'], data['learning_rate'], label='Learning Rate', color='green') -plt.xlabel('Step') -plt.ylabel('Learning Rate') -plt.legend() - -# 调整布局并保存图片 -plt.tight_layout() -plt.savefig('training_metrics.png') -plt.show() \ No newline at end of file