# Transformer's Trainer Memory shared Error

**URL:** <https://discuss.huggingface.co/t/transformers-trainer-memory-shared-error/129381>\
**Category:** 🤗Transformers\
**Created:** [December 5, 2024, 10:07am UTC](https://discuss.huggingface.co/t/transformers-trainer-memory-shared-error/129381 "2024-12-05T10:07:56Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [December 5, 2024, 10:21am UTC](https://discuss.huggingface.co/t/transformers-trainer-memory-shared-error/129381/2 "2024-12-05T10:21:44Z")

</div>

Perhaps same error?

> [@Transformer's trainer runtime error](https://discuss.huggingface.co/t/transformers-trainer-runtime-error/129375):
>
> I performed fine tuning flan-t5-base model using peft. here is my peft config code peft\_model = get\_peft\_model(original\_model, lora\_config).to('cuda') output\_dir = f'/kaggle/working/peft-dialogue-summary-lora-training-{str(int(time.time()))}' peft\_training\_args = TrainingArguments( output\_dir=output\_dir, per\_device\_train\_batch\_size=8, gradient\_accumulation\_steps=4, learning\_rate=1e-3, # Higher learning rate than full fine-tuning. num\_train\_epo…

Edit:

> <https://github.com/hiyouga/LLaMA-Factory/issues/3400>
>
> \### Reminder
> 
> \- \[X\] I have read the README and searched the existing issues.
> 
> \##…# Reproduction
> 
> WANDB\_DISABLED=1 NCCL\_P2P\_DISABLE=1 NCCL\_IB\_DISABLE=1 deepspeed --num\_gpus 2 --master\_port=9527 /workspace/projects/LLaMA-Factory/src/train\_bash.py \\
> --stage rm \\
> --do\_train \\
> --deepspeed xxxxxxxx/ds\_z3\_offload\_config.json \\
> --model\_name\_or\_path xxxxxxx/chatglm3-6b \\
> --adapter\_name\_or\_path /xxx/chatglm\_exp\_sft\_lora\_llamafactory \\
> --create\_new\_adapter \\
> --dataset comparison\_gpt4\_zh \\
> --dataset\_dir xxx/data \\
> --template chatglm3 \\
> --finetuning\_type lora \\
> --lora\_target query\_key\_value \\
> --output\_dir xxx/chatglm\_exp\_rm\_lora\_llamafactory \\
> --overwrite\_cache \\
> --overwrite\_output\_dir \\
> --cutoff\_len 1024 \\
> --preprocessing\_num\_workers 4 \\
> --per\_device\_train\_batch\_size 2 \\
> --per\_device\_eval\_batch\_size 1 \\
> --gradient\_accumulation\_steps 4 \\
> --lr\_scheduler\_type cosine \\
> --logging\_steps 10 \\
> --warmup\_steps 20 \\
> --save\_steps 10 \\
> --eval\_steps 20 \\
> --evaluation\_strategy steps \\
> --learning\_rate 1e-5 \\
> --num\_train\_epochs 2.0 \\
> --max\_samples 5000 \\
> --val\_size 0.1 \\
> --plot\_loss \\
> --fp16
> 可以正常训练，但是保存checkpoint时候提示如下错误：
> \[INFO|trainer.py:3305\] 2024-04-23 16:56:46,579 \>\> Saving model checkpoint to /workspace/models/huggingface/chatglm32k\_rm\_sft\_lora\_llamafactory/checkpoint-10
> \[INFO|trainer.py:3319\] 2024-04-23 16:56:46,587 \>\> Trainer.model is not a \`PreTrainedModel\`, only saving its state dict.
> Traceback (most recent call last):
> File "/workspace/projects/LLaMA-Factory/src/train\_bash.py", line 14, in \<module\>
> main()
> File "/workspace/projects/LLaMA-Factory/src/train\_bash.py", line 5, in main
> run\_exp()
> File "/workspace/projects/LLaMA-Factory/src/llmtuner/train/tuner.py", line 35, in run\_exp
> run\_rm(model\_args, data\_args, training\_args, finetuning\_args, callbacks)
> File "/workspace/projects/LLaMA-Factory/src/llmtuner/train/rm/workflow.py", line 50, in run\_rm
> train\_result = trainer.train(resume\_from\_checkpoint=training\_args.resume\_from\_checkpoint)
> File "/opt/conda/lib/python3.10/site-packages/transformers/trainer.py", line 1859, in train
> return inner\_training\_loop(
> File "/opt/conda/lib/python3.10/site-packages/transformers/trainer.py", line 2278, in \_inner\_training\_loop
> self.\_maybe\_log\_save\_evaluate(tr\_loss, grad\_norm, model, trial, epoch, ignore\_keys\_for\_eval)
> File "/opt/conda/lib/python3.10/site-packages/transformers/trainer.py", line 2673, in \_maybe\_log\_save\_evaluate
> self.\_save\_checkpoint(model, trial, metrics=metrics)
> File "/opt/conda/lib/python3.10/site-packages/transformers/trainer.py", line 2752, in \_save\_checkpoint
> self.save\_model(output\_dir, \_internal\_call=True)
> File "/opt/conda/lib/python3.10/site-packages/transformers/trainer.py", line 3239, in save\_model
> self.\_save(output\_dir, state\_dict=state\_dict)
> File "/opt/conda/lib/python3.10/site-packages/transformers/trainer.py", line 3321, in \_save
> safetensors.torch.save\_file(
> File "/opt/conda/lib/python3.10/site-packages/safetensors/torch.py", line 284, in save\_file
> serialize\_file(\_flatten(tensors), filename, metadata=metadata)
> File "/opt/conda/lib/python3.10/site-packages/safetensors/torch.py", line 480, in \_flatten
> raise RuntimeError(
> RuntimeError: 
> Some tensors share memory, this will lead to duplicate memory on disk and potential differences when loading them again: \[{'pretrained\_model.base\_model.model.lm\_head.weight', 'pretrained\_model.base\_model.model.transformer.output\_layer.weight'}\].
> A potential way to correctly save your model is to use \`save\_model\`.
> More information at https://huggingface.co/docs/safetensors/torch\_shared\_tensors
> 
> \### Expected behavior
> 
> 能够保存rm的checkpoints并顺利完成训练
> 
> \### System Info
> 
> Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points.
> 
> \- \`transformers\` version: 4.40.0
> \- Platform: Linux-5.15.0-101-generic-x86\_64-with-glibc2.31
> \- Python version: 3.10.11
> \- Huggingface\_hub version: 0.22.2
> \- Safetensors version: 0.4.3
> \- Accelerate version: 0.29.3
> \- Accelerate config: not found
> \- PyTorch version (GPU?): 2.0.1 (True)
> \- Tensorflow version (GPU?): not installed (NA)
> \- Flax version (CPU?/GPU?/TPU?): not installed (NA)
> \- Jax version: not installed
> \- JaxLib version: not installed
> \- Using GPU in script?: \<fill in\>
> \- Using distributed or parallel set-up in script?: \<fill in\>
> 
> \### Others
> 
> 无

```auto
--save_safetensors False

```

---

_[View the full topic](https://discuss.huggingface.co/t/transformers-trainer-memory-shared-error/129381)._
