首页 > 其他分享 >[本科项目实训] P-Tuning v2 训练记录

[本科项目实训] P-Tuning v2 训练记录

时间:2024-06-24 12:43:21浏览次数:3  
标签:Tuning 05 -- py 2024 v2 实训 chatglm 21

训练脚本

PRE_SEQ_LEN=64
LR=2e-2

CUDA_VISIBLE_DEVICES=0 python3 main.py \
    --do_train \
    --train_file trainVX.json \
    --validation_file devVX.json \
    --prompt_column content \
    --response_column summary \
    --overwrite_cache \
    --model_name_or_path /home/lyc/workspace/ChatGLM-6B/chatglm-6b \
    --output_dir output/dsbtpg-chatglm-6b-pt-$PRE_SEQ_LEN-$LR \
    --overwrite_output_dir \
    --max_source_length 64 \
    --max_target_length 64 \
    --per_device_train_batch_size 4 \
    --per_device_eval_batch_size 1 \
    --gradient_accumulation_steps 16 \
    --predict_with_generate \
    --max_steps 500 \
    --logging_steps 20 \
    --save_steps 100 \
    --learning_rate $LR \
    --pre_seq_len $PRE_SEQ_LEN \
    --quantization_bit 8

训练脚本如上例,各参数含义可以参考 [1] ,我们尝试了一些参数变化对于模型的影响,但由于目标任务的难度并不大,所以在实际使用过程中差异并不明显。

训练过程

