-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17145503484199.html
1310 lines (1209 loc) · 84.6 KB
/
17145503484199.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
复现LoReFT(VCLab) - Prepare for the FUTURE
</title>
<link href="atom.xml" rel="alternate" title="Prepare for the FUTURE" type="application/atom+xml">
<link rel="stylesheet" href="asset/css/style.min.css">
<link rel="stylesheet" href="asset/css/doc.css">
<script src="asset/app.js"></script>
</head>
<body>
<section class="hero">
<div class="hero-head">
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="container">
<div class="navbar-brand">
<a target="_self" class="navbar-item " href="index.html">Home</a>
<a target="_self" class="navbar-item " href="archives.html">Archives</a>
<a role="button" id="navbarSNSRssSwitchBtn" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navbarSNSRssButtons">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbarSNSRssButtons" class="navbar-menu">
<div class="navbar-start">
</div>
<div class="navbar-end">
<div class="navbar-item">
<!--buttons start-->
<div class="buttons">
<a href="atom.xml" target="_blank" title="RSS">
<span class="icon is-large has-text-black-bis">
<svg class="svg-inline--fa fa-rss fa-w-14 fa-lg" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="rss" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" data-fa-i2svg=""><path fill="currentColor" d="M128.081 415.959c0 35.369-28.672 64.041-64.041 64.041S0 451.328 0 415.959s28.672-64.041 64.041-64.041 64.04 28.673 64.04 64.041zm175.66 47.25c-8.354-154.6-132.185-278.587-286.95-286.95C7.656 175.765 0 183.105 0 192.253v48.069c0 8.415 6.49 15.472 14.887 16.018 111.832 7.284 201.473 96.702 208.772 208.772.547 8.397 7.604 14.887 16.018 14.887h48.069c9.149.001 16.489-7.655 15.995-16.79zm144.249.288C439.596 229.677 251.465 40.445 16.503 32.01 7.473 31.686 0 38.981 0 48.016v48.068c0 8.625 6.835 15.645 15.453 15.999 191.179 7.839 344.627 161.316 352.465 352.465.353 8.618 7.373 15.453 15.999 15.453h48.068c9.034-.001 16.329-7.474 16.005-16.504z"></path></svg><!-- <i class="fas fa-rss fa-lg"></i> -->
</span>
</a>
</div>
<!--buttons end-->
</div>
</div>
</div>
</div>
</nav>
</div>
<div class="hero-body ct-body"></div>
</section>
<section class="ct-body">
<div class="container">
<div class="columns is-variable bd-klmn-columns is-4 is-centered">
<div class="column is-four-fifths">
<div class="post-body single-content">
<h1 class="title">
复现LoReFT(VCLab)
</h1>
<div class="media">
<div class="media-content">
<div class="content">
<p>
<span class="date">2024/05/01</span>
<br />
<span class="tran-tags">Tags:</span>
<a class="tag is-link is-light" href='tag_Llama3%20ReFTEng%20vs%20PEFT.html'>#Llama3 ReFTEng vs PEFT</a>
</p>
</div>
</div>
</div>
</div>
<article class="markdown-body single-content">
<h2><a id="1-prepare" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>1 Prepare</h2>
<p>选择在VCLab实验室的主机上进行复现,因此首先利用conda进行虚拟环境构建。</p>
<pre><code class="language-shell"># 激活conda
source .bashrc
# 新建名为"LoReFT"的conda环境,由于pyreft的setup.py中要求python_requires='>=3.8',因此设置python版本为3.8
conda create -n "LoReFT" python=3.8
# 进入该conda环境
conda activate LoReFT
</code></pre>
<p><br />
在进入conda虚拟环境后,首先安装torch。观察到在<code>pyreft/requirements.txt</code>中要求<code>torch>=2.0.0</code>,鉴于本实验室的cuda版本为11.7,因此采用<a href="https://pytorch.org/get-started/previous-versions/" title="torch">以下命令</a>进行安装2.0.0版本的torch:</p>
<pre><code class="language-shell"># CUDA 11.7
pip install torch==2.0.0 torchvision==0.15.1 torchaudio==2.0.1
</code></pre>
<p><br />
接着,用<code>pip install git+https://github.com/stanfordnlp/pyreft.git</code>安装<code>pyreft</code>,然而由于网络问题,报错如下:</p>
<pre><code class="language-shell">Collecting git+https://github.com/stanfordnlp/pyreft.git
Cloning https://github.com/stanfordnlp/pyreft.git to /tmp/pip-req-build-eeva9wo9
Running command git clone --filter=blob:none --quiet https://github.com/stanfordnlp/pyreft.git /tmp/pip-req-build-eeva9wo9
error: RPC failed; curl 28 Failed to connect to github.com port 443: Connection timed out
fatal: the remote end hung up unexpectedly
error: subprocess-exited-with-error
× git clone --filter=blob:none --quiet https://github.com/stanfordnlp/pyreft.git /tmp/pip-req-build-eeva9wo9 did not run successfully.
│ exit code: 128
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× git clone --filter=blob:none --quiet https://github.com/stanfordnlp/pyreft.git /tmp/pip-req-build-eeva9wo9 did not run successfully.
│ exit code: 128
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
</code></pre>
<p><br />
因此我们采用两步的安装方式。如下所示:</p>
<pre><code class="language-shell"># 首先下载pyreft的包
git clone https://github.com/stanfordnlp/pyreft.git
# 在解压后的包内完成安装
cd pyreft
python setup.py install
</code></pre>
<p><br />
但是会报错,根据错误查看(例如要求numpy>=1.26.4),发现应该将python版本设为3.9。因此删除该虚拟环境,重新安装新的虚拟环境。</p>
<pre><code class="language-shell"># 退出当前虚拟环境
conda deactivate
# 删除虚拟环境
conda env remove -p LoReFT_path
# 新建虚拟环境
conda create -n "ReFT" python=3.9
# 进入虚拟环境
conda activate ReFT
# 安装torch
/home/workspace/nanyang/anaconda3/envs/ReFT/bin/pip install torch==2.0.0 torchvision==0.15.1 torchaudio==2.0.1
# 安装pyreft
/home/workspace/nanyang/anaconda3/envs/ReFT/bin/pip install pyreft
</code></pre>
<p><br />
检查当前虚拟环境下的包:</p>
<pre><code class="language-shell">(ReFT) nanyang@vclab-gpuserver-57:~$ conda list
# packages in environment at /home/workspace/nanyang/anaconda3/envs/ReFT:
#
# Name Version Build Channel
_libgcc_mutex 0.1 conda_forge https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
_openmp_mutex 4.5 2_kmp_llvm https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
accelerate 0.29.3 <pip>
aiohttp 3.9.5 <pip>
aiosignal 1.3.1 <pip>
annotated-types 0.6.0 <pip>
anyio 4.3.0 <pip>
appdirs 1.4.4 <pip>
argon2-cffi 23.1.0 <pip>
argon2-cffi-bindings 21.2.0 <pip>
arrow 1.3.0 <pip>
asttokens 2.4.1 <pip>
async-lru 2.0.4 <pip>
async-timeout 4.0.3 <pip>
attrs 23.2.0 <pip>
Babel 2.14.0 <pip>
beautifulsoup4 4.12.3 <pip>
bleach 6.1.0 <pip>
ca-certificates 2024.3.11 h06a4308_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
cachetools 5.3.3 <pip>
certifi 2024.2.2 <pip>
cffi 1.16.0 <pip>
charset-normalizer 3.3.2 <pip>
click 8.1.7 <pip>
cmake 3.29.2 <pip>
comm 0.2.2 <pip>
contourpy 1.2.1 <pip>
cycler 0.12.1 <pip>
dacite 1.8.1 <pip>
datasets 2.18.0 <pip>
debugpy 1.8.1 <pip>
decorator 5.1.1 <pip>
defusedxml 0.7.1 <pip>
dill 0.3.8 <pip>
docker-pycreds 0.4.0 <pip>
evaluate 0.4.2 <pip>
exceptiongroup 1.2.1 <pip>
executing 2.0.1 <pip>
fastjsonschema 2.19.1 <pip>
filelock 3.14.0 <pip>
fonttools 4.51.0 <pip>
fqdn 1.5.1 <pip>
frozenlist 1.4.1 <pip>
fsspec 2024.2.0 <pip>
gcsfs 2024.2.0 <pip>
gitdb 4.0.11 <pip>
GitPython 3.1.43 <pip>
google-api-core 2.19.0 <pip>
google-auth 2.29.0 <pip>
google-auth-oauthlib 1.2.0 <pip>
google-cloud-core 2.4.1 <pip>
google-cloud-storage 2.16.0 <pip>
google-crc32c 1.5.0 <pip>
google-resumable-media 2.7.0 <pip>
googleapis-common-protos 1.63.0 <pip>
h11 0.14.0 <pip>
htmlmin 0.1.12 <pip>
httpcore 1.0.5 <pip>
httpx 0.27.0 <pip>
huggingface-hub 0.20.3 <pip>
idna 3.7 <pip>
ImageHash 4.3.1 <pip>
importlib_metadata 7.1.0 <pip>
importlib_resources 6.4.0 <pip>
ipykernel 6.29.4 <pip>
ipython 8.18.1 <pip>
ipywidgets 8.1.2 <pip>
isoduration 20.11.0 <pip>
jedi 0.19.1 <pip>
Jinja2 3.1.3 <pip>
joblib 1.4.0 <pip>
json5 0.9.25 <pip>
jsonpointer 2.4 <pip>
jsonschema 4.22.0 <pip>
jsonschema-specifications 2023.12.1 <pip>
jupyter 1.0.0 <pip>
jupyter-console 6.6.3 <pip>
jupyter-events 0.10.0 <pip>
jupyter-lsp 2.2.5 <pip>
jupyter_client 8.6.1 <pip>
jupyter_core 5.7.2 <pip>
jupyter_server 2.14.0 <pip>
jupyter_server_terminals 0.5.3 <pip>
jupyterlab 4.1.8 <pip>
jupyterlab_pygments 0.3.0 <pip>
jupyterlab_server 2.27.1 <pip>
jupyterlab_widgets 3.0.10 <pip>
kiwisolver 1.4.5 <pip>
ld_impl_linux-64 2.38 h1181459_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libffi 3.4.4 h6a678d5_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libgcc-ng 12.2.0 h65d4601_19 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libstdcxx-ng 12.2.0 h46fd767_19 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
lit 18.1.4 <pip>
llvm-openmp 14.0.6 h9e868ea_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
llvmlite 0.42.0 <pip>
MarkupSafe 2.1.5 <pip>
matplotlib 3.8.4 <pip>
matplotlib-inline 0.1.7 <pip>
mistune 3.0.2 <pip>
mizani 0.11.2 <pip>
mpmath 1.3.0 <pip>
multidict 6.0.5 <pip>
multimethod 1.11.2 <pip>
multiprocess 0.70.16 <pip>
nbclient 0.10.0 <pip>
nbconvert 7.16.4 <pip>
nbformat 5.10.4 <pip>
ncurses 6.4 h6a678d5_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
nest-asyncio 1.6.0 <pip>
networkx 3.2.1 <pip>
notebook 7.1.3 <pip>
notebook_shim 0.2.4 <pip>
numba 0.59.1 <pip>
numpy 1.26.4 <pip>
nvidia-cublas-cu11 11.10.3.66 <pip>
nvidia-cuda-cupti-cu11 11.7.101 <pip>
nvidia-cuda-nvrtc-cu11 11.7.99 <pip>
nvidia-cuda-runtime-cu11 11.7.99 <pip>
nvidia-cudnn-cu11 8.5.0.96 <pip>
nvidia-cufft-cu11 10.9.0.58 <pip>
nvidia-curand-cu11 10.2.10.91 <pip>
nvidia-cusolver-cu11 11.4.0.1 <pip>
nvidia-cusparse-cu11 11.7.4.91 <pip>
nvidia-nccl-cu11 2.14.3 <pip>
nvidia-nvtx-cu11 11.7.91 <pip>
oauthlib 3.2.2 <pip>
openssl 3.0.13 h7f8727e_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
overrides 7.7.0 <pip>
packaging 24.0 <pip>
pandas 2.2.2 <pip>
pandocfilters 1.5.1 <pip>
parso 0.8.4 <pip>
patsy 0.5.6 <pip>
pexpect 4.9.0 <pip>
phik 0.12.4 <pip>
pillow 10.3.0 <pip>
pip 23.3.1 py39h06a4308_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
platformdirs 4.2.1 <pip>
plotnine 0.13.5 <pip>
prometheus_client 0.20.0 <pip>
prompt-toolkit 3.0.43 <pip>
proto-plus 1.23.0 <pip>
protobuf 4.25.3 <pip>
psutil 5.9.8 <pip>
ptyprocess 0.7.0 <pip>
pure-eval 0.2.2 <pip>
pyarrow 16.0.0 <pip>
pyarrow-hotfix 0.6 <pip>
pyasn1 0.6.0 <pip>
pyasn1_modules 0.4.0 <pip>
pycparser 2.22 <pip>
pydantic 2.7.1 <pip>
pydantic_core 2.18.2 <pip>
Pygments 2.17.2 <pip>
pyparsing 3.1.2 <pip>
pyreft 0.0.5 <pip>
python 3.9.19 h955ad1f_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
python-dateutil 2.9.0.post0 <pip>
python-json-logger 2.0.7 <pip>
pytz 2024.1 <pip>
pyvene 0.1.1 <pip>
PyWavelets 1.6.0 <pip>
PyYAML 6.0.1 <pip>
pyzmq 26.0.2 <pip>
qtconsole 5.5.1 <pip>
QtPy 2.4.1 <pip>
readline 8.2 h5eee18b_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
referencing 0.35.0 <pip>
regex 2024.4.28 <pip>
requests 2.31.0 <pip>
requests-oauthlib 2.0.0 <pip>
rfc3339-validator 0.1.4 <pip>
rfc3986-validator 0.1.1 <pip>
rpds-py 0.18.0 <pip>
rsa 4.9 <pip>
safetensors 0.4.3 <pip>
scikit-learn 1.4.2 <pip>
scipy 1.11.4 <pip>
seaborn 0.12.2 <pip>
Send2Trash 1.8.3 <pip>
sentencepiece 0.2.0 <pip>
sentry-sdk 2.0.1 <pip>
setproctitle 1.3.3 <pip>
setuptools 68.2.2 py39h06a4308_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
six 1.16.0 <pip>
smmap 5.0.1 <pip>
sniffio 1.3.1 <pip>
soupsieve 2.5 <pip>
sqlite 3.45.3 h5eee18b_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
stack-data 0.6.3 <pip>
statsmodels 0.14.2 <pip>
sympy 1.12 <pip>
terminado 0.18.1 <pip>
threadpoolctl 3.5.0 <pip>
tinycss2 1.3.0 <pip>
tk 8.6.12 h1ccaba5_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
tokenizers 0.19.1 <pip>
tomli 2.0.1 <pip>
torch 2.0.0 <pip>
torchaudio 2.0.1 <pip>
torchvision 0.15.1 <pip>
tornado 6.4 <pip>
tqdm 4.66.2 <pip>
traitlets 5.14.3 <pip>
transformers 4.40.1 <pip>
triton 2.0.0 <pip>
typeguard 4.2.1 <pip>
types-python-dateutil 2.9.0.20240316 <pip>
typing_extensions 4.11.0 <pip>
tzdata 2024a h04d1e81_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
tzdata 2024.1 <pip>
uri-template 1.3.0 <pip>
urllib3 2.2.1 <pip>
visions 0.7.6 <pip>
wandb 0.16.6 <pip>
wcwidth 0.2.13 <pip>
webcolors 1.13 <pip>
webencodings 0.5.1 <pip>
websocket-client 1.8.0 <pip>
wheel 0.41.2 py39h06a4308_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
widgetsnbextension 4.0.10 <pip>
wordcloud 1.9.3 <pip>
xxhash 3.4.1 <pip>
xz 5.4.6 h5eee18b_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
yarl 1.9.4 <pip>
ydata-profiling 4.7.0 <pip>
zipp 3.18.1 <pip>
zlib 1.2.13 h5eee18b_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
</code></pre>
<h2><a id="2-reproduction" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>2 Reproduction</h2>
<p>首先通过git命令下载pyreft源码:</p>
<pre><code class="language-shell">git clone https://github.com/stanfordnlp/pyreft.git
</code></pre>
<h3><a id="2-1-data-creation" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>2.1 Data Creation</h3>
<p>进入到LoReFT的文件夹中,并通过命令行生成所需要的数据:</p>
<pre><code class="language-shell">cd examples/loreft
bash load_datasets.sh
</code></pre>
<p><br />
接着观察其<code>train.py</code>,由于我们需要测试llama3-8b的base模型和instruct模型,因此在model_name处做修改:</p>
<pre><code class="language-python"># load tokenizer
if "Meta-Llama-3-8B" in model_name:
tokenizer = AutoTokenizer.from_pretrained(
"meta-llama/Meta-Llama-3-8B", # use instruct for the template.
model_max_length=max_length,
padding_side="right",
use_fast=False,
)
elif "Meta-Llama-3-8B-Instruct" in model_name:
tokenizer = AutoTokenizer.from_pretrained(
"meta-llama/Meta-Llama-3-8B-Instruct", # use instruct for the template.
model_max_length=max_length,
padding_side="right",
use_fast=False,
)
else:
tokenizer = AutoTokenizer.from_pretrained(
model_name,
model_max_length=max_length,
padding_side="right",
use_fast=False,
)
</code></pre>
<p><br />
接着通过<code>nvidia-smi</code>命令查看未使用的显卡,并开始训练:</p>
<pre><code class="language-shell">CUDA_VISIBLE_DIVICES=1 python train.py -task commonsense \
-data_dir dataset \
-model Meta-Llama-3-8B \
-seed 42 \
-l all -r 8 -p f7+l7 -e 6 -lr 9e-4 \
-type LoreftIntervention \
-gradient_accumulation_steps 2 \
-batch_size 16 \
-eval_batch_size 4 \
--dropout 0.00 \
--test_split test \
--use_normalized_template \
--share_weights \
--warmup_ratio 0.1 \
--greedy_decoding
</code></pre>
<p><br />
报错如下:</p>
<pre><code class="language-shell">task: commonsense, model: Meta-Llama-3-8B, intervention_type: LoreftIntervention, layers: all, rank: 8, position: f7+l7, epoch: 6, train_on_inputs: False, max_length: 512, allow_cls_grad: False
Traceback (most recent call last):
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/urllib3/connection.py", line 198, in _new_conn
sock = connection.create_connection(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/urllib3/util/connection.py", line 85, in create_connection
raise err
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/urllib3/util/connection.py", line 73, in create_connection
sock.connect(sa)
socket.timeout: timed out
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/urllib3/connectionpool.py", line 793, in urlopen
response = self._make_request(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/urllib3/connectionpool.py", line 491, in _make_request
raise new_e
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/urllib3/connectionpool.py", line 467, in _make_request
self._validate_conn(conn)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1099, in _validate_conn
conn.connect()
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/urllib3/connection.py", line 616, in connect
self.sock = sock = self._new_conn()
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/urllib3/connection.py", line 207, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x7f65ec50d5e0>, 'Connection to huggingface.co timed out. (connect timeout=10)')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/requests/adapters.py", line 486, in send
resp = conn.urlopen(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/urllib3/connectionpool.py", line 847, in urlopen
retries = retries.increment(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/urllib3/util/retry.py", line 515, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /Meta-Llama-3-8B/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f65ec50d5e0>, 'Connection to huggingface.co timed out. (connect timeout=10)'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 1238, in hf_hub_download
metadata = get_hf_file_metadata(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
return fn(*args, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 1631, in get_hf_file_metadata
r = _request_wrapper(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 385, in _request_wrapper
response = _request_wrapper(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 408, in _request_wrapper
response = get_session().request(method=method, url=url, **params)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/utils/_http.py", line 67, in send
return super().send(request, *args, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/requests/adapters.py", line 507, in send
raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: (MaxRetryError("HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /Meta-Llama-3-8B/resolve/main/config.json (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f65ec50d5e0>, 'Connection to huggingface.co timed out. (connect timeout=10)'))"), '(Request ID: 4aa9cce0-b0ea-43ed-ab01-d537e90a1652)')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/utils/hub.py", line 398, in cached_file
resolved_file = hf_hub_download(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
return fn(*args, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 1371, in hf_hub_download
raise LocalEntryNotFoundError(
huggingface_hub.utils._errors.LocalEntryNotFoundError: An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/workspace/nanyang/pyreft/examples/loreft/train.py", line 494, in <module>
main()
File "/home/workspace/nanyang/pyreft/examples/loreft/train.py", line 490, in main
finetune(**vars(args), args=args)
File "/home/workspace/nanyang/pyreft/examples/loreft/train.py", line 147, in finetune
temp_config = AutoConfig.from_pretrained(model)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/models/auto/configuration_auto.py", line 928, in from_pretrained
config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/configuration_utils.py", line 631, in get_config_dict
config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/configuration_utils.py", line 686, in _get_config_dict
resolved_config_file = cached_file(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/utils/hub.py", line 441, in cached_file
raise EnvironmentError(
OSError: We couldn't connect to 'https://huggingface.co' to load this file, couldn't find it in the cached files and it looks like Meta-Llama-3-8B is not the path to a directory containing a file named config.json.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.
</code></pre>
<p><br />
起初以为是预训练模型路径不对,在用了默认的预训练模型<code>yahma/llama-7b-hf</code>后同样产生这样的报错,因而将问题定位在网络连接上。应用群里的改变HF环境变量如下:</p>
<pre><code class="language-shell"># in .bashrc
# >>> hugging face init >>>
export HF_DATASETS_CACHE=/home/share/nanyang/HuggingFace/.catch
export HF_CACHE_DIR=/home/share/nanyang/HuggingFace/.catch
export HF_HOME=/home/share/nanyang/HuggingFace/.catch/huggingface
export HF_HUB_CACHE=/home/share/nanyang/HuggingFace/.catch/huggingface/hub
export HF_ENDPOINT=https://hf-mirror.com
export HF_TOKEN=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
# <<< hugging face init <<<
</code></pre>
<p><br />
在<code>source .bashrc</code>后,运行<code>train.py</code>,报错如下:</p>
<pre><code class="language-shell">task: commonsense, model: Meta-Llama-3-8B, intervention_type: LoreftIntervention, layers: all, rank: 8, position: f7+l7, epoch: 6, train_on_inputs: False, max_length: 512, allow_cls_grad: False
Traceback (most recent call last):
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/utils/_errors.py", line 286, in hf_raise_for_status
response.raise_for_status()
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://hf-mirror.com/Meta-Llama-3-8B/resolve/main/config.json
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/utils/hub.py", line 398, in cached_file
resolved_file = hf_hub_download(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
return fn(*args, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 1368, in hf_hub_download
raise head_call_error
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 1238, in hf_hub_download
metadata = get_hf_file_metadata(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
return fn(*args, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 1631, in get_hf_file_metadata
r = _request_wrapper(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 385, in _request_wrapper
response = _request_wrapper(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/file_download.py", line 409, in _request_wrapper
hf_raise_for_status(response)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/huggingface_hub/utils/_errors.py", line 323, in hf_raise_for_status
raise RepositoryNotFoundError(message, response) from e
huggingface_hub.utils._errors.RepositoryNotFoundError: 404 Client Error. (Request ID: Root=1-663247eb-195d3af1450531d11c40c61c;7306600f-6215-45e4-a6c4-a9aa32ddcd73)
Repository Not Found for url: https://hf-mirror.com/Meta-Llama-3-8B/resolve/main/config.json.
Please make sure you specified the correct `repo_id` and `repo_type`.
If you are trying to access a private or gated repo, make sure you are authenticated.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/workspace/nanyang/pyreft/examples/loreft/train.py", line 494, in <module>
main()
File "/home/workspace/nanyang/pyreft/examples/loreft/train.py", line 490, in main
finetune(**vars(args), args=args)
File "/home/workspace/nanyang/pyreft/examples/loreft/train.py", line 147, in finetune
temp_config = AutoConfig.from_pretrained(model)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/models/auto/configuration_auto.py", line 928, in from_pretrained
config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/configuration_utils.py", line 631, in get_config_dict
config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/configuration_utils.py", line 686, in _get_config_dict
resolved_config_file = cached_file(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/utils/hub.py", line 421, in cached_file
raise EnvironmentError(
OSError: Meta-Llama-3-8B is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'
If this is a private repository, make sure to pass a token having permission to this repo either by logging in with `huggingface-cli login` or by passing `token=<your_token>`
</code></pre>
<p><br />
可以看到错误是源于<code>Repository Not Found for url: https://hf-mirror.com/Meta-Llama-3-8B/resolve/main/config.json.</code>,而实际上他的位置应该是<code>https://hf-mirror.com/meta-llama/Meta-Llama-3-8B/resolve/main/config.json.</code> 思考可能是因为调成镜像网站后,有些数据集的路径对不上,因此做以下两点改动:</p>
<ul>
<li>在.bashrc中将<code>export HF_ENDPOINT=https://hf-mirror.com</code>改为<code>export HF_ENDPOINT=https://hf-mirror.com/meta-llama</code>;</li>
<li>在<code>train.py</code>中作如下修改:</li>
</ul>
<pre><code class="language-python"># 原始代码
if "Meta-Llama-3-8B" in model_name:
tokenizer = AutoTokenizer.from_pretrained(
"meta-llama/Meta-Llama-3-8B", # use instruct for the template.
model_max_length=max_length,
padding_side="right",
use_fast=False,
)
elif "Meta-Llama-3-8B-Instruct" in model_name:
tokenizer = AutoTokenizer.from_pretrained(
"meta-llama/Meta-Llama-3-8B-Instruct", # use instruct for the template.
model_max_length=max_length,
padding_side="right",
use_fast=False,
)
else:
tokenizer = AutoTokenizer.from_pretrained(
model_name,
model_max_length=max_length,
padding_side="right",
use_fast=False,
)
# 修改后代码
tokenizer = AutoTokenizer.from_pretrained(
model_name,
model_max_length=max_length,
padding_side="right",
use_fast=False,
)
</code></pre>
<p>经过该改动后,数据集被成功加载如下(以Meta-Llama-3-8B-Instruct为例):</p>
<pre><code class="language-shell">(ReFT) nanyang@vclab-gpuserver-57:/home/workspace/nanyang/pyreft/examples/loreft$ CUDA_VISIBLE_DIVICES=1 python train.py -task commonsense \
> -data_dir dataset \
> -model Meta-Llama-3-8B-Instruct \
> -seed 42 \
> -l all -r 8 -p f7+l7 -e 6 -lr 9e-4 \
> -type LoreftIntervention \
> -gradient_accumulation_steps 2 \
> -batch_size 16 \
> -eval_batch_size 4 \
> --dropout 0.00 \
> --test_split test \
> --use_normalized_template \
> --share_weights \
> --warmup_ratio 0.1 \
> --greedy_decoding
task: commonsense, model: Meta-Llama-3-8B-Instruct, intervention_type: LoreftIntervention, layers: all, rank: 8, position: f7+l7, epoch: 6, train_on_inputs: False, max_length: 512, allow_cls_grad: False
config.json: 654B [00:00, 56.6kB/s]
tokenizer_config.json: 50.6kB [00:00, 4.04MB/s]
tokenizer.json: 9.09MB [00:11, 777kB/s]
special_tokens_map.json: 100%|███████████████████████████████████| 73.0/73.0 [00:00<00:00, 6.54kB/s]
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
adding a special padding token...
{'num_interventions': 32, 'position': 'f7+l7', 'share_weights': True, 'test_split': 'test'}
loading data for dataset: dataset/commonsense_170k/train.json
100%|██████████████████████████████████████████████████████| 170420/170420 [03:21<00:00, 845.06it/s]
{'num_interventions': 32, 'position': 'f7+l7', 'share_weights': True}
loading data for dataset: dataset/boolq/test.json
100%|█████████████████████████████████████████████████████████| 3270/3270 [00:01<00:00, 2315.61it/s]
{'num_interventions': 32, 'position': 'f7+l7', 'share_weights': True}
loading data for dataset: dataset/piqa/test.json
100%|█████████████████████████████████████████████████████████| 1838/1838 [00:01<00:00, 1724.39it/s]
{'num_interventions': 32, 'position': 'f7+l7', 'share_weights': True}
loading data for dataset: dataset/social_i_qa/test.json
100%|█████████████████████████████████████████████████████████| 1954/1954 [00:01<00:00, 1831.40it/s]
{'num_interventions': 32, 'position': 'f7+l7', 'share_weights': True}
loading data for dataset: dataset/hellaswag/test.json
100%|████████████████████████████████████████████████████████| 10042/10042 [00:11<00:00, 875.58it/s]
{'num_interventions': 32, 'position': 'f7+l7', 'share_weights': True}
loading data for dataset: dataset/winogrande/test.json
100%|█████████████████████████████████████████████████████████| 1267/1267 [00:00<00:00, 1925.84it/s]
{'num_interventions': 32, 'position': 'f7+l7', 'share_weights': True}
loading data for dataset: dataset/ARC-Easy/test.json
100%|█████████████████████████████████████████████████████████| 2376/2376 [00:01<00:00, 1730.06it/s]
{'num_interventions': 32, 'position': 'f7+l7', 'share_weights': True}
loading data for dataset: dataset/ARC-Challenge/test.json
100%|█████████████████████████████████████████████████████████| 1172/1172 [00:00<00:00, 1622.61it/s]
{'num_interventions': 32, 'position': 'f7+l7', 'share_weights': True}
loading data for dataset: dataset/openbookqa/test.json
100%|███████████████████████████████████████████████████████████| 500/500 [00:00<00:00, 1803.62it/s]
model.safetensors.index.json: 23.9kB [00:00, 1.84MB/s]
model-00001-of-00004.safetensors: 100%|████████████████████████| 4.98G/4.98G [01:24<00:00, 59.1MB/s]
model-00002-of-00004.safetensors: 100%|████████████████████████| 5.00G/5.00G [01:26<00:00, 58.1MB/s]
model-00003-of-00004.safetensors: 100%|████████████████████████| 4.92G/4.92G [01:29<00:00, 54.9MB/s]
model-00004-of-00004.safetensors: 100%|████████████████████████| 1.17G/1.17G [00:18<00:00, 63.3MB/s]
Downloading shards: 100%|█████████████████████████████████████████████| 4/4 [04:40<00:00, 70.08s/it]
Loading checkpoint shards: 100%|██████████████████████████████████████| 4/4 [00:13<00:00, 3.50s/it]
generation_config.json: 100%|██████████████████████████████████████| 187/187 [00:00<00:00, 17.5kB/s]
trainable intervention params: 2,097,408 || trainable model params: 0
model params: 8,030,269,440 || trainable%: 0.0261187749137344
</code></pre>
<p><br />
然而又有新问题:</p>
<pre><code class="language-shell">huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...
To disable this warning, you can either:
- Avoid using `tokenizers` before the fork if possible
- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)
Detected kernel version 5.4.0, which is below the recommended minimum of 5.5.0; this can cause the process to hang. It is recommended to upgrade the kernel to the minimum version or higher.
0%| | 0/3996 [00:00<?, ?it/s]Traceback (most recent call last):
File "/home/workspace/nanyang/pyreft/examples/loreft/train.py", line 494, in <module>
main()
File "/home/workspace/nanyang/pyreft/examples/loreft/train.py", line 490, in main
finetune(**vars(args), args=args)
File "/home/workspace/nanyang/pyreft/examples/loreft/train.py", line 389, in finetune
trainer.train()
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/trainer.py", line 1859, in train
return inner_training_loop(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/trainer.py", line 2203, in _inner_training_loop
tr_loss_step = self.training_step(model, inputs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/trainer.py", line 3130, in training_step
model.train()
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/torch/nn/modules/module.py", line 2288, in train
module.train(mode)
TypeError: train() takes 1 positional argument but 2 were given
0%| | 0/3996 [00:02<?, ?it/s]
</code></pre>
<p><br />
在<a href="https://github.com/stanfordnlp/pyreft/issues/31" title="link-1">link-1</a>中得到答案,命令行未识别到<code>CUDA_VISIBLE_DIVICES=1</code>,需要先将其export:</p>
<pre><code class="language-shell">export CUDA_VISIBLE_DIVICES=1 python train.py -task commonsense \
-data_dir dataset \
-model Meta-Llama-3-8B \
-seed 42 \
-l all -r 8 -p f7+l7 -e 6 -lr 9e-4 \
-type LoreftIntervention \
-gradient_accumulation_steps 2 \
-batch_size 16 \
-eval_batch_size 4 \
--dropout 0.00 \
--test_split test \
--use_normalized_template \
--share_weights \
--warmup_ratio 0.1 \
--greedy_decoding
</code></pre>
<p><br />
然而又遇到问题:显示<code>triu_tril_cuda_template</code>模版并不适配<code>BFloat16</code>。</p>
<pre><code class="language-shell">huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...
To disable this warning, you can either:
- Avoid using `tokenizers` before the fork if possible
- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)
Detected kernel version 5.4.0, which is below the recommended minimum of 5.5.0; this can cause the process to hang. It is recommended to upgrade the kernel to the minimum version or higher.
0%| | 0/31956 [00:00<?, ?it/s]Traceback (most recent call last):
File "/home/workspace/nanyang/pyreft/examples/loreft/train.py", line 494, in <module>
main()
File "/home/workspace/nanyang/pyreft/examples/loreft/train.py", line 490, in main
finetune(**vars(args), args=args)
File "/home/workspace/nanyang/pyreft/examples/loreft/train.py", line 389, in finetune
trainer.train()
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/trainer.py", line 1859, in train
return inner_training_loop(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/trainer.py", line 2203, in _inner_training_loop
tr_loss_step = self.training_step(model, inputs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/trainer.py", line 3138, in training_step
loss = self.compute_loss(model, inputs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/pyreft/reft_trainer.py", line 82, in compute_loss
_, cf_outputs = intervenable(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/pyvene/models/intervenable_base.py", line 1460, in forward
raise e
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/pyvene/models/intervenable_base.py", line 1443, in forward
counterfactual_outputs = self.model(**base, labels=labels)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/models/llama/modeling_llama.py", line 1208, in forward
outputs = self.model(
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/models/llama/modeling_llama.py", line 992, in forward
causal_mask = self._update_causal_mask(attention_mask, inputs_embeds, cache_position, past_seen_tokens)
File "/home/workspace/nanyang/anaconda3/envs/ReFT/lib/python3.9/site-packages/transformers/models/llama/modeling_llama.py", line 1095, in _update_causal_mask
causal_mask = torch.triu(causal_mask, diagonal=1)
RuntimeError: "triu_tril_cuda_template" not implemented for 'BFloat16'
0%| | 0/31956 [00:02<?, ?it/s]
</code></pre>
<p><br />
在<a href="https://www.zhihu.com/question/622711856/answer/3339303390" title="link-2">link-2</a>上找到答案:</p>
<ul>
<li>需要将torch版本升级为2.1.0;</li>
<li>将BFloat修改为half tensor。(可能对精度会造成影响)</li>
</ul>
<p>因此首先要考虑的是升级torch版本,然而发现目前实验室服务器的3090显卡最高只支持cuda11.7的版本,而2.1.0的torch支持的最低cuda版本为11.8,<del>因此考虑第二种做法。</del></p>
<blockquote>
<p>发现实验室另一个服务器上最高支持12.4版本的CUDA!火速找管理员申请账号ing...<br />
ok,管理员不让多个账号,那我只好先用用学长的了...(小气管理员一枚哈哈哈哈哈哈哈哈哈哈哈)</p>
</blockquote>
<hr />
<p>然而情况并没有那么顺利:我用学长的账号死活无法连接到对应的服务器:</p>
<ul>
<li>
<p>对于工位的主机:终端连接一次成功;vscode无法连接(显示超时)</p>
</li>
<li>
<p>对于自己的笔记本电脑:终端、vscode均无法连接(超时)</p>
</li>
</ul>
<p>最终在<a href="https://www.zhihu.com/question/622711856/answer/3339303390" title="link-2">link-2</a>上找到答案:其实可以在nvidia-smi显示的cuda版本为11.7的显卡上,在conda环境中安装cuda为11.8版本对应的pytorch。因此考虑重新配一个环境:</p>
<pre><code class="language-shell">conda create -n "reft" python=3.9
conda activate reft
/home/workspace/nanyang/anaconda3/envs/reft/bin/pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu118
</code></pre>
<p><br />
经过一下测试,表明torch安装成功,并且可以使用cuda:</p>
<pre><code class="language-shell">python
Python 3.9.19 (main, Mar 21 2024, 17:11:28)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True
</code></pre>
<p><br />
接着安装<code>pyreft</code>:</p>
<pre><code class="language-shell">/home/workspace/nanyang/anaconda3/envs/reft/bin/pip install pyreft
</code></pre>
<p><br />
查看当前情况下虚拟环境安装的包:</p>
<pre><code class="language-shell">conda list
# packages in environment at /home/workspace/nanyang/anaconda3/envs/reft:
#
# Name Version Build Channel
_libgcc_mutex 0.1 conda_forge https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
_openmp_mutex 4.5 2_kmp_llvm https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
accelerate 0.29.3 <pip>
aiohttp 3.9.5 <pip>
aiosignal 1.3.1 <pip>
annotated-types 0.6.0 <pip>
anyio 4.3.0 <pip>
appdirs 1.4.4 <pip>
argon2-cffi 23.1.0 <pip>
argon2-cffi-bindings 21.2.0 <pip>
arrow 1.3.0 <pip>
asttokens 2.4.1 <pip>
async-lru 2.0.4 <pip>
async-timeout 4.0.3 <pip>
attrs 23.2.0 <pip>
Babel 2.14.0 <pip>
beautifulsoup4 4.12.3 <pip>
bleach 6.1.0 <pip>
ca-certificates 2024.3.11 h06a4308_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
cachetools 5.3.3 <pip>
certifi 2022.12.7 <pip>
cffi 1.16.0 <pip>
charset-normalizer 2.1.1 <pip>
click 8.1.7 <pip>
comm 0.2.2 <pip>
contourpy 1.2.1 <pip>
cycler 0.12.1 <pip>
dacite 1.8.1 <pip>
datasets 2.18.0 <pip>
debugpy 1.8.1 <pip>
decorator 5.1.1 <pip>
defusedxml 0.7.1 <pip>
dill 0.3.8 <pip>
docker-pycreds 0.4.0 <pip>
evaluate 0.4.2 <pip>
exceptiongroup 1.2.1 <pip>
executing 2.0.1 <pip>
fastjsonschema 2.19.1 <pip>
filelock 3.13.1 <pip>
fonttools 4.51.0 <pip>
fqdn 1.5.1 <pip>
frozenlist 1.4.1 <pip>
fsspec 2024.2.0 <pip>
gcsfs 2024.2.0 <pip>
gitdb 4.0.11 <pip>
GitPython 3.1.43 <pip>
google-api-core 2.19.0 <pip>
google-auth 2.29.0 <pip>
google-auth-oauthlib 1.2.0 <pip>
google-cloud-core 2.4.1 <pip>
google-cloud-storage 2.16.0 <pip>
google-crc32c 1.5.0 <pip>
google-resumable-media 2.7.0 <pip>
googleapis-common-protos 1.63.0 <pip>
h11 0.14.0 <pip>
htmlmin 0.1.12 <pip>
httpcore 1.0.5 <pip>
httpx 0.27.0 <pip>
huggingface-hub 0.20.3 <pip>
idna 3.4 <pip>
ImageHash 4.3.1 <pip>
importlib_metadata 7.1.0 <pip>
importlib_resources 6.4.0 <pip>
ipykernel 6.29.4 <pip>
ipython 8.18.1 <pip>
ipywidgets 8.1.2 <pip>
isoduration 20.11.0 <pip>
jedi 0.19.1 <pip>
Jinja2 3.1.3 <pip>
joblib 1.4.2 <pip>
json5 0.9.25 <pip>
jsonpointer 2.4 <pip>
jsonschema 4.22.0 <pip>
jsonschema-specifications 2023.12.1 <pip>
jupyter 1.0.0 <pip>
jupyter-console 6.6.3 <pip>
jupyter-events 0.10.0 <pip>
jupyter-lsp 2.2.5 <pip>
jupyter_client 8.6.1 <pip>
jupyter_core 5.7.2 <pip>
jupyter_server 2.14.0 <pip>
jupyter_server_terminals 0.5.3 <pip>
jupyterlab 4.1.8 <pip>
jupyterlab_pygments 0.3.0 <pip>
jupyterlab_server 2.27.1 <pip>
jupyterlab_widgets 3.0.10 <pip>
kiwisolver 1.4.5 <pip>
ld_impl_linux-64 2.38 h1181459_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libffi 3.4.4 h6a678d5_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libgcc-ng 12.2.0 h65d4601_19 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libstdcxx-ng 12.2.0 h46fd767_19 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
llvm-openmp 14.0.6 h9e868ea_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
llvmlite 0.42.0 <pip>
MarkupSafe 2.1.5 <pip>
matplotlib 3.8.4 <pip>
matplotlib-inline 0.1.7 <pip>
mistune 3.0.2 <pip>
mizani 0.11.2 <pip>
mpmath 1.3.0 <pip>
multidict 6.0.5 <pip>
multimethod 1.11.2 <pip>
multiprocess 0.70.16 <pip>
nbclient 0.10.0 <pip>
nbconvert 7.16.4 <pip>
nbformat 5.10.4 <pip>
ncurses 6.4 h6a678d5_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
nest-asyncio 1.6.0 <pip>
networkx 3.2.1 <pip>
notebook 7.1.3 <pip>
notebook_shim 0.2.4 <pip>
numba 0.59.1 <pip>
numpy 1.26.4 <pip>
oauthlib 3.2.2 <pip>
openssl 3.0.13 h7f8727e_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
overrides 7.7.0 <pip>
packaging 24.0 <pip>
pandas 2.2.2 <pip>
pandocfilters 1.5.1 <pip>
parso 0.8.4 <pip>
patsy 0.5.6 <pip>
pexpect 4.9.0 <pip>
phik 0.12.4 <pip>
pillow 10.2.0 <pip>
pip 23.3.1 py39h06a4308_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
platformdirs 4.2.1 <pip>
plotnine 0.13.5 <pip>
prometheus_client 0.20.0 <pip>
prompt-toolkit 3.0.43 <pip>
proto-plus 1.23.0 <pip>
protobuf 4.25.3 <pip>
psutil 5.9.8 <pip>
ptyprocess 0.7.0 <pip>
pure-eval 0.2.2 <pip>
pyarrow 16.0.0 <pip>
pyarrow-hotfix 0.6 <pip>
pyasn1 0.6.0 <pip>
pyasn1_modules 0.4.0 <pip>
pycparser 2.22 <pip>
pydantic 2.7.1 <pip>
pydantic_core 2.18.2 <pip>
Pygments 2.17.2 <pip>