[THUDM/ChatGLM-6B][BUG/Help] ptuning之后如何使用新的模型

2024-07-12 63 views
8

按照ptuning/README.md完成了ptuning的训练和推理,目前看generated_predictions.txt的结果均达到预期,请问如何使用checkpoint中训练后的模型?调用了半天都是各种报错,求大佬指条明路。

能够正常调用微调后的模型进行chat

修改了web_demo.py中的路径及模型,但无法正常使用。

Environment
OS: Ubuntu 20.04
Python: 3.10
Transformers: 4.26.1
PyTorch: 1.13.1
CUDA Support: True

回答

4

你用的什么数据集?跑了多少轮?

6

@luieswww 暂时先用的ptuning/README.md提到的ADGEN 数据集进行测试,按照原文件还是3000步,得到checkpoint-3000。我想先把程序跑通再测试自己的数据集。但是不知道怎么调用训练之后得到的模型。

2

tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True) model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().quantize(4).cuda() model = model.eval()

模型文件换成你的目录就行。

9

请提供具体的报错信息

0

我也是这么改的,但是会报错。

HFValidationError: Repo id must be in the form 'repo_name' or 'namespace/repo_name': 'E:/chatglm/check3000'. Use repo_type argument if needed.

E:/chatglm/check3000这个目录就是ptuning训练生成的目录,我按照报错提示添加了repo_type,仍然报错,显示如下:

OSError: [WinError 123] 文件名、目录名或卷标语法不正确。: 'C:\Users\admin\.cache\huggingface\modules\transformers_modules\E:'

命名没有用到C盘路径,还是会报这样的错误,不明白到底哪里出现了问题 ,诚邀大佬们指点 @luieswww @duzx16

7

Traceback (most recent call last): File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script exec(code, module.dict) File "E:\chatglm\ChatGLM-6B\ptuning\web_demo2.py", line 64, in st.session_state["state"] = predict(prompt_text, st.session_state["state"]) File "E:\chatglm\ChatGLM-6B\ptuning\web_demo2.py", line 30, in predict tokenizer, model = get_model() File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\streamlit\runtime\caching\cache_utils.py", line 194, in wrapper return cached_func(*args, *kwargs) File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\streamlit\runtime\caching\cache_utils.py", line 223, in call return self._get_or_create_cached_value(args, kwargs) File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\streamlit\runtime\caching\cache_utils.py", line 248, in _get_or_create_cached_value return self._handle_cache_miss(cache, value_key, func_args, func_kwargs) File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\streamlit\runtime\caching\cache_utils.py", line 302, in _handle_cache_miss computed_value = self._info.func(func_args, **func_kwargs) File "E:\chatglm\ChatGLM-6B\ptuning\web_demo2.py", line 17, in get_model tokenizer = AutoTokenizer.from_pretrained(mypath, trust_remote_code=True) File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\transformers\models\auto\tokenization_auto.py", line 663, in from_pretrained tokenizer_class = get_class_from_dynamic_module( File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\transformers\dynamic_module_utils.py", line 388, in get_class_from_dynamic_module final_module = get_cached_module_file( File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\transformers\dynamic_module_utils.py", line 273, in get_cached_module_file create_dynamic_module(full_submodule) File "C:\Users\admin\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\transformers\dynamic_module_utils.py", line 59, in create_dynamic_module os.makedirs(dynamic_module_path, exist_ok=True) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64qbz5n2kfra8p0\lib\os.py", line 215, in makedirs makedirs(head, exist_ok=exist_ok) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64qbz5n2kfra8p0\lib\os.py", line 215, in makedirs makedirs(head, exist_ok=exist_ok) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\os.py", line 225, in makedirs mkdir(name, mode) OSError: [WinError 123] 文件名、目录名或卷标语法不正确。: 'C:\Users\admin\.cache\huggingface\modules\transformers_modules\E:'

2

我可能懂了,路径加载的E:/chatglm/check3000中的“/”应该改成“\",习惯性地用了linux里地”/“,程序跑通了,虽然生成得很慢,感谢大佬们的指点,麻烦了,我继续下一步测试了。

9

请问路径加载的E:/chatglm/check3000中的“/”应该改成 什么了? "" 是什么意思?

9

保留原路径中的"\"就可以了,亲测

0

windows下一定要将路径中的 / 改成 \ , 你试试