$ python gen_dataVX.py
Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
Explicitly passing a `revision` is encouraged when loading a configuration with custom code to ensure no malicious code has been contributed in a newer revision.
Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
Loading checkpoint shards: 100%|██████████████████████████████████████████████████████████| 8/8 [00:10<00:00,  1.34s/it]
The dtype of attention mask (torch.int64) is not bool
(/home/lyc/workspace/Conda-env/dsbtpg) root@autodl-container-07ff4facf2-80be90b7:/home/lyc/workspace/ChatGLM-6B/ptuning# bash trainVX.sh 
05/21/2024 12:09:10 - WARNING - __main__ - Process rank: -1, device: cuda:0, n_gpu: 1distributed training: False, 16-bits training: False
05/21/2024 12:09:10 - INFO - __main__ - Training/evaluation parameters Seq2SeqTrainingArguments(
_n_gpu=1,
adafactor=False,
adam_beta1=0.9,
adam_beta2=0.999,
adam_epsilon=1e-08,
auto_find_batch_size=False,
bf16=False,
bf16_full_eval=False,
data_seed=None,
dataloader_drop_last=False,
dataloader_num_workers=0,
dataloader_pin_memory=True,
ddp_bucket_cap_mb=None,
ddp_find_unused_parameters=None,
ddp_timeout=1800,
debug=[],
deepspeed=None,
disable_tqdm=False,
do_eval=False,
do_predict=False,
do_train=True,
eval_accumulation_steps=None,
eval_delay=0,
eval_steps=None,
evaluation_strategy=no,
fp16=False,
fp16_backend=auto,
fp16_full_eval=False,
fp16_opt_level=O1,
fsdp=[],
fsdp_config={'fsdp_min_num_params': 0, 'xla': False, 'xla_fsdp_grad_ckpt': False},
fsdp_min_num_params=0,
fsdp_transformer_layer_cls_to_wrap=None,
full_determinism=False,
generation_max_length=None,
generation_num_beams=None,
gradient_accumulation_steps=16,
gradient_checkpointing=False,
greater_is_better=None,
group_by_length=False,
half_precision_backend=auto,
hub_model_id=None,
hub_private_repo=False,
hub_strategy=every_save,
hub_token=<HUB_TOKEN>,
ignore_data_skip=False,
include_inputs_for_metrics=False,
jit_mode_eval=False,
label_names=None,
label_smoothing_factor=0.0,
learning_rate=0.02,
length_column_name=length,
load_best_model_at_end=False,
local_rank=-1,
log_level=passive,
log_level_replica=warning,
log_on_each_node=True,
logging_dir=output/dsbtpg-chatglm-6b-pt-64-2e-2/runs/Jun24_02-09-10_autodl-container-07ff4facf2-80be90b7,
logging_first_step=False,
logging_nan_inf_filter=True,
logging_steps=20,
logging_strategy=steps,
lr_scheduler_type=linear,
max_grad_norm=1.0,
max_steps=1500,
metric_for_best_model=None,
mp_parameters=,
no_cuda=False,
num_train_epochs=3.0,
optim=adamw_hf,
optim_args=None,
output_dir=output/dsbtpg-chatglm-6b-pt-64-2e-2,
overwrite_output_dir=True,
past_index=-1,
per_device_eval_batch_size=1,
per_device_train_batch_size=4,
predict_with_generate=True,
prediction_loss_only=False,
push_to_hub=False,
push_to_hub_model_id=None,
push_to_hub_organization=None,
push_to_hub_token=<PUSH_TO_HUB_TOKEN>,
ray_scope=last,
remove_unused_columns=True,
report_to=[],
resume_from_checkpoint=None,
run_name=output/dsbtpg-chatglm-6b-pt-64-2e-2,
save_on_each_node=False,
save_steps=500,
save_strategy=steps,
save_total_limit=None,
seed=42,
sharded_ddp=[],
skip_memory_metrics=True,
sortish_sampler=False,
tf32=None,
torch_compile=False,
torch_compile_backend=None,
torch_compile_mode=None,
torchdynamo=None,
tpu_metrics_debug=False,
tpu_num_cores=None,
use_ipex=False,
use_legacy_prediction_loop=False,
use_mps_device=False,
warmup_ratio=0.0,
warmup_steps=0,
weight_decay=0.0,
xpu_backend=None,
)
/home/lyc/workspace/Conda-env/dsbtpg/lib/python3.10/site-packages/datasets/load.py:2547: FutureWarning: 'use_auth_token' was deprecated in favor of 'token' in version 2.14.0 and will be removed in 3.0.0.
You can remove this warning by passing 'token=<use_auth_token>' instead.
  warnings.warn(
Generating train split: 540 examples [00:00, 79703.14 examples/s]
Generating validation split: 140 examples [00:00, 74565.40 examples/s]
[INFO|configuration_utils.py:666] 2024-05-21 12:09:10,905 >> loading configuration file /home/lyc/workspace/ChatGLM-6B/chatglm-6b/config.json
[WARNING|configuration_auto.py:905] 2024-05-21 12:09:10,905 >> Explicitly passing a `revision` is encouraged when loading a configuration with custom code to ensure no malicious code has been contributed in a newer revision.
[INFO|configuration_utils.py:666] 2024-05-21 12:09:10,930 >> loading configuration file /home/lyc/workspace/ChatGLM-6B/chatglm-6b/config.json
[INFO|configuration_utils.py:720] 2024-05-21 12:09:10,930 >> Model config ChatGLMConfig {
  "_name_or_path": "/home/lyc/workspace/ChatGLM-6B/chatglm-6b",
  "architectures": [
    "ChatGLMModel"
  ],
  "auto_map": {
    "AutoConfig": "configuration_chatglm.ChatGLMConfig",
    "AutoModel": "modeling_chatglm.ChatGLMForConditionalGeneration",
    "AutoModelForSeq2SeqLM": "modeling_chatglm.ChatGLMForConditionalGeneration"
  },
  "bos_token_id": 130004,
  "eos_token_id": 130005,
  "gmask_token_id": 130001,
  "hidden_size": 4096,
  "inner_hidden_size": 16384,
  "layernorm_epsilon": 1e-05,
  "mask_token_id": 130000,
  "max_sequence_length": 2048,
  "model_type": "chatglm",
  "num_attention_heads": 32,
  "num_layers": 28,
  "pad_token_id": 3,
  "position_encoding_2d": true,
  "pre_seq_len": null,
  "prefix_projection": false,
  "quantization_bit": 0,
  "torch_dtype": "float16",
  "transformers_version": "4.27.1",
  "use_cache": true,
  "vocab_size": 130528
}

[WARNING|tokenization_auto.py:652] 2024-05-21 12:09:10,931 >> Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
[INFO|tokenization_utils_base.py:1800] 2024-05-21 12:09:10,951 >> loading file ice_text.model
[INFO|tokenization_utils_base.py:1800] 2024-05-21 12:09:10,951 >> loading file added_tokens.json
[INFO|tokenization_utils_base.py:1800] 2024-05-21 12:09:10,951 >> loading file special_tokens_map.json
[INFO|tokenization_utils_base.py:1800] 2024-05-21 12:09:10,951 >> loading file tokenizer_config.json
[WARNING|auto_factory.py:456] 2024-05-21 12:09:11,153 >> Explicitly passing a `revision` is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
[INFO|modeling_utils.py:2400] 2024-05-21 12:09:11,204 >> loading weights file /home/lyc/workspace/ChatGLM-6B/chatglm-6b/pytorch_model.bin.index.json
[INFO|configuration_utils.py:575] 2024-05-21 12:09:11,205 >> Generate config GenerationConfig {
  "_from_model_config": true,
  "bos_token_id": 130004,
  "eos_token_id": 130005,
  "pad_token_id": 3,
  "transformers_version": "4.27.1"
}

Loading checkpoint shards: 100%|██████████████████████████████████████████████████████████| 8/8 [00:11<00:00,  1.38s/it]
[INFO|modeling_utils.py:3032] 2024-05-21 12:09:22,387 >> All model checkpoint weights were used when initializing ChatGLMForConditionalGeneration.

[WARNING|modeling_utils.py:3034] 2024-05-21 12:09:22,387 >> Some weights of ChatGLMForConditionalGeneration were not initialized from the model checkpoint at /home/lyc/workspace/ChatGLM-6B/chatglm-6b and are newly initialized: ['transformer.prefix_encoder.embedding.weight']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
[INFO|modeling_utils.py:2690] 2024-05-21 12:09:22,458 >> Generation config file not found, using a generation config created from the model config.
Quantized to 8 bit

以上为模型的加载内容,模型训练过程中会展示loss和部分训练样例,如:

{'loss': 1.1579, 'learning_rate': 0.0192, 'epoch': 2.37}                                                                
{'loss': 0.3397, 'learning_rate': 0.0184, 'epoch': 4.74}                                                                
{'loss': 0.3101, 'learning_rate': 0.0176, 'epoch': 7.11}                                                                
{'loss': 0.3134, 'learning_rate': 0.0168, 'epoch': 9.48}                                                                
{'loss': 0.3046, 'learning_rate': 0.016, 'epoch': 11.85}                                                                
 20%|█████▊                   | 100/500 [15:49<1:03:04,  9.46s/it]

可以观察到loss有明显下降,并且lr随训练次数降低以确保模型收敛,模型训练完后会自动保存并展示训练指标:

{'loss': 0.2978, 'learning_rate': 0.0032, 'epoch': 49.78}                                                               
{'loss': 0.2993, 'learning_rate': 0.0024, 'epoch': 52.15}                                                               
{'loss': 0.2991, 'learning_rate': 0.0016, 'epoch': 54.52}                                                               
{'loss': 0.2983, 'learning_rate': 0.0008, 'epoch': 56.89}                                                               
{'loss': 0.2957, 'learning_rate': 0.0, 'epoch': 59.26}                                                                  
100%|███████████████████████████████████████████████████████████████████████████████| 500/500 [1:18:43<00:00,  9.45s/it]Saving PrefixEncoder
[INFO|configuration_utils.py:457] 2024-05-21 13:34:01,058 >> Configuration saved in output/dsbtpg-chatglm-6b-pt-64-2e-2/checkpoint-500/config.json
[INFO|configuration_utils.py:362] 2024-05-21 13:34:01,060 >> Configuration saved in output/dsbtpg-chatglm-6b-pt-64-2e-2/checkpoint-500/generation_config.json
[INFO|modeling_utils.py:1762] 2024-05-21 13:34:01,148 >> Model weights saved in output/dsbtpg-chatglm-6b-pt-64-2e-2/checkpoint-500/pytorch_model.bin
[INFO|tokenization_utils_base.py:2163] 2024-05-21 13:34:01,149 >> tokenizer config file saved in output/dsbtpg-chatglm-6b-pt-64-2e-2/checkpoint-500/tokenizer_config.json
[INFO|tokenization_utils_base.py:2170] 2024-05-21 13:34:01,149 >> Special tokens file saved in output/dsbtpg-chatglm-6b-pt-64-2e-2/checkpoint-500/special_tokens_map.json
{'train_runtime': 4723.6339, 'train_samples_per_second': 6.774, 'train_steps_per_second': 0.106, 'train_loss': 0.33856764221191404, 'epoch': 59.26}
100%|███████████████████████████████████████████████████████████████████████████████| 500/500 [1:18:43<00:00,  9.45s/it]
***** train metrics *****
  epoch                    =      59.26
  train_loss               =     0.3386
  train_runtime            = 1:18:43.63
  train_samples            =        540
  train_samples_per_second =      6.774
  train_steps_per_second   =      0.106

注:这里由于训练问题重新训练了,上述数据仅作为格式展示。

参考资料

[1] #ChatGLM-6B模型基于 P-Tuning v2 微调脚本参数解释 - Linux自动化运维 (linuxdevops.cn)

标签:Tuning,05,--,py,2024,v2,实训,chatglm,21
From: https://www.cnblogs.com/yichengliu0219/p/18264221

相关文章

  • [本科项目实训] 模型量化技术
    概述模型量化作为一种能够有效减少模型大小,加速深度学习推理的优化技术,主要包含8/4/2/1bit等精度设置。在8-bit低精度推理中,我们将一个原本FP32的weight/activation浮点数张量转化成一个int8/uint8张量,从而减少内存带宽和存储空间,并提高系统吞吐量降低系统时延。[2]......
  • [本科项目实训] Hugging Face Transformers 模型部署与微调
    TransformersHuggingFaceTransformer提供了模型的加载、推理、微调接口,使用该库可以轻松完成自然语言模型的部署微调工作,其有继承自AutoClass的四个最为常见的接口,且调用方式均为AutoClass.from_pretrain("model_name"):AutoTokenizer:用于文本分词AutoFeatureExtractor:用......
  • [本科项目实训] ChatGLM3 与 ChatGLM4 简述
    ChatGLM3-6B简述ChatGLM3-6B是ChatGLM系列最新一代的开源模型,在保留了前两代模型对话流畅、部署门槛低等众多优秀特性的基础上,ChatGLM3-6B引入了如下特性:更强大的基础模型:ChatGLM3-6B的基础模型ChatGLM3-6B-Base采用了更多样的训练数据、更充分的训练步数和更合理的......
  • 创新实训 (九)CodeForces 数据和微调数据处理
    Codeforces数据获取Codeforces的题目中存在一些数学公式,所以处理的时候需要比较小心的对其进行处理。首先是题面数据,在CF当中标识一道题目的方式是problemSet与problemId。其中problemSet是一个数字,而problemId是一个字母。另外需要注意的是CF题面中存在许多数学......
  • 创新实训 (十)大模型微调
    1.数据部分CodeGeeX基于ChatGLM基座语言模型,所以需要关注ChatGLM的训练数据。训练数据为jsonl格式,每一行的数据格式如下,其中chat_rounds字段是必需的,可以根据实际需求添加或删除其他字段。在本项目当中,我们更加关注的是模型的单轮对话能力,所以只需要单轮对话数据。推理......
  • 创新实训(十)——代码美化部分:导航栏的active
    代码美化部分————导航栏的active对于导航栏来说,当选定在某个功能部分时,当前模块会有高亮显示。查看main-nav.php中有管导航栏的代码<divclass="collapsenavbar-collapse"id="navbarSupportedContent"> <ulclass="navnav-pillsmain-navmr-auto"> <liclass="......
  • 【openGauss、PostgreSQL】openGauss、PostgreSQL数据库通用查表字段信息脚本-v202406
    【openGauss、PostgreSQL】openGauss、PostgreSQL数据库通用查表字段信息脚本-v20240620-2216openGauss、PostgreSQL数据库通用查表字段信息脚本-v20240620-2216openGauss、PostgreSQL数据库通用查表字段信息脚本-v20240620-2216此脚本,openGauss、PostgreSQL都可执......
  • 电影《绝地战警:生死与共》迅雷BT选择[高清版百度云下载/MKV2.88GB][中英双字资源]
    《绝地战警:生死与共》:一场华丽的动作盛宴电影《绝地战警:生死与共》是一部由导演马丁·坎贝尔执导、克里斯·塔克和杰克·切尼主演的动作喜剧片。该片于2021年上映,以其惊险刺激的动作场面和幽默风格赢得了广大观众的喜爱。 故事发生在现代繁华的洛杉矶市,克里斯·塔克......
  • 创新实训(八)——题目相关的逻辑处理解释
    题目部分题目是整个OJ系统的练习基础,无论是平时学生的练习还是比赛时的准备用题,题目系统在OJ中都是至关重要的。在controllers文件夹下,负责题目部分的代码文件分别为:problem_set.php,problem.php,problem_statistics.php,problem_data_manage.php,problem_statement_manage.php,p......
  • 创新实训(10)- 大模型服务进一步完善&邮件服务
    之前为应付中期检查简单接入了一个基础服务,并未对prompt词等做太深入的细分,为了实现更人性化的效果,我对大模型的服务进行了更进一步的完善首先是前端的效果:超级用户端:一般用户端:三个按钮分别对应AI整理格式,AI基础纠错,AI结合题目和代码详细检查错误。前两者的返回值是